use of org.semanticweb.owlapi.model.OWLOntologyID in project stanbol by apache.
the class TestOWLUtils method lookaheadVersionedImmediate.
/*
* Guessing the ID of a versioned ontology whose ID is at the beginning of the graph.
*/
@Test
public void lookaheadVersionedImmediate() throws Exception {
String location = "/owl/versioned_immediate.owl";
log.info("Testing lookahead for location {}", location);
org.semanticweb.owlapi.model.IRI incubatedVersion = org.semanticweb.owlapi.model.IRI.create("http://svn.apache.org/repos/asf/incubator/stanbol/trunk/commons/owl/src/test/resources/owl/versioned_immediate.owl");
OWLOntologyID expectedOntId = new OWLOntologyID(ontologyIri, incubatedVersion);
// Try a low triple limit (the ontology IRI triple is much further).
InputStream content = getClass().getResourceAsStream(location);
OWLOntologyID id = OWLUtils.guessOntologyID(content, parser, RDF_XML, 10);
assertNotNull(id);
assertEquals(expectedOntId, id);
}
use of org.semanticweb.owlapi.model.OWLOntologyID in project stanbol by apache.
the class TestOWLUtils method lookaheadVersioned.
/*
* Guessing the ID of a versioned ontology whose IRIs are grouped at the end of the graph.
*/
@Test
public void lookaheadVersioned() throws Exception {
// Identifiers are at position > 10 . Triples are grouped.
// Minimum offset required is 2 because of an owl:versionInfo triple in-between.
String location = "/owl/versioned.owl";
log.info("Testing lookahead for location {}", location);
org.semanticweb.owlapi.model.IRI incubatedVersion = org.semanticweb.owlapi.model.IRI.create("http://svn.apache.org/repos/asf/incubator/stanbol/trunk/commons/owl/src/test/resources/owl/versioned.owl");
OWLOntologyID expectedOntId = new OWLOntologyID(ontologyIri, incubatedVersion);
// Low triple limit: guessing should fail.
InputStream content = getClass().getResourceAsStream(location);
OWLOntologyID id = OWLUtils.guessOntologyID(content, parser, RDF_XML, 10);
assertTrue(id.isAnonymous());
// Reasonable triple limit with low offset: guessing should return the unversioned ID.
content = getClass().getResourceAsStream(location);
id = OWLUtils.guessOntologyID(content, parser, RDF_XML, 256, 1);
assertNotNull(id);
assertFalse(id.isAnonymous());
assertEquals(new OWLOntologyID(ontologyIri), id);
// Reasonable triple limit with auto offset: guessing should succeed.
content = getClass().getResourceAsStream(location);
id = OWLUtils.guessOntologyID(content, parser, RDF_XML, 256);
assertNotNull(id);
assertFalse(id.isAnonymous());
assertEquals(expectedOntId, id);
// No triple limit: guessing should succeed.
content = getClass().getResourceAsStream(location);
id = OWLUtils.guessOntologyID(content, parser, RDF_XML);
assertNotNull(id);
assertFalse(id.isAnonymous());
assertEquals(expectedOntId, id);
}
use of org.semanticweb.owlapi.model.OWLOntologyID in project stanbol by apache.
the class TestOWLUtils method lookaheadNamedImmediate.
/*
* Guessing the ID of a named ontology whose IRI is at the beginning of the graph.
*/
@Test
public void lookaheadNamedImmediate() throws Exception {
String location = "/owl/named_immediate.owl";
log.info("Testing lookahead for location {}", location);
// Try a low triple limit (the ontology IRI triple is much further).
InputStream content = getClass().getResourceAsStream(location);
OWLOntologyID id = OWLUtils.guessOntologyID(content, parser, RDF_XML, 10);
assertNotNull(id);
assertEquals(new OWLOntologyID(ontologyIri), id);
}
use of org.semanticweb.owlapi.model.OWLOntologyID in project stanbol by apache.
the class OWLUtils method extractOntologyID.
/**
* Returns the logical identifier of the supplied RDF graph, which is interpreted as an OWL ontology.
*
* @param graph
* the RDF graph
* @return the OWL ontology ID of the supplied graph, or null if it denotes an anonymous ontology.
*/
public static OWLOntologyID extractOntologyID(Graph graph) {
IRI ontologyIri = null, versionIri = null;
Iterator<Triple> it = graph.filter(null, RDF.type, OWL.Ontology);
if (it.hasNext()) {
BlankNodeOrIRI subj = it.next().getSubject();
if (it.hasNext()) {
log.warn("Multiple OWL ontology definitions found.");
log.warn("Ignoring all but {}", subj);
}
if (subj instanceof org.apache.clerezza.commons.rdf.IRI) {
ontologyIri = IRI.create(((org.apache.clerezza.commons.rdf.IRI) subj).getUnicodeString());
Iterator<Triple> it2 = graph.filter(subj, new org.apache.clerezza.commons.rdf.IRI(OWL2Constants.OWL_VERSION_IRI), null);
if (it2.hasNext())
versionIri = IRI.create(((org.apache.clerezza.commons.rdf.IRI) it2.next().getObject()).getUnicodeString());
}
}
if (ontologyIri == null) {
// Note that OWL 2 does not allow ontologies with a version IRI and no ontology IRI.
log.debug("Ontology is anonymous. Returning null ID.");
return null;
}
if (versionIri == null)
return new OWLOntologyID(ontologyIri);
else
return new OWLOntologyID(ontologyIri, versionIri);
}
use of org.semanticweb.owlapi.model.OWLOntologyID in project stanbol by apache.
the class OWLUtils method extractOntologyID.
/**
* If the ontology is named, this method will return its logical ID, otherwise it will return the location
* it was retrieved from (which is still unique).
*
* @param o
* @return
*/
public static OWLOntologyID extractOntologyID(OWLOntology o) {
String oiri;
IRI viri = null;
// For anonymous ontologies, it is the URI they were fetched from, if any.
if (o.isAnonymous())
oiri = o.getOWLOntologyManager().getOntologyDocumentIRI(o).toString();
else {
OWLOntologyID id = o.getOntologyID();
oiri = id.getOntologyIRI().toString();
viri = id.getVersionIRI();
}
// Strip fragment or query tokens. TODO do proper URL Encoding.
while (oiri.endsWith("#") || oiri.endsWith("?")) oiri = oiri.substring(0, oiri.length() - 1);
if (viri != null)
return new OWLOntologyID(IRI.create(oiri), viri);
else
return new OWLOntologyID(IRI.create(oiri));
}
Aggregations