forked from vangelisv/thea
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathowl2_export_manchester.pl
74 lines (60 loc) · 1.98 KB
/
owl2_export_manchester.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* -*- Mode: Prolog -*- */
:- module(owl2_export_manchester,
[ owl_generate_manchester/1, % +FileName
owl_generate_manchester/2 % +FileName, +Options
]).
:- use_module(owl2_model).
:- use_module(library(option)).
/** <module> Generate Manchester syntax
@tbd Almost everything ...
*/
%! owl_generate_manchester(+FileName) is det.
%! owl_generate_manchester(+FileName, +Options) is det.
%
% Emit the current axioms as Manchester syntax.
owl_generate_manchester(FileName) :-
setof(Ontology,ontology(Ontology),[Ontology]),
!,
owl_generate_manchester(FileName, [ontology(Ontology)]).
owl_generate_manchester(FileName) :-
owl_generate_manchester(FileName, []).
owl_generate_manchester(FileName, Options) :-
setup_call_cleanup(
open(FileName, write, Out, [encoding(utf8)]),
owl_generate_manchester_to_stream(Out, Options),
close(Out)).
owl_generate_manchester_to_stream(Out, Options) :-
save_prefixes(Out, Options),
ontology(Ontology, Options),
format(Out, '~nOntology: <~w>~n', [Ontology]),
save_classes(Out).
save_prefixes(Out, Options) :-
save_default_prefix(Out, Options).
save_default_prefix(Out, Options) :-
option(prefix(Prefix), Options),
!,
format(Out, 'Prefix: : <~w>~n', [Prefix]).
save_default_prefix(_, _).
ontology(Ontology, Options) :-
option(ontology(Ontology), Options),
!.
ontology('http://example.org/ontology#', _).
save_classes(Out) :-
forall(axiom(class(Class)),
save_class(Out, Class)).
save_class(Out, Class) :-
format(Out, '~nClass: ~w~n', [Class]),
save_subclasses(Out, Class).
save_subclasses(Out, Class) :-
setof(Sub, axiom(subClassOf(Class, Sub)), Subs),
!,
format(Out, ' SubClassOf:~n', []),
save_list(Out, Subs).
save_subclasses(_, _).
save_list(_Out, []) :- !.
save_list(Out, [H|T]) :-
( T == []
-> format(Out, ' ~w~n', [H])
; format(Out, ' ~w,~n', [H]),
save_list(Out, T)
).