-
Notifications
You must be signed in to change notification settings - Fork 0
/
Normalizer.groovy
84 lines (73 loc) · 3.34 KB
/
Normalizer.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
@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="de.tu-dresden.inf.lat.jcel", module="jcel-owlapi", version="0.24.1"),
@Grab(group='commons-cli', module='commons-cli', version='1.4'),
@GrabConfig(systemClassLoader=true)
])
import org.semanticweb.owlapi.apibinding.OWLManager
import org.semanticweb.owlapi.functional.renderer.OWLFunctionalSyntaxRenderer
import org.semanticweb.owlapi.io.AbstractOWLRenderer
import org.semanticweb.owlapi.io.OWLRendererException
import org.semanticweb.owlapi.krss2.renderer.KRSS2OWLSyntaxRenderer
import org.semanticweb.owlapi.krss2.renderer.KRSS2SyntaxRenderer
import org.semanticweb.owlapi.krss2.renderer.KRSSSyntaxRenderer
import org.semanticweb.owlapi.latex.renderer.LatexRenderer
import org.semanticweb.owlapi.manchestersyntax.renderer.*
import org.semanticweb.owlapi.model.IRI
import org.semanticweb.owlapi.model.OWLDataFactory
import org.semanticweb.owlapi.model.OWLOntology
import org.semanticweb.owlapi.model.OWLOntologyCreationException
import org.semanticweb.owlapi.model.OWLOntologyManager
import org.semanticweb.owlapi.owlxml.renderer.OWLXMLRenderer
import org.semanticweb.owlapi.reasoner.InferenceType
import de.tudresden.inf.lat.jcel.owlapi.main.*
import de.tudresden.inf.lat.jcel.reasoner.main.VersionInfo
import de.tudresden.inf.lat.jcel.reasoner.main.*
import de.tudresden.inf.lat.jcel.ontology.normalization.*
import de.tudresden.inf.lat.jcel.ontology.axiom.extension.*
import de.tudresden.inf.lat.jcel.coreontology.axiom.*
import de.tudresden.inf.lat.jcel.owlapi.translator.*
import de.tudresden.inf.lat.jcel.ontology.axiom.complex.*
def cli = new CliBuilder()
cli.with {
usage: 'Self'
h longOpt:'help', 'this information'
i longOpt:'input', 'input OWL file', args:1, required:true
o longOpt:'output', 'output file containing normalized axioms',args:1, required:true
}
def opt = cli.parse(args)
if( !opt ) {
// cli.usage()
return
}
if( opt.h ) {
cli.usage()
return
}
// input: OWL file
File ontologyFile = new File(opt.i)
// output: contains all normalized axioms in OWL Functional Syntax
PrintWriter fout = new PrintWriter(new BufferedWriter(new FileWriter(opt.o)))
OWLOntologyManager manager = OWLManager.createOWLOntologyManager()
OWLOntology ontology = manager.loadOntologyFromOntologyDocument(ontologyFile)
JcelReasoner ret = new JcelReasoner(ontology, false)
def translator = ret.getTranslator()
Set<ComplexIntegerAxiom> iOntology = ret.getIntegerOntology()
OntologyNormalizer normalizer = new OntologyNormalizer()
IntegerOntologyObjectFactory factory = new IntegerOntologyObjectFactoryImpl()
Set<NormalizedIntegerAxiom> normalizedOntology = normalizer.normalize(iOntology, factory)
def renderer = new ManchesterOWLSyntaxOWLObjectRendererImpl()
ReverseAxiomTranslator rTranslator = new ReverseAxiomTranslator(translator, ontology)
normalizedOntology.each { ax ->
try {
fout.println(renderer.render(rTranslator.visit(ax)))
} catch (Exception E) {
println "Ignoring $ax:" + E.getMessage()
}
}
fout.flush()
fout.close()