Skip to content

Commit 11f0c1e

Browse files
authored
Merge pull request #3 from mans0954/owlapi4
Update to use OWLAPI v4.x (necessary for Protege 5.x)
2 parents bbde4f6 + 24f59ef commit 11f0c1e

3 files changed

Lines changed: 24 additions & 20 deletions

File tree

META-INF/MANIFEST.MF

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ Import-Package: org.osgi.framework,
3535
org.xml.sax,
3636
org.xml.sax.ext,
3737
org.xml.sax.helpers,
38-
javax.xml.parsers
38+
javax.xml.parsers,
39+
com.google.common.base
3940
Bundle-Version: 0.1.3
4041
Bundle-Activator: org.protege.editor.core.plugin.DefaultPluginActivator
4142
Require-Bundle: org.eclipse.equinox.registry,

src/graphModifier/TransformOWLtoGraph.java

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
import languages.LanguageGraphEN;
44
import org.apache.log4j.Logger;
55
import org.semanticweb.owlapi.model.*;
6+
//import org.semanticweb.owlapi.search.Searcher;
7+
import org.semanticweb.owlapi.search.EntitySearcher;
68
import prefuse.data.Graph;
79
import storage.GraphStorage;
810
import types.EdgesType;
911
import types.OWLTypes;
1012
import types.PropertyType;
1113

1214
import java.util.Set;
15+
import java.util.Collection;
1316

1417
/**
1518
* This class transforms the OWL ontology to a graph.
@@ -113,7 +116,7 @@ private void transformDataTypeProperty(Set<OWLDataProperty> OWLDataPropertiesSet
113116
String owlVersionInfo = "";
114117
String objectPropertyIRI = owlDataProp.getIRI().toString();
115118

116-
Set<OWLAnnotation> owlPropAnoSet = owlDataProp.getAnnotations(onto);
119+
Collection<OWLAnnotation> owlPropAnoSet = EntitySearcher.getAnnotations(owlDataProp,onto);
117120
for (OWLAnnotation owlPropAno : owlPropAnoSet) {
118121
// extract data from owl:ObjectProperty
119122
String checkFor = owlPropAno.getProperty().toString();
@@ -128,7 +131,7 @@ private void transformDataTypeProperty(Set<OWLDataProperty> OWLDataPropertiesSet
128131
}
129132

130133
// get the domain of the property
131-
for (OWLClassExpression domain : owlDataProp.getDomains(onto)) {
134+
for (OWLClassExpression domain : EntitySearcher.getDomains(owlDataProp,onto)) {
132135
if (!domain.isAnonymous()) {
133136
rdfsDomain = domain.asOWLClass().getIRI().toString();
134137
} else {
@@ -141,7 +144,7 @@ private void transformDataTypeProperty(Set<OWLDataProperty> OWLDataPropertiesSet
141144
}
142145
}
143146
// get the range of the property
144-
for (OWLDataRange domain : owlDataProp.getRanges(onto)) {
147+
for (OWLDataRange domain : EntitySearcher.getRanges(owlDataProp,onto)) {
145148
try {
146149
rdfsRange = domain.asOWLDatatype().getIRI().toString();
147150
} catch (OWLRuntimeException e) {
@@ -172,7 +175,7 @@ private void transformDataTypeProperty(Set<OWLDataProperty> OWLDataPropertiesSet
172175
isGenericLiteral = true;
173176
}
174177

175-
IRI ontoIRI = onto.getOntologyID().getOntologyIRI();
178+
IRI ontoIRI = onto.getOntologyID().getOntologyIRI().get();
176179
if (ontoIRI == null && rdfsIsDefinedBy != null) {
177180
ontoIRI = IRI.create(rdfsIsDefinedBy);
178181
}
@@ -230,7 +233,7 @@ private void transformObjectProperty(Set<OWLObjectProperty> OWLObjectPropertiesS
230233
GraphDataModifier mod, String id) {
231234
TransformOWLtoGraphUtilities tgu = new TransformOWLtoGraphUtilities();
232235
for (OWLObjectProperty owlProp : OWLObjectPropertiesSet) {
233-
Set<OWLAnnotation> owlPropAnoSet = owlProp.getAnnotations(onto);
236+
Collection<OWLAnnotation> owlPropAnoSet = EntitySearcher.getAnnotations(owlProp,onto);
234237
String rdfsDomain = "";
235238
String rdfsRange = "";
236239
String rdfsInversOf = "";
@@ -251,7 +254,7 @@ private void transformObjectProperty(Set<OWLObjectProperty> OWLObjectPropertiesS
251254
owlVersionInfo);
252255
}
253256
// get the domain of the property
254-
for (OWLClassExpression domain : owlProp.getDomains(onto)) {
257+
for (OWLClassExpression domain : EntitySearcher.getDomains(owlProp,onto)) {
255258
if (!domain.isAnonymous()) {
256259
rdfsDomain = domain.asOWLClass().getIRI().toString();
257260
} else {
@@ -264,7 +267,7 @@ private void transformObjectProperty(Set<OWLObjectProperty> OWLObjectPropertiesS
264267
}
265268
}
266269
// get the range of the property
267-
for (OWLClassExpression domain : owlProp.getRanges(onto)) {
270+
for (OWLClassExpression domain : EntitySearcher.getRanges(owlProp,onto)) {
268271
if (!domain.isAnonymous()) {
269272
rdfsRange = domain.asOWLClass().getIRI().toString();
270273
} else {
@@ -281,7 +284,7 @@ private void transformObjectProperty(Set<OWLObjectProperty> OWLObjectPropertiesS
281284
// add blank space, avoid text runs out of the colored background (only an optic fix)
282285
rdfsLabel = rdfsLabel.concat(" ");
283286
// get the IRI of the object property which is inverse to 'this' object property
284-
Set<OWLObjectPropertyExpression> OWLObjectPropertyExpressionSet = owlProp.getInverses(onto);
287+
Collection<OWLObjectPropertyExpression> OWLObjectPropertyExpressionSet = EntitySearcher.getInverses(owlProp,onto);
285288
for (OWLObjectPropertyExpression owlOPE : OWLObjectPropertyExpressionSet) {
286289

287290
rdfsInversOf = owlOPE.asOWLObjectProperty().getIRI().toString();
@@ -293,7 +296,7 @@ private void transformObjectProperty(Set<OWLObjectProperty> OWLObjectPropertiesS
293296
// logger.info("old Range - " + rdfsRange);
294297
// logger.info("old Domain - " + rdfsDomain);
295298
if (rdfsRange == null || rdfsRange.isEmpty()) {
296-
for (OWLClassExpression domain : owlProp.getRanges(onto)) {
299+
for (OWLClassExpression domain : EntitySearcher.getRanges(owlProp,onto)) {
297300
if (!domain.isAnonymous()) {
298301
rdfsRange = domain.asOWLClass().getIRI().toString();
299302
} else {
@@ -307,7 +310,7 @@ private void transformObjectProperty(Set<OWLObjectProperty> OWLObjectPropertiesS
307310
}
308311
}
309312
if (rdfsDomain == null || rdfsDomain.isEmpty()) {
310-
for (OWLClassExpression domain : owlProp.getDomains(onto)) {
313+
for (OWLClassExpression domain : EntitySearcher.getDomains(owlProp,onto)) {
311314
if (!domain.isAnonymous()) {
312315
rdfsDomain = domain.asOWLClass().getIRI().toString();
313316
} else {
@@ -337,7 +340,7 @@ private void transformObjectProperty(Set<OWLObjectProperty> OWLObjectPropertiesS
337340
targetNodeID = -1;
338341
}
339342

340-
IRI ontoIRI = onto.getOntologyID().getOntologyIRI();
343+
IRI ontoIRI = onto.getOntologyID().getOntologyIRI().get();
341344
if (ontoIRI == null && rdfsIsDefinedBy != null) {
342345
ontoIRI = IRI.create(rdfsIsDefinedBy);
343346
}
@@ -436,7 +439,7 @@ private void transformClasses(Set<OWLClass> OWLClassSet, OWLOntology onto, Graph
436439
String definedBy = "";
437440
String owlVersion = "";
438441
Boolean isDeprecated = false;
439-
Set<OWLAnnotation> owl_class_annotationSET = owl_class.getAnnotations(onto);
442+
Collection<OWLAnnotation> owl_class_annotationSET = EntitySearcher.getAnnotations(owl_class,onto);
440443
for (OWLAnnotation owl_class_annotation : owl_class_annotationSET) {
441444
// extract data from owl:Class
442445
OWLAnnotationProperty owl_class_annotation_property = owl_class_annotation.getProperty();
@@ -461,7 +464,7 @@ private void transformClasses(Set<OWLClass> OWLClassSet, OWLOntology onto, Graph
461464
mod.addClassThingWithDetails(0, classID, className, classIRI, classComment, definedBy, owlVersion);
462465
} else {
463466
// check the namespace of the class if the class is imported or not
464-
IRI ontoIRI = onto.getOntologyID().getOntologyIRI();
467+
IRI ontoIRI = onto.getOntologyID().getOntologyIRI().get();
465468
if (ontoIRI == null && definedBy != null) {
466469
ontoIRI = IRI.create(definedBy);
467470
}
@@ -472,7 +475,7 @@ private void transformClasses(Set<OWLClass> OWLClassSet, OWLOntology onto, Graph
472475
mod.addClass(classID, className, classIRI, classComment, definedBy, owlVersion, isDeprecated, isImported);
473476
} else {
474477
Boolean equivalentClassHasAlreadyBeenAdded = false;
475-
for (OWLClassExpression equiClassExpression : owl_class.getEquivalentClasses(onto)) {
478+
for (OWLClassExpression equiClassExpression : EntitySearcher.getEquivalentClasses(owl_class,onto)) {
476479
if (!equiClassExpression.isAnonymous()) {
477480
// check if one the equivalent classes has already been added to the graph
478481
String equiClassIRI = equiClassExpression.asOWLClass().getIRI().toString();
@@ -489,7 +492,7 @@ private void transformClasses(Set<OWLClass> OWLClassSet, OWLOntology onto, Graph
489492
}
490493
// no equival1ent class has been added yet -> add it
491494
if (!equivalentClassHasAlreadyBeenAdded) {
492-
for (OWLClassExpression equiClassExpression : owl_class.getEquivalentClasses(onto)) {
495+
for (OWLClassExpression equiClassExpression : EntitySearcher.getEquivalentClasses(owl_class,onto)) {
493496
if (!equiClassExpression.isAnonymous()) {
494497
// take the first class with ontology namespace as equivalent class master
495498
String equiClassIRI = equiClassExpression.asOWLClass().getIRI().toString();
@@ -500,7 +503,7 @@ private void transformClasses(Set<OWLClass> OWLClassSet, OWLOntology onto, Graph
500503
String classComment2 = "";
501504
String definedBy2 = "";
502505
String owlVersion2 = "";
503-
Set<OWLAnnotation> owl_class_annotationSET2 = equiClassExpression.asOWLClass().getAnnotations(onto);
506+
Collection<OWLAnnotation> owl_class_annotationSET2 = EntitySearcher.getAnnotations(equiClassExpression.asOWLClass(),onto);
504507
Boolean isDeprecated2 = false;
505508
for (OWLAnnotation owl_class_annotation : owl_class_annotationSET2) {
506509
// extract data from owl:Class
@@ -542,7 +545,7 @@ private void transformClasses(Set<OWLClass> OWLClassSet, OWLOntology onto, Graph
542545
for (OWLEntity owl_class_entity : equiClassExpressionSignatureSet) {
543546
String equiClassIRI = owl_class_entity.getIRI().toString();
544547

545-
Set<OWLAnnotation> owl_class_annotationSET2 = owl_class_entity.getAnnotations(onto);
548+
Collection<OWLAnnotation> owl_class_annotationSET2 = EntitySearcher.getAnnotations(owl_class_entity,onto);
546549
for (OWLAnnotation owl_class_annotation : owl_class_annotationSET2) {
547550
// extract data from owl:Class
548551
OWLAnnotationProperty owl_class_annotation_property2 = owl_class_annotation.getProperty();
@@ -578,7 +581,7 @@ private void transformClasses(Set<OWLClass> OWLClassSet, OWLOntology onto, Graph
578581

579582
}
580583
// check if class has a subclass relationship (yes -> add it to the graph)
581-
for (OWLClassExpression subClassExpression : owl_class.getSubClasses(onto)) {
584+
for (OWLClassExpression subClassExpression : EntitySearcher.getSubClasses(owl_class,onto)) {
582585
if (!subClassExpression.isAnonymous()) {
583586
String subClassURI = subClassExpression.asOWLClass().getIRI().toString();
584587
// ignore subclass with the namespace of OWLClass Thing

src/graphModifier/TransformOWLtoGraphUtilities.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public String helperExtractLabelNameFromIRIIfLabelHasNoName(String name, String
120120
* @return boolean true, if the namespace is different
121121
*/
122122
public boolean hasDifferentNamespace(String elementNamespace, OWLOntology onto) {
123-
return hasDifferentNamespace(elementNamespace, onto.getOntologyID().getOntologyIRI());
123+
return hasDifferentNamespace(elementNamespace, onto.getOntologyID().getOntologyIRI().get());
124124
}
125125

126126
/**

0 commit comments

Comments
 (0)