-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLoadUnivBench.java
More file actions
143 lines (114 loc) · 5.66 KB
/
Copy pathLoadUnivBench.java
File metadata and controls
143 lines (114 loc) · 5.66 KB
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
package loader;
import database.Configuration;
import database.DBInitException;
import database.impl.Cassandra;
import loader.impl.*;
import openllet.owlapi.OpenlletReasoner;
import openllet.owlapi.OpenlletReasonerFactory;
import org.apache.log4j.Logger;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.model.parameters.Imports;
import org.semanticweb.owlapi.util.SimpleIRIMapper;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.Stream;
public class LoadUnivBench {
private final static Logger LOGGER = Logger.getLogger(LoadUnivBench.class);
public static void main(String[] argv) {
Configuration conf = new Configuration();
Cassandra connection = new Cassandra(conf);
LOGGER.info("Connecting to Cassandra");
try {
connection.connect();
LOGGER.info("Dropping keyspace");
connection.dropDatabaseIfExists();
LOGGER.info("Recreating keyspace");
connection.createDatabaseIfNotExists();
} catch (DBInitException e) {
e.printStackTrace();
}
File ontology = new File("examples/Univ-bench/univ-bench.owl");
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
// Manually map imports
IRI documentIRI = IRI.create(ontology);
IRI ontologyIRI = IRI.create("http://swat.cse.lehigh.edu/onto/univ-bench.owl");
SimpleIRIMapper mapper = new SimpleIRIMapper(ontologyIRI, documentIRI);
manager.getIRIMappers().add(mapper);
LoaderClassIndividuals loaderClassIndividuals = new LoaderClassIndividuals(connection, manager);
LoaderPropIndividuals loaderPropIndividuals = new LoaderPropIndividuals(connection, manager);
try (Stream<Path> paths = Files.walk(Paths.get("examples/Univ-bench/individuals/"))) {
OWLOntologyManager finalManager = manager;
paths
.sorted()
.filter(Files::isRegularFile)
.map(Path::toFile)
.forEach(individual -> {
LOGGER.info(String.format("Found document %s", individual));
try {
LOGGER.info("Reading ontology from document");
OWLOntology knowledgeGraph = finalManager.loadOntologyFromOntologyDocument(individual);
LOGGER.info("Loaded!");
loaderClassIndividuals
.loadOWLOntology(knowledgeGraph, Imports.EXCLUDED)
.forEach(connection::executeAsyncWithSession);
loaderPropIndividuals
.loadOWLOntology(knowledgeGraph)
.forEach(connection::executeAsyncWithSession);
} catch (OWLOntologyCreationException e) {
e.printStackTrace();
}
});
} catch (IOException e) {
e.printStackTrace();
}
try {
manager = OWLManager.createOWLOntologyManager();
OWLOntology TBox = manager.loadOntologyFromOntologyDocument(ontology);
OpenlletReasoner reasoner = OpenlletReasonerFactory.getInstance().createReasoner(TBox);
loaderClassIndividuals
.loadOWLOntology(TBox)
.forEach(connection::executeAsyncWithSession);
loaderPropIndividuals
.loadOWLOntology(TBox)
.forEach(connection::executeAsyncWithSession);
new LoaderDisjointClasses(connection, manager, reasoner)
.loadOWLOntology(TBox)
.forEach(connection::executeAsyncWithSession);
new LoaderEquivalentClasses(connection, manager, reasoner)
.loadOWLOntology(TBox)
.forEach(connection::executeAsyncWithSession);
new LoaderObjectPropertyDomains(connection, manager, reasoner)
.loadOWLOntology(TBox)
.forEach(connection::executeAsyncWithSession);
new LoaderObjectPropertyEquivalentClasses(connection, manager, reasoner)
.loadOWLOntology(TBox)
.forEach(connection::executeAsyncWithSession);
new LoaderObjectPropertyInverses(connection, manager, reasoner)
.loadOWLOntology(TBox)
.forEach(connection::executeAsyncWithSession);
new LoaderObjectPropertyRanges(connection, manager, reasoner)
.loadOWLOntology(TBox)
.forEach(connection::executeAsyncWithSession);
new LoaderObjectPropertySubProperties(connection, manager, reasoner)
.loadOWLOntology(TBox)
.forEach(connection::executeAsyncWithSession);
new LoaderSubClasses(connection, manager, reasoner)
.loadOWLOntology(TBox)
.forEach(connection::executeAsyncWithSession);
new LoaderSupClasses(connection, manager, reasoner)
.loadOWLOntology(TBox)
.forEach(connection::executeAsyncWithSession);
} catch (Exception e) {
e.printStackTrace();
}
LOGGER.info("Completed");
connection.disconnect();
}
}