-
Notifications
You must be signed in to change notification settings - Fork 4
/
RetrievePrefixesModule.java
68 lines (53 loc) · 2.3 KB
/
RetrievePrefixesModule.java
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
package cz.cvut.spipes.modules;
import cz.cvut.spipes.constants.KBSS_MODULE;
import cz.cvut.spipes.constants.SML;
import cz.cvut.spipes.engine.ExecutionContext;
import cz.cvut.spipes.manager.OntoDocManager;
import cz.cvut.spipes.manager.OntologyDocumentManager;
import org.apache.jena.assembler.JA;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.vocabulary.RDF;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class RetrievePrefixesModule extends AbstractModule {
private static final Logger LOG = LoggerFactory.getLogger(RetrievePrefixesModule.class.getName());
private static String TYPE_URI = KBSS_MODULE.getURI() + "retrieve-prefixes";
//sml:replace
private boolean isReplace;
//TODO refactor -> should be part of execution context
OntologyDocumentManager ontologyDocumentManager = OntoDocManager.getInstance();
@Override
ExecutionContext executeSelf() {
Model outputModel = ModelFactory.createDefaultModel();
for (String ontologyUri : ontologyDocumentManager.getRegisteredOntologyUris()) {
Resource ontology = outputModel.createResource(ontologyUri);
ontologyDocumentManager.getOntology(ontologyUri).getNsPrefixMap().forEach((key, value) -> {
Resource singlePrefixMapping = outputModel.createResource();
outputModel.add(ontology, JA.prefixMapping, singlePrefixMapping);
outputModel.add(
singlePrefixMapping, RDF.type, JA.SinglePrefixMapping
);
outputModel.add(
singlePrefixMapping, JA.prefix, key
);
outputModel.add(
singlePrefixMapping, JA.namespace, value
);
});
}
return this.createOutputContext(isReplace, executionContext.getDefaultModel(), outputModel);
}
@Override
public String getTypeURI() {
return TYPE_URI;
}
@Override
public void loadConfiguration() {
isReplace = this.getPropertyValue(SML.replace, false);
}
void setOntologyDocumentManager(OntologyDocumentManager ontologyDocumentManager) {
this.ontologyDocumentManager = ontologyDocumentManager;
}
}