forked from conceptsinmotion/thea
-
Notifications
You must be signed in to change notification settings - Fork 0
/
swrl_rdf_hooks.pl
126 lines (106 loc) · 3.76 KB
/
swrl_rdf_hooks.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* -*- Mode: Prolog -*- */
:- module(swrl_rdf_hooks,
[
]).
:- use_module(library('semweb/rdf_db.pl')).
:- use_module(swrl).
:- use_module(owl2_from_rdf).
:- use_module(owl2_model).
:- use_module(owl2_metamodel).
:- rdf_register_ns(swrl,'http://www.w3.org/2003/11/swrl#',[force(true)]).
:- rdf_register_ns(swrlb,'http://www.w3.org/2003/11/swrlb#',[force(true)]).
:- multifile owl2_from_rdf:owl_parse_axiom_hook/3.
owl2_from_rdf:owl_parse_axiom_hook(X,AnnMode,List) :-
debug(swrl,'trying swrl hooks for: ~w',[X]),
swrl_parse_axiom(X,AnnMode,List).
use_owl(A,B,C) :-
owl2_from_rdf:use_owl(A,B,C).
%owl_parse_axiom(swrl:implies(Body,Head),AnnMode,List) :-
swrl_parse_axiom(implies(Body,Head),AnnMode,List) :-
debug(swrl,'Testing swrl:Imp ',[]),
test_use_owl(X,'rdf:type','swrl:Imp'), % TODO: named rules
valid_axiom_annotation_mode(AnnMode,X,'rdf:type','swrl:Imp',List),
use_owl(X,'rdf:type','swrl:Imp'), % TODO: named rules
debug(swrl,'Parsing swrl:Imp ~w',[X]),
use_owl(X,'swrl:body',RdfBody),
use_owl(X,'swrl:head',RdfHead),
swrl_description_list(RdfBody,Body),
debug(swrl,' Body ~w',[Body]),
swrl_description_list(RdfHead,Head),
debug(swrl,' Head ~w',[Head]).
swrl_description_list('http://www.w3.org/1999/02/22-rdf-syntax-ns#nil',[]) :- !.
swrl_description_list(X,[F|R]) :-
% use_owl(X,'rdf:type','rdf:List'), -- required? for swrl it is swrl:AtomList
use_owl(X,'rdf:first',Element),
swrl_description(Element,F),
use_owl(X,'rdf:rest',Y),
!,
swrl_description_list(Y,R).
swrl_description(X,i(X)) :-
test_use_owl(X,'rdf:type','swrl:Variable'), % do not consume
!.
swrl_description(X,G) :-
use_owl(X,'rdf:type','swrl:IndividualPropertyAtom'),
!,
use_owl(X,'swrl:propertyPredicate',P),
use_owl(X,'swrl:argument1',A1),
use_owl(X,'swrl:argument2',A2),
swrl_description(P,PP),
swrl_description(A1,A1P),
swrl_description(A2,A2P),
G=..[PP,A1P,A2P]. % TODO: make this canonical form?
swrl_description(X,G) :-
use_owl(X,'rdf:type','swrl:DatavaluedPropertyAtom'),
!,
use_owl(X,'swrl:propertyPredicate',P),
use_owl(X,'swrl:argument1',A1),
use_owl(X,'swrl:argument2',A2),
swrl_description(P,PP),
swrl_description(A1,A1P),
swrl_description(A2,A2P),
G=..[PP,A1P,A2P]. % TODO: make this canonical form?
swrl_description(X,builtin(P,ArgsP)) :-
use_owl(X,'rdf:type','swrl:BuiltinAtom'),
!,
use_owl(X,'swrl:builtin',P),
use_owl(X,'swrl:arguments',Args),
swrl_description_list(Args,ArgsP).
swrl_description(X,G) :-
use_owl(X,'rdf:type','swrl:ClassAtom'),
!,
use_owl(X,'swrl:classPredicate',P),
use_owl(X,'swrl:argument1',A1),
swrl_description(P,PP),
swrl_description(A1,A1P),
G=description(PP,A1P).
% G=..[PP,A1P].
swrl_description(X,G) :-
use_owl(X,'rdf:type','swrl:DifferentIndividualsAtom'),
!,
use_owl(X,'swrl:argument1',A1),
use_owl(X,'swrl:argument2',A2),
swrl_description(A1,A1P),
swrl_description(A2,A2P),
G=differentFrom(A1P,A2P).
swrl_description(X,G) :-
use_owl(X,'rdf:type','swrl:SameIndividualAtom'),
!,
use_owl(X,'swrl:argument1',A1),
use_owl(X,'swrl:argument2',A2),
swrl_description(A1,A1P),
swrl_description(A2,A2P),
G=sameAs(A1P,A2P).
swrl_description(X,DX) :-
owl_description(X,DX),
!.
swrl_description(X,X) :- !.
/** <module> additional RDF parsing of SWRL rules
---+ Synopsis
==
[owl2_from_rdf].
[swrl].
[swrl_rdf_hooks].
owl_parse_rdf('testfiles/dl-safe-ancestor.owl').
==
---+ Details
*/