14
15
16:- module(implication_to_swrl, [
17 implication_to_swrl/3
18 ]). 19
20:- use_module(drs_to_owlswrl_core, [
21 is_toplevel/3,
22 get_entity/3,
23 condlist_and/4,
24 is_object_with_generalized_quantifier/1,
25 has_dom_for_member/3,
26 dataitem_datavalue_datatypeuri/3
27 ]).
51implication_to_swrl(
52 '=>'(CondList1, CondList2),
53 RefList,
54 'DLSafeRule'('Body'(AtomList1), 'Head'(AtomList2))
55) :-
56 condlist_atomlist(CondList1, RefList, AtomList1),
57 condlist_atomlist(CondList2, RefList, AtomList2).
70condlist_atomlist([], _, []).
71
79
90condlist_atomlist([Condition | ConditionList], RefList, AtomList) :-
91 has_dom_for_member(_Ref, [Condition], []),
92 !,
93 condlist_atomlist(ConditionList, RefList, AtomList).
94
95condlist_atomlist([Condition | ConditionList], RefList, AtomList) :-
96 condition_atomlist(Condition, RefList, AtomList1),
97 condlist_atomlist(ConditionList, RefList, AtomList2),
98 append(AtomList1, AtomList2, AtomList).
99
100
133condition_atomlist(Condition, _, _) :-
134 is_object_with_generalized_quantifier(Condition),
135 !,
136 fail.
137
138condition_atomlist(formula(Expr1, Comp, Expr2)-_, RefList, Builtins) :-
139 expr_to_builtins(Expr1, Var1, B1),
140 expr_to_builtins(Expr2, Var2, B1, B2),
141 add_relation(Comp, Var1, Var2, RefList, B2, Builtins).
142
143condition_atomlist(object(X, Value, _, na, _, _)-_, _, ['ClassAtom'(NamedClass, Variable)]) :-
144 get_variable(X, Variable),
145 get_entity(class, Value, NamedClass).
146
147condition_atomlist('-'([predicate(_, be, X1, X2)-_]), RefList, ['DifferentIndividualsAtom'(OutX1, OutX2)]) :-
148 get_argument(X1, RefList, object, OutX1, _),
149 get_argument(X2, RefList, object, OutX2, _).
150
151condition_atomlist(predicate(_, be, X1, X2)-_, RefList, ['SameIndividualAtom'(OutX1, OutX2)]) :-
152 get_argument(X1, RefList, object, OutX1, _),
153 get_argument(X2, RefList, object, OutX2, _).
154
155condition_atomlist(predicate(_, Value, X1, X2)-_, RefList, ['DataPropertyAtom'(DataProperty, OutX1, OutX2) | L]) :-
156 Value \= be,
157 get_entity(data_property, Value, DataProperty),
158 get_argument(X1, RefList, object, OutX1, L1),
159 get_argument(X2, RefList, data, OutX2, L2),
160 append(L1, L2, L).
161
162condition_atomlist(predicate(_, Value, X1, X2)-_, RefList, ['ObjectPropertyAtom'(ObjectProperty, OutX1, OutX2)]) :-
163 Value \= be,
164 get_entity(object_property, Value, ObjectProperty),
165 get_argument(X1, RefList, object, OutX1, _),
166 get_argument(X2, RefList, object, OutX2, _).
167
171condition_atomlist([C | Cs], RefList, ['ClassAtom'(SubListClass, OutX)]) :-
172 condlist_and(X, [C | Cs], RefList, SubListClass),
173 get_argument(X, RefList, object, OutX, _).
174
177condition_atomlist('-'(Not), RefList, ['ClassAtom'('ObjectComplementOf'(NotClass), OutX)]) :-
178 condlist_and(X, Not, RefList, NotClass),
179 get_argument(X, RefList, object, OutX, _).
180
182condition_atomlist('v'(Or1, Or2), RefList, ['ClassAtom'('ObjectUnionOf'([Or1Class, Or2Class]), OutX)]) :-
183 condlist_and(X, Or1, RefList, Or1Class),
184 condlist_and(X, Or2, RefList, Or2Class),
185 get_argument(X, RefList, object, OutX, _).
196get_argument(expr(X, Y, Z), _RefList, data, Var, Builtins) :-
197 !,
198 expr_to_builtins(expr(X, Y, Z), Var, Builtins).
199
204get_argument(DataItem, _RefList, data, '^^'(DataValue, DataTypeUri), []) :-
205 dataitem_datavalue_datatypeuri(DataItem, DataValue, DataTypeUri),
206 !.
207
208get_argument(X, RefList, object, Individual, []) :-
209 is_toplevel(X, RefList, 'ObjectOneOf'([Individual])),
210 !.
211
212get_argument('$VAR'(X), _RefList, object, Variable, []) :-
213 get_variable(X, Variable).
214
215get_argument(X, _RefList, object, X, []).
225add_relation(Relation, Var1, Var2, RefList, B, ['BuiltInAtom'(swrlb:Builtin, [OutVar1, OutVar2]) | B]) :-
226 relation_builtin(Relation, Builtin),
227 get_argument(Var1, RefList, _, OutVar1, _),
228 get_argument(Var2, RefList, _, OutVar2, _).
229
230
246expr_to_builtins(Expr, List) :-
247 expr_to_builtins(Expr, _, List).
248
249expr_to_builtins(Expr, Var, List) :-
250 expr_to_builtins(Expr, Var, [], List).
251
252expr_to_builtins(expr(Op, E1, E2), Var, LIn, ['BuiltInAtom'(swrlb:Builtin, [Var, Var1, Var2]) | LOut]) :-
253 !,
254 op_builtin(Op, Builtin),
255 get_swrl_variable(Var),
256 expr_to_builtins(E1, Var1, LIn, LTmp),
257 expr_to_builtins(E2, Var2, LTmp, LOut).
258
260expr_to_builtins(Var, OutVar, List, List) :-
261 get_argument(Var, [], _, OutVar, _).
270get_swrl_variable(Variable) :-
271 gensym(g, GenSym),
272 get_variable(GenSym, Variable).
278get_variable('$VAR'(X), 'Variable'(Var)) :-
279 !,
280 with_output_to(atom(Var), format("urn:swrl#x~w", [X])).
281
282get_variable(X, 'Variable'(Var)) :-
283 with_output_to(atom(Var), format("urn:swrl#x~w", [X])).
293relation_builtin('=', equal).
294relation_builtin('\\=', notEqual).
295relation_builtin('<', lessThan).
296relation_builtin('=<', lessThanOrEqual).
297relation_builtin('>', greaterThan).
298relation_builtin('>=', greaterThanOrEqual).
308op_builtin('+', add).
309op_builtin('-', subtract).
310op_builtin('*', multiply).
311op_builtin('/', divide).
312op_builtin('^', pow).
313op_builtin('&', stringConcat)
DRS implication to SWRL-rule translator
Translate an Attempto DRS implication into Semantic Web Rule Language (SWRL) rule.
We use the SWRL rule syntax specified in http://www.webont.org/owled/2009/papers/owled2009_submission_16.pdf
TODO
: add a constraint that the variables in the head is a subset of the variables in the body.