/
owl2_basic_reasoner.plt
169 lines (140 loc) · 5.96 KB
/
owl2_basic_reasoner.plt
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/* -*- Mode: Prolog -*- */
:- use_module(owl2_basic_reasoner).
:- use_module(owl2_model).
:- begin_tests(owl2_basic_reasoner,[setup(init_axioms),cleanup(retract_all_axioms)]).
init_axioms :-
Axioms=[
ontology(trophy),
class(animal),
class(organism),
class(bird),
class(fish),
class(arthropod),
class(crustacean),
class(mammal),
class(cat),
class(mouse),
class(dog),
class(human),
class(raptor),
class(eagle),
class(kestrel),
class(goldfish),
class(pike),
class(shrimp),
class(man_eating_shrimp),
class(dangerous_animal),
class(carnivore),
subClassOf(animal,organism),
subClassOf(mammal,animal),
subClassOf(bird,animal),
subClassOf(fish,animal),
subClassOf(arthropod,animal),
subClassOf(crustacean,arthropod),
subClassOf(cat,mammal),
subClassOf(mouse,mammal),
subClassOf(dog,mammal),
subClassOf(human,mammal),
subClassOf(raptor,bird),
subClassOf(eagle,raptor),
subClassOf(kestrel,raptor),
subClassOf(goldfish,fish),
subClassOf(pike,fish),
subClassOf(perch,fish),
subClassOf(shrimp,crustacean),
subClassOf(man_eating_shrimp,crustacean),
subClassOf(cat,someValuesFrom(eats,mouse)),
equivalentClasses([man_eating_shrimp,intersectionOf([shrimp,someValuesFrom(eats,human)])]),
equivalentClasses([dangerous_animal,intersectionOf([animal,someValuesFrom(eats,human)])]),
equivalentClasses([carnivore,intersectionOf([organism,someValuesFrom(eats,animal)])]),
classAssertion(cat,tom),
classAssertion(mouse,jerry),
classAssertion(goldfish,goldie),
classAssertion(kestrel,kes),
classAssertion(pike,pike1),
classAssertion(perch,perch2),
classAssertion(shrimp,shrimp3),
classAssertion(human,human1),
classAssertion(man_eating_shrimp,shrimpzilla),
classAssertion(shrimp,shrimpzuki),
propertyAssertion(eats,tom,goldie),
propertyAssertion(eats,tom,jerry),
propertyAssertion(eats,kes,tom),
propertyAssertion(eats,kes,pike1),
propertyAssertion(eats,pike1,perch2),
propertyAssertion(eats,perch2,shrimp3),
propertyAssertion(eats,perch2,shrimp3),
propertyAssertion(eats,shrimpzilla,human1),
propertyAssertion(eats,shrimpzuki,human1),
objectProperty(eats),
disjointClasses([mammal,fish])
],
retract_all_axioms,
maplist(assert_axiom,Axioms).
test(loaded) :-
\+ \+ ontology(_).
test(query) :-
forall((query(Q,T,ExpectedL),debug(test,'Query: ~w',[Q])),
( setof(T,Q^entailed(Q),RL),
writeln(results=RL),
RL=ExpectedL)).
test(lca) :-
forall(property_assertion_least_common_ancestor(P,XI,YI,XC,YC),
writeln(lca(P,XI,YI,XC,YC))),
nl.
query(subClassOf(human,Y),
Y,
[animal, mammal, organism]).
query(subClassOf(someValuesFrom(eats,human),
someValuesFrom(eats,Y)),
Y,
[animal, mammal, organism]).
query(subClassOf(intersectionOf([shrimp,someValuesFrom(eats,human)]),
someValuesFrom(eats,Y)),
Y,
[animal, mammal, organism]).
query(subClassOf(intersectionOf([shrimp,someValuesFrom(eats,human)]),
intersectionOf([X,someValuesFrom(eats,Y)])),
X-Y,
[animal-animal, animal-mammal, animal-organism, arthropod-animal, arthropod-mammal, arthropod-organism, crustacean-animal, crustacean-mammal, crustacean-organism, man_eating_shrimp-animal, man_eating_shrimp-mammal, man_eating_shrimp-organism, organism-animal, organism-mammal, organism-organism, shrimp-animal, shrimp-mammal, shrimp-organism]).
query(subClassOf(cat,X),X,[animal,mammal,organism|_]).
query(classAssertion(intersectionOf([A,someValuesFrom(P,B)]),X),
X,[kes, perch2, pike1, shrimpzilla, shrimpzuki, tom]).
expected(subClassOf(man_eating_shrimp,someValuesFrom(eats,human))).
expected(subClassOf(man_eating_shrimp,dangerous_animal)).
expected(subClassOf(human,organism)).
expected(subClassOf(raptor,bird)).
expected(subClassOfReflexive(raptor,raptor)).
expected(subClassOf(carnivore,someValuesFrom(eats,animal))).
expected(subClassOf(cat,someValuesFrom(eats,animal))).
expected(subClassOf(cat,carnivore)).
expected(subClassOf(intersectionOf([mammal, someValuesFrom(eats, organism)]),
mammal)).
expected(subClassOf(intersectionOf([mammal, someValuesFrom(eats, animal)]),
intersectionOf([mammal, someValuesFrom(eats, organism)]))).
expected(classAssertion(organism,human1)).
expected(classAssertion(man_eating_shrimp,shrimpzuki)).
expected(classAssertion(intersectionOf([mammal, someValuesFrom(eats, fish)]),tom)).
expected(classAssertion(carnivore,tom)).
test(expected) :-
forall(expected(A),
test_for(A)).
test_for(A) :-
debug(test,'testing for ~w',[A]),
( entailed(A)
-> debug(test,' **OK** ~w',[A])
; debug(test,' **FAIL** ~w',[A]),
fail).
:- end_tests(owl2_basic_reasoner).
/** <module> tests for OWL2 basic_reasoner
---+ Synopsis
Command line:
==
swipl
?- [owl2_basic_reasoner].
?- load_test_files([]).
?- run_tests.
==
---+ Details
This is a test module for the module owl2_basic_reasoner
*/