35
36:- module(rdfs_entailment,
37 [
38 ]). 39:- use_module(rdfql(rdfql_runtime)). 40:- use_module(library(nb_set)). 41:- use_module(library('semweb/rdf_db'),
42 [ rdf_current_predicate/1,
43 rdf_global_id/2,
44 rdf_reachable/3,
45 rdf_has/3,
46 rdf_has/4,
47 rdf_subject/1,
48 rdf_equal/2,
49 (rdf_meta)/1,
50 op(_,_,_)
51 ]). 52:- use_module(library('semweb/rdfs'),
53 [ rdfs_subclass_of/2,
54 rdfs_subproperty_of/2
55 ]).
68:- rdf_meta
69 rdf(o,o,o),
70 individual_of(r,r). 71
72:- public
73 rdf/3,
74 rdf/4. 75
76rdf(literal(L), _, _) :- 77 nonvar(L), !, fail.
78rdf(_, literal(L), _) :- 79 nonvar(L), !, fail.
80rdf(S, P, O) :-
81 var(P),
82 !,
83 ( rdf_db:rdf(S,P,O)
84 ; rdf(P, rdf:type, rdf:'Property'),
85 rdf(S, P, O),
86 \+ rdf_db:rdf(S,P,O)
87 ).
88rdf(S, P, C) :-
89 rdf_reachable(rdf:type, rdfs:subPropertyOf, P),
90 !,
91 individual_of(S, C).
92rdf(S, P, O) :- 93 rdf_reachable(rdfs:subClassOf, rdfs:subPropertyOf, P),
94 !,
95 ( (nonvar(S) ; nonvar(O))
96 -> rdfs_subclass_of(S, O) 97 ; individual_of(S, rdfs:'Class'), 98 rdfs_subclass_of(S, O)
99 ).
100rdf(S, rdfs:subPropertyOf, O) :-
101 !,
102 ( nonvar(S)
103 -> individual_of(S, rdf:'Property'),
104 rdfs_subproperty_of(S, O)
105 ; nonvar(O)
106 -> individual_of(O, rdf:'Property'),
107 rdfs_subproperty_of(S, O)
108 ; individual_of(S, rdf:'Property'),
109 rdfs_subproperty_of(S, O)
110 ).
111rdf(S, serql:directSubClassOf, O) :-
112 !,
113 rdf_has(S, rdfs:subClassOf, O).
114rdf(S, serql:directType, O) :-
115 !,
116 rdf_has(S, rdf:type, O).
117rdf(S, serql:directSubPropertyOf, O) :-
118 !,
119 rdf_has(S, rdfs:subPropertyOf, O).
120rdf(S, P, O) :-
121 rdf_has(S, P, O).
125rdf(S, P, O, G) :-
126 var(P),
127 !,
128 rdf_db:rdf(S, P, O, G).
129rdf(S, P, O, G) :-
130 rdf_has(S, P, O, RP),
131 rdf_db:rdf(S, RP, O, G).
136individual_of(Resource, Class) :-
137 nonvar(Resource),
138 !,
139 ( Resource = literal(_)
140 -> rdfs_subclass_of(Class, rdfs:'Literal')
141 ; rdfs_has_type(Resource, MyClass),
142 rdfs_subclass_of(MyClass, Class)
143 ; rdf_equal(Class, rdfs:'Resource')
144 ).
145individual_of(Resource, Class) :-
146 nonvar(Class),
147 !,
148 ( rdf_equal(Class, rdfs:'Resource')
149 -> rdf_subject(Resource)
150 ; rdfs_subclass_of(SubClass, Class),
151 rdfs_has_type(Resource, SubClass)
152 ).
153individual_of(Resource, Class) :-
154 rdf_subject(Resource),
155 individual_of(Resource, Class).
164rdfs_has_type(Resource, Class) :-
165 empty_nb_set(Set),
166 ( atom(Resource)
167 -> ( rdf_has(Resource, rdf:type, Class)
168 ; rdf_db:rdf(Resource, P, _),
169 rdf_has(P, rdfs:domain, Class)
170 ; rdf_db:rdf(_, P, Resource),
171 rdf_has(P, rdfs:range, Class)
172 ; rdf_db:rdf(Resource, rdfs:subPropertyOf, _),
173 rdf_equal(Class, rdf:'Property')
174 ; rdf_db:rdf(_, rdfs:subPropertyOf, Resource),
175 rdf_equal(Class, rdf:'Property')
176 ; ( rdf_db:rdf(_,Resource,_)
177 -> rdf_equal(Class, rdf:'Property'),
178 \+ rdf_has(Resource, rdf:type, Class)
179 )
180 ),
181 add_nb_set(Class, Set, New),
182 New == true
183 ; atom(Class)
184 -> ( rdf_has(Resource, rdf:type, Class)
185 ; rdf_has(P, rdfs:domain, Class),
186 rdf_has(Resource, P, _)
187 ; rdf_has(P, rdfs:range, Class),
188 rdf_has(_, P, Resource)
189 ; ( rdf_reachable(Class, rdfs:subClassOf, rdf:'Property')
190 -> rdf_current_predicate(Resource),
191 ( rdf(_,Resource,_)
192 -> \+ rdf_has(Resource, rdf:type, Class)
193 )
194 )
195 ),
196 add_nb_set(Resource, Set, New),
197 New == true
198 ; throw(error(instantiation_error, _))
199 ).
200
201
202 205
206:- multifile
207 cliopatria:entailment/2. 208
209cliopatria:entailment(rdfs, rdfs_entailment)
RDFS entailment
The function of an entailment module is to provide an implementation of rdf/3 that extends basic triple-lookup using the entailment rules of the semantic web sub language of RDF.
This entailment module does RDFS entailment.