use of org.apache.clerezza.commons.rdf.ImmutableGraph in project stanbol by apache.
the class ScopeImpl method exportToGraph.
/**
* Get a Clerezza {@link Graph} representation of the scope.
*
* @param merge
* if true the core and custom spaces will be recursively merged with the scope graph,
* otherwise owl:imports statements will be added.
* @return the RDF representation of the scope as a modifiable graph.
*/
protected Graph exportToGraph(boolean merge, org.semanticweb.owlapi.model.IRI universalPrefix) {
// No need to store, give it a name, or anything.
Graph root = new SimpleGraph();
IRI iri = new IRI(universalPrefix + getID());
if (root != null) {
// Set the ontology ID
root.add(new TripleImpl(iri, RDF.type, OWL.Ontology));
if (merge) {
ImmutableGraph custom, core;
// Get the subjects of "bad" triples (those with subjects of type owl:Ontology).
Iterator<Triple> it;
Set<BlankNodeOrIRI> ontologies = new HashSet<BlankNodeOrIRI>();
Set<RDFTerm> importTargets = new HashSet<RDFTerm>();
custom = this.getCustomSpace().export(ImmutableGraph.class, merge);
// root.addAll(space);
it = custom.filter(null, RDF.type, OWL.Ontology);
while (it.hasNext()) ontologies.add(it.next().getSubject());
it = custom.filter(null, OWL.imports, null);
while (it.hasNext()) importTargets.add(it.next().getObject());
core = this.getCoreSpace().export(ImmutableGraph.class, merge);
// root.addAll(space);
it = core.filter(null, RDF.type, OWL.Ontology);
while (it.hasNext()) ontologies.add(it.next().getSubject());
it = core.filter(null, OWL.imports, null);
while (it.hasNext()) importTargets.add(it.next().getObject());
// Make sure the scope itself is not in the "bad" subjects.
ontologies.remove(iri);
for (BlankNodeOrIRI nl : ontologies) log.debug("{} -related triples will not be added to {}", nl, iri);
// Merge the two spaces, skipping the "bad" triples.
log.debug("Merging custom space of {}.", getID());
for (Triple t : custom) if (!ontologies.contains(t.getSubject()))
root.add(t);
log.debug("Merging core space of {}.", getID());
for (Triple t : core) if (!ontologies.contains(t.getSubject()))
root.add(t);
/*
* Reinstate import statements, though. If imported ontologies were not merged earlier, we are
* not doing it now anyway.
*/
for (RDFTerm target : importTargets) root.add(new TripleImpl(iri, OWL.imports, target));
} else {
IRI physIRI = new IRI(universalPrefix.toString() + this.getID() + "/" + SpaceType.CUSTOM.getIRISuffix());
root.add(new TripleImpl(iri, OWL.imports, physIRI));
physIRI = new IRI(universalPrefix.toString() + this.getID() + "/" + SpaceType.CORE.getIRISuffix());
root.add(new TripleImpl(iri, OWL.imports, physIRI));
}
}
return root;
}
use of org.apache.clerezza.commons.rdf.ImmutableGraph in project stanbol by apache.
the class ZemantaAPIWrapper method parseResponse.
private ImmutableGraph parseResponse(InputStream is) {
JenaParserProvider jenaParserProvider = new JenaParserProvider();
//NOTE(rw): the new third parameter is the base URI used to resolve relative paths
Graph g = new SimpleGraph();
jenaParserProvider.parse(g, is, SupportedFormat.RDF_XML, null);
log.debug("graph: " + g.toString());
return g.getImmutableGraph();
}
use of org.apache.clerezza.commons.rdf.ImmutableGraph in project stanbol by apache.
the class ZemantaAPIWrapper method enhance.
public ImmutableGraph enhance(String textToAnalyze) throws IOException {
InputStream is = sendRequest(textToAnalyze);
ImmutableGraph zemantaResponseGraph = parseResponse(is);
return zemantaResponseGraph;
}
use of org.apache.clerezza.commons.rdf.ImmutableGraph in project stanbol by apache.
the class TopicEngineTest method testImportModelFromSKOS.
@Test
public void testImportModelFromSKOS() throws Exception {
log.info(" --- testImportModelFromSKOS --- ");
Parser parser = Parser.getInstance();
parser.bindParsingProvider(new JenaParserProvider());
ImmutableGraph graph = parser.parse(getClass().getResourceAsStream("/sample-scheme.skos.rdf.xml"), SupportedFormat.RDF_XML);
int imported = classifier.importConceptsFromGraph(graph, OntologicalClasses.SKOS_CONCEPT, Properties.SKOS_BROADER);
assertEquals(imported, 4);
assertEquals(0, classifier.getBroaderConcepts("http://example.com/ns#someconceptscheme/100").size());
assertEquals(0, classifier.getBroaderConcepts("http://example.com/ns#someconceptscheme/200").size());
assertEquals(1, classifier.getBroaderConcepts("http://example.com/ns#someconceptscheme/010").size());
assertEquals(1, classifier.getBroaderConcepts("http://example.com/ns#someconceptscheme/020").size());
assertEquals(2, classifier.getRootConcepts().size());
}
use of org.apache.clerezza.commons.rdf.ImmutableGraph in project stanbol by apache.
the class TestAxiomInterpretation method testCustomAboxCoreTbox.
@Test
public void testCustomAboxCoreTbox() throws Exception {
String path = "/ontologies/imports-disconnected";
InputStream content = getClass().getResourceAsStream(path + "/abox.owl");
OntologyInputSource<?> coreSrc = new GraphContentInputSource(content, SupportedFormat.TURTLE);
Scope scope = onManager.createOntologyScope("imports-disconnected", coreSrc);
assertNotNull(scope);
content = getClass().getResourceAsStream(path + "/tbox.owl");
OntologyInputSource<?> custSrc = new GraphContentInputSource(content, SupportedFormat.TURTLE);
scope.getCustomSpace().addOntology(custSrc);
ImmutableGraph g = scope.export(ImmutableGraph.class, true);
// for (Triple t : g)
// System.out.println(t);
//
// OWLOntology o = scope.export(OWLOntology.class, true);
// for (OWLAxiom ax : o.getAxioms())
// System.out.println(ax);
}
Aggregations