-
Notifications
You must be signed in to change notification settings - Fork 4
/
RetrievePrefixesModule.java
95 lines (80 loc) · 3.1 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
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
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;
/**
* Module retrieves metadata of all prefixes from scripts.
* Metadata is represented as RDF triple:
* ja:PrefixMapping
* [ a ja:SinglePrefixMapping ;
* ja:namespace namespaceURI ;
* ja:prefix prefix
* ] ;
* Example script content:
* @prefix : <http://example.org/> .
* @prefix owl: <http://www.w3.org/2002/07/owl#> .
*
*
* :my-ontology a owl:Ontology .
*
* Example output:
* @prefix : <http://example.org/> .
* @prefix ja: <http://jena.hpl.hp.com/2005/11/Assembler#>
* :my-ontology
* ja:prefixMapping
* [ a ja:SinglePrefixMapping ;
* ja:namespace
* "http://www.w3.org/2002/07/owl#" ;
* ja:prefix
* "owl"
* ] ;
*/
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, 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;
}
}