blob: 50865d4659fffabf29cafe292904b843624b28be (
plain) (
blame)
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
|
package uk.ac.ox.cs.pagoda.owl;
import java.io.File;
import java.io.IOException;
import org.semanticweb.HermiT.Configuration;
import org.semanticweb.HermiT.model.AnnotatedEquality;
import org.semanticweb.HermiT.model.AtLeast;
import org.semanticweb.HermiT.model.Atom;
import org.semanticweb.HermiT.model.DLClause;
import org.semanticweb.HermiT.model.DLOntology;
import org.semanticweb.HermiT.model.DLPredicate;
import org.semanticweb.HermiT.model.Equality;
import org.semanticweb.HermiT.model.Inequality;
import org.semanticweb.HermiT.structural.OWLClausification;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLAnnotationAxiom;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLClassAssertionAxiom;
import org.semanticweb.owlapi.model.OWLDataPropertyAssertionAxiom;
import org.semanticweb.owlapi.model.OWLDeclarationAxiom;
import org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.model.OWLOntologyStorageException;
import org.semanticweb.owlapi.model.OWLTransitiveObjectPropertyAxiom;
import org.semanticweb.owlapi.model.UnknownOWLOntologyException;
import uk.ac.ox.cs.pagoda.hermit.TermGraph;
import uk.ac.ox.cs.pagoda.util.Utility;
public class EqualitiesEliminator {
String fileName;
OWLOntologyManager manager;
OWLOntology inputOntology, outputOntology = null;
public EqualitiesEliminator(OWLOntology o) {
this.fileName = OWLHelper.getOntologyPath(o);
inputOntology = o;
manager = inputOntology.getOWLOntologyManager();
}
public void removeEqualities() throws OWLOntologyCreationException {
outputOntology = manager.createOntology(IRI.create(inputOntology.getOntologyID().getOntologyIRI().toString().replace(".owl", "-minus.owl")));
try {
manager.setOntologyDocumentIRI(outputOntology, IRI.create(Utility.toFileIRI(getOutputFile().getCanonicalPath())));
} catch (UnknownOWLOntologyException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
for (OWLOntology onto: inputOntology.getImportsClosure())
for (OWLAxiom axiom: onto.getAxioms()) {
if (axiom instanceof OWLAnnotationAxiom
|| axiom instanceof OWLDeclarationAxiom
|| axiom instanceof OWLTransitiveObjectPropertyAxiom
|| axiom instanceof OWLClassAssertionAxiom
|| axiom instanceof OWLObjectPropertyAssertionAxiom
|| axiom instanceof OWLDataPropertyAssertionAxiom
) {
manager.removeAxiom(onto, axiom);
manager.addAxiom(outputOntology, axiom);
}
}
Configuration conf = new Configuration();
OWLClausification clausifier = new OWLClausification(conf);
DLOntology dlOntology = (DLOntology)clausifier.preprocessAndClausify(inputOntology, null)[1];
TermGraph termGraph;
for (DLClause dlClause: dlOntology.getDLClauses()) {
if (!containsEqualities(dlClause)) {
termGraph = new TermGraph(dlClause);
manager.addAxiom(outputOntology, OWLHelper.getOWLAxiom(inputOntology, termGraph.simplify()));
}
}
}
private boolean containsEqualities(DLClause dlClause) {
DLPredicate predicate;
for (Atom headAtom: dlClause.getHeadAtoms()) {
predicate = headAtom.getDLPredicate();
if (predicate instanceof Equality || predicate instanceof AnnotatedEquality || predicate instanceof Inequality) {
return true;
}
if (predicate instanceof AtLeast) {
AtLeast atLeast = (AtLeast) predicate;
if (atLeast.getNumber() >= 2)
return true;
}
}
return false;
}
public void save() {
if (outputOntology == null)
try {
removeEqualities();
} catch (OWLOntologyCreationException e) {
e.printStackTrace();
return ;
}
try {
manager.saveOntology(outputOntology, IRI.create(getOutputFile()));
} catch (OWLOntologyStorageException e) {
e.printStackTrace();
}
}
public File getOutputFile() {
return new File(fileName.replace(".owl", "-minus.owl"));
}
public OWLOntology getOutputOntology() {
if (outputOntology == null)
try {
removeEqualities();
} catch (OWLOntologyCreationException e) {
e.printStackTrace();
}
return outputOntology;
}
public static void main(String[] args) throws OWLOntologyCreationException, OWLOntologyStorageException {
args = ("/home/yzhou/ontologies/uobm/univ-bench-dl.owl").split("\\ ");
EqualitiesEliminator eliminator = new EqualitiesEliminator(OWLHelper.loadOntology(args[0]));
eliminator.save();
}
}
|