-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathProcessOntology.groovy
151 lines (130 loc) · 6.21 KB
/
ProcessOntology.groovy
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
@Grapes([
@Grab(group="org.semanticweb.elk", module="elk-owlapi", version="0.4.3"),
@Grab(group="net.sourceforge.owlapi", module="owlapi-api", version="4.2.5"),
@Grab(group="net.sourceforge.owlapi", module="owlapi-apibinding", version="4.2.5"),
@Grab(group="net.sourceforge.owlapi", module="owlapi-impl", version="4.2.5"),
@Grab(group="net.sourceforge.owlapi", module="owlapi-parsers", version="4.2.5"),
@Grab(group="org.codehaus.gpars", module="gpars", version="1.1.0"),
@Grab(group="net.sourceforge.owlapi", module="org.semanticweb.hermit", version="1.3.8.413"),
@GrabConfig(systemClassLoader=true)
])
import org.semanticweb.owlapi.model.parameters.*;
import org.semanticweb.elk.owlapi.ElkReasonerFactory;
import org.semanticweb.elk.owlapi.ElkReasonerConfiguration;
import org.semanticweb.elk.reasoner.config.*;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.reasoner.*;
import org.semanticweb.owlapi.reasoner.structural.StructuralReasoner
import org.semanticweb.owlapi.vocab.OWLRDFVocabulary;
import org.semanticweb.owlapi.model.*;
import org.semanticweb.owlapi.io.*;
import org.semanticweb.owlapi.owllink.*;
import org.semanticweb.owlapi.util.*;
import org.semanticweb.owlapi.search.*;
import org.semanticweb.owlapi.manchestersyntax.renderer.*;
import org.semanticweb.owlapi.reasoner.structural.*;
import uk.ac.manchester.cs.owlapi.modularity.ModuleType;
import uk.ac.manchester.cs.owlapi.modularity.SyntacticLocalityModuleExtractor;
import org.semanticweb.owlapi.manchestersyntax.renderer.*;
import java.io.*;
import java.io.PrintWriter;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.*;
import org.semanticweb.owlapi.reasoner.InferenceType;
import org.semanticweb.owlapi.util.InferredAxiomGenerator;
import org.semanticweb.owlapi.util.InferredOntologyGenerator;
import org.semanticweb.owlapi.util.InferredSubClassAxiomGenerator;
import org.semanticweb.owlapi.util.InferredEquivalentClassAxiomGenerator;
import org.semanticweb.owlapi.reasoner.OWLReasonerFactory;
import org.semanticweb.owlapi.reasoner.OWLReasoner;
import org.semanticweb.HermiT.Reasoner;
import org.semanticweb.owlapi.reasoner.OWLReasonerConfiguration;
import groovyx.gpars.GParsPool;
OWLOntologyManager outputManager = OWLManager.createOWLOntologyManager();
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
String ontostring = args[0];
String prefreasoner =args[1];
OWLOntology ont = manager.loadOntologyFromOntologyDocument(new File(ontostring));
public class SimpleShortFormProvider1 implements ShortFormProvider, Serializable {
private final SimpleIRIShortFormProvider uriShortFormProvider = new SimpleIRIShortFormProvider();
@Override
public String getShortForm(OWLEntity entity) {
return '<'+entity.getIRI().toString()+'>';
}
public void dispose(){
;
}
}
if (prefreasoner.toLowerCase().equals("elk"))
{
OWLDataFactory dataFactory = manager.getOWLDataFactory()
OWLDataFactory fac = manager.getOWLDataFactory()
ConsoleProgressMonitor progressMonitor = new ConsoleProgressMonitor()
OWLReasonerConfiguration config = new SimpleConfiguration(progressMonitor)
ElkReasonerFactory f1 = new ElkReasonerFactory()
OWLReasoner reasoner = f1.createReasoner(ont, config)
reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY)
List<InferredAxiomGenerator<? extends OWLAxiom>> gens = new ArrayList<InferredAxiomGenerator<? extends OWLAxiom>>();
gens.add(new InferredSubClassAxiomGenerator());
gens.add(new InferredEquivalentClassAxiomGenerator());
OWLOntology infOnt = outputManager.createOntology();
InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner,gens);
iog.fillOntology(outputManager.getOWLDataFactory(), infOnt);
// Save the inferred ontology.
//outputManager.saveOntology(infOnt,IRI.create((new File("inferredontologygo2.owl").toURI())));
// Display Axioms
OWLObjectRenderer renderer =new ManchesterOWLSyntaxOWLObjectRendererImpl ();
renderer.setShortFormProvider(new SimpleShortFormProvider1());
int numaxiom1= infOnt.getAxiomCount();
Set<OWLClass> classes=infOnt.getClassesInSignature();
//display original axioms
//int numaxiom1= Ont.getAxiomCount();
Set<OWLClass> classeso=ont.getClassesInSignature();
FileWriter fwo= new FileWriter ("axiomsorig.lst");
BufferedWriter bwo =new BufferedWriter (fwo);
PrintWriter outo =new PrintWriter (bwo);
for (OWLClass classo : classeso)
{
Set<OWLClassAxiom> ontoaxioms=ont.getAxioms (classo);
for (OWLClassAxiom claxiom: ontoaxioms)
{
// classess=renderer.render(class1);
classaxiom=renderer.render (claxiom);
//out1.println (classess);
outo.println (classaxiom.replaceAll("\n"," ").replaceAll(","," "));
}
}
outo.flush() //Tilman comment
} else {
OWLReasonerFactory reasonerFactory = new Reasoner.ReasonerFactory();
OWLReasoner reasoner =reasonerFactory.createReasoner(ont);
OWLDataFactory factory=manager.getOWLDataFactory();
reasoner.precomputeInferences();
InferredSubClassAxiomGenerator generator = new InferredSubClassAxiomGenerator();
Set<OWLAxiom> axioms = generator.createAxioms(factory, reasoner);
manager.addAxioms(ont,axioms);
OWLObjectRenderer renderer =new ManchesterOWLSyntaxOWLObjectRendererImpl ();
renderer.setShortFormProvider(new SimpleShortFormProvider1());
Set<OWLClass> classes=ont.getClassesInSignature();
FileWriter fw= new FileWriter ("axiomsinf.lst");
BufferedWriter bw =new BufferedWriter (fw);
PrintWriter out =new PrintWriter (bw);
FileWriter fw1= new FileWriter ("classes.lst");
BufferedWriter bw1 =new BufferedWriter (fw1);
PrintWriter out1 =new PrintWriter (bw1);
for (OWLClass class1 : classes)
{
Set<OWLClassAxiom> ontoaxioms=ont.getAxioms (class1);
for (OWLClassAxiom claxiom: ontoaxioms)
{
classess=renderer.render(class1);
classaxiom=renderer.render (claxiom);
out1.println (classess);
out.println (classaxiom.replaceAll("\n"," ").replaceAll(","," "));
}
}
FileWriter fwo= new FileWriter ("axiomsorig.lst"); BufferedWriter bwo =new BufferedWriter (fwo); PrintWriter outo =new PrintWriter (bwo);
outo.println(" ");
outo.flush()
outo.close()
}