14
15:- module(owlswrl_to_fss, [
16 owlswrl_to_fss/1,
17 owlswrl_to_fss/2
18 ]). 19
20:- use_module(owlswrl_iri, [
21 iri_to_prefix/2,
22 builtin_iri/2
23 ]).
42owlswrl_to_fss('Ontology'(OntologyIri, Axioms)) :-
43 iri_to_prefix(OntologyIri, Prefix),
44 format("Prefix(:=<~w>)~n", [Prefix]),
45 forall(
46 builtin_iri(Abbr, IriPrefix),
47 format("Prefix(~w:=<~w>)~n", [Abbr, IriPrefix])
48 ),
49 format("Ontology(<~w>~n", [OntologyIri]),
50 print_list(Axioms, 1),
51 format(")~n").
52
54owlswrl_to_fss(Ontology, OntologyFss) :-
55 with_output_to(atom(OntologyFss), owlswrl_to_fss(Ontology)).
61print_compound(OwlFss, Level) :-
62 OwlFss =.. [Name | Args],
63 PrettyIndent is Level * 3,
64 writef('%r%w(\n', [' ', PrettyIndent, Name]),
65 NewLevel is Level + 1,
66 print_list(Args, NewLevel),
67 writef('%r)\n', [' ', PrettyIndent]).
75print_list([], _).
76
77print_list([Head | Tail], Level) :-
78 is_list(Head),
79 !,
80 print_list(Head, Level),
81 print_list(Tail, Level).
82
83print_list([Expression | Tail], Level) :-
84 print_terminal(Expression, Level),
85 !,
86 print_list(Tail, Level).
87
88print_list([Head | Tail], Level) :-
89 compound(Head),
90 !,
91 print_compound(Head, Level),
92 print_list(Tail, Level).
98print_terminal(Number, Level) :-
99 number(Number),
100 !,
101 PrettyIndent is Level * 3,
102 writef('%r%w\n', [' ', PrettyIndent, Number]).
103
104print_terminal(Iri, Level) :-
105 atom(Iri),
106 !,
107 PrettyIndent is Level * 3,
108 writef('%r<%w>\n', [' ', PrettyIndent, Iri]).
109
110print_terminal('Variable'(Iri), Level) :-
111 PrettyIndent is Level * 3,
112 writef('%rVariable(<%w>)\n', [' ', PrettyIndent, Iri]).
113
114print_terminal('BuiltInAtom'(Iri, DArgList), Level) :-
115 PrettyIndent is Level * 3,
116 writef('%rBuiltInAtom(<%w>\n', [' ', PrettyIndent, Iri]),
117 NewLevel is Level + 1,
118 print_list(DArgList, NewLevel),
119 writef('%r)\n', [' ', PrettyIndent]).
120
121print_terminal('^^'(DataValue, DataType), Level) :-
122 PrettyIndent is Level * 3,
123 writef('%r"%w"^^<%w>\n', [' ', PrettyIndent, DataValue, DataType]).
124
125print_terminal(Terminal, Level) :-
126 pretty_print(Terminal, PrettyExpression),
127 !,
128 PrettyIndent is Level * 3,
129 writef('%r%w\n', [' ', PrettyIndent, PrettyExpression]).
130
131
132pretty_print(nodeID(Number), '_':Number).
133pretty_print(NS:Name, NS:Name)
OWL/SWRL serializer into OWL/SWRL Functional-Style Syntax
*/