-
Notifications
You must be signed in to change notification settings - Fork 2
/
AMOntologyHandler.java
186 lines (149 loc) · 7.26 KB
/
AMOntologyHandler.java
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
package javareasoner.ontology;
import java.io.FileNotFoundException;
import java.util.HashSet;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLDataProperty;
import org.semanticweb.owlapi.model.OWLDataPropertyDomainAxiom;
import org.semanticweb.owlapi.model.OWLDataPropertyRangeAxiom;
import org.semanticweb.owlapi.model.OWLDatatype;
import org.semanticweb.owlapi.model.OWLDeclarationAxiom;
import org.semanticweb.owlapi.model.OWLDisjointClassesAxiom;
import org.semanticweb.owlapi.model.OWLFunctionalDataPropertyAxiom;
import org.semanticweb.owlapi.model.OWLObjectProperty;
import org.semanticweb.owlapi.model.OWLObjectPropertyDomainAxiom;
import org.semanticweb.owlapi.model.OWLObjectPropertyRangeAxiom;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyStorageException;
import org.semanticweb.owlapi.model.OWLSubClassOfAxiom;
import org.semanticweb.owlapi.model.OWLSubObjectPropertyOfAxiom;
import javareasoner.server.ReasoningServer;
public class AMOntologyHandler extends OntologyHandler implements ReasoningServer {
public AMOntologyHandler() {
super();
}
/**
* Override the method specifying the ArtMarket ontology's axioms through
* the OWLAPI.
*/
@Override
public void initOntology() throws OWLOntologyStorageException, FileNotFoundException, OWLOntologyCreationException {
appOntology = manager.createOntology(IOR);
df = appOntology.getOWLOntologyManager().getOWLDataFactory();
//CLASSES
//Note: Declare Axiom can be omitted because triggered by subclass axioms
OWLClass person = declareClass("Person");
OWLClass artist = declareClass("Artist");
OWLClass painter = declareClass("Painter");
OWLClass sculptor = declareClass("Sculptor");
OWLClass artisan = declareClass("Artisan");
OWLClass thing = declareClass("Thing");
OWLClass artwork = declareClass("ArtWork");
OWLClass product = declareClass("Product");
OWLClass paint = declareClass("Paint");
OWLClass sculpt = declareClass("Sculpt");
OWLSubClassOfAxiom artist_sub_p = df.getOWLSubClassOfAxiom(artist, person);
appOntology.add(artist_sub_p);
OWLSubClassOfAxiom artisan_sub_p = df.getOWLSubClassOfAxiom(artisan, person);
appOntology.add(artisan_sub_p);
OWLSubClassOfAxiom p_sub_a = df.getOWLSubClassOfAxiom(painter, artist);
appOntology.add(p_sub_a);
OWLSubClassOfAxiom s_sub_a = df.getOWLSubClassOfAxiom(sculptor, artist);
appOntology.add(s_sub_a);
OWLSubClassOfAxiom a_sub_t = df.getOWLSubClassOfAxiom(artwork, thing);
appOntology.add(a_sub_t);
OWLSubClassOfAxiom p_sub_t = df.getOWLSubClassOfAxiom(product, thing);
appOntology.add(p_sub_t);
OWLSubClassOfAxiom paint_sub_a = df.getOWLSubClassOfAxiom(paint, artwork);
appOntology.add(paint_sub_a);
OWLSubClassOfAxiom sculpt_sub_a = df.getOWLSubClassOfAxiom(sculpt, artwork);
appOntology.add(sculpt_sub_a);
//OBJECT PROPERTIES
OWLObjectProperty crafts = df.getOWLObjectProperty(IOR + "#crafts");
OWLObjectPropertyRangeAxiom c_range = df.getOWLObjectPropertyRangeAxiom(crafts, artwork);
appOntology.add(c_range);
OWLObjectPropertyDomainAxiom c_domain = df.getOWLObjectPropertyDomainAxiom(crafts, artist);
appOntology.add(c_domain);
OWLObjectProperty produces = df.getOWLObjectProperty(IOR + "#produces");
OWLObjectPropertyRangeAxiom p_range = df.getOWLObjectPropertyRangeAxiom(produces, product);
appOntology.add(p_range);
OWLObjectPropertyDomainAxiom p_domain = df.getOWLObjectPropertyDomainAxiom(produces, artisan);
appOntology.add(p_domain);
OWLObjectProperty paints = df.getOWLObjectProperty(IOR + "#paints");
OWLObjectPropertyRangeAxiom pa_range = df.getOWLObjectPropertyRangeAxiom(paints, paint);
appOntology.add(pa_range);
OWLObjectPropertyDomainAxiom pa_domain = df.getOWLObjectPropertyDomainAxiom(paints, painter);
appOntology.add(pa_domain);
OWLObjectProperty sculpts = df.getOWLObjectProperty(IOR + "#sculpts");
OWLObjectPropertyRangeAxiom s_range = df.getOWLObjectPropertyRangeAxiom(sculpts, sculpt);
appOntology.add(s_range);
OWLObjectPropertyDomainAxiom s_domain = df.getOWLObjectPropertyDomainAxiom(sculpts, sculptor);
appOntology.add(s_domain);
OWLSubObjectPropertyOfAxiom p_sub_c = df.getOWLSubObjectPropertyOfAxiom(paints, crafts);
appOntology.add(p_sub_c);
OWLSubObjectPropertyOfAxiom s_sub_c = df.getOWLSubObjectPropertyOfAxiom(sculpts, crafts);
appOntology.add(s_sub_c);
//DATA PROPERTIES
OWLDatatype stringDatatype = df.getStringOWLDatatype();
OWLDataProperty name = df.getOWLDataProperty(IOR + "#name");
OWLDataPropertyDomainAxiom name_domain = df.getOWLDataPropertyDomainAxiom(name, person);
appOntology.add(name_domain);
OWLDataPropertyRangeAxiom name_range = df.getOWLDataPropertyRangeAxiom(name, stringDatatype);
appOntology.add(name_range);
OWLFunctionalDataPropertyAxiom fun_name = df.getOWLFunctionalDataPropertyAxiom(name);
appOntology.add(fun_name);
OWLDataProperty identifier = df.getOWLDataProperty(IOR + "#id");
OWLDataPropertyDomainAxiom id_domain = df.getOWLDataPropertyDomainAxiom(identifier, thing);
appOntology.add(id_domain);
OWLDataPropertyRangeAxiom id_range = df.getOWLDataPropertyRangeAxiom(identifier, stringDatatype);
appOntology.add(id_range);
OWLFunctionalDataPropertyAxiom fun_id = df.getOWLFunctionalDataPropertyAxiom(identifier);
appOntology.add(fun_id);
HashSet<OWLClass> disclasses = new HashSet<>();
disclasses.add(person);
disclasses.add(thing);
OWLDisjointClassesAxiom discla = df.getOWLDisjointClassesAxiom(disclasses);
appOntology.add(discla);
HashSet<OWLClass> disclassesThings = new HashSet<>();
disclassesThings.add(paint);
disclassesThings.add(sculpt);
disclassesThings.add(product);
OWLDisjointClassesAxiom discla2 = df.getOWLDisjointClassesAxiom(disclassesThings);
appOntology.add(discla2);
saveOntology();
getReasoner();
}
/**
* Utility method to declare a class with the IRI fragment given as string.
* @param id String representing IRI fragment
* @return The OWLClass declared
*/
private OWLClass declareClass(String id) {
OWLClass owlClass = df.getOWLClass(IOR + "#" + id);
OWLDeclarationAxiom da = df.getOWLDeclarationAxiom(owlClass);
appOntology.add(da);
return owlClass;
}
@Override
public void reasoningRoutine() {
boolean consistent = isConsistent();
System.out.println("\nIs ontology still consistent? " + consistent);
if (consistent) {
System.out.println("\nReasoning Routine");
System.out.println("\nPainter(*)");
getInstances("Painter").forEach(System.out::println);
System.out.println("\nPaint(*)");
getInstances("Paint").forEach(System.out::println);
System.out.println("\nThing(*)");
getInstances("Thing").forEach(System.out::println);
System.out.println("\nproduces(*)");
getInstances("produces", null).forEach(System.out::println);
System.out.println("\npaints some Paint(*)");
getInstances("paints", null).forEach(System.out::println);
System.out.println("\ncrafts some Sculpt(*)");
getInstances("crafts", "Sculpt").forEach(System.out::println);
System.out.println("\nArtist and (crafts some ArtWork) (*)");
getInstances("crafts", "ArtWork").forEach(System.out::println);
}
System.out.println("*******************************************************");
}
}