Search in sources :

Example 11 with OWLOntologyID

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);
}
Also used : InputStream(java.io.InputStream) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) Test(org.junit.Test)

Example 12 with OWLOntologyID

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);
}
Also used : InputStream(java.io.InputStream) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) Test(org.junit.Test)

Example 13 with OWLOntologyID

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);
}
Also used : InputStream(java.io.InputStream) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) Test(org.junit.Test)

Example 14 with OWLOntologyID

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);
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) IRI(org.semanticweb.owlapi.model.IRI) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI)

Example 15 with OWLOntologyID

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));
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID)

Aggregations

OWLOntologyID (org.semanticweb.owlapi.model.OWLOntologyID)101 Test (org.junit.Test)32 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)32 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)23 HashSet (java.util.HashSet)22 OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)21 InputStream (java.io.InputStream)20 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)19 Triple (org.apache.clerezza.commons.rdf.Triple)19 IRI (org.semanticweb.owlapi.model.IRI)18 IRI (org.apache.clerezza.commons.rdf.IRI)17 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)16 RDFTerm (org.apache.clerezza.commons.rdf.RDFTerm)13 IOException (java.io.IOException)12 UnmodifiableOntologyCollectorException (org.apache.stanbol.ontologymanager.servicesapi.collector.UnmodifiableOntologyCollectorException)12 WebApplicationException (javax.ws.rs.WebApplicationException)11 Graph (org.apache.clerezza.commons.rdf.Graph)10 AddImport (org.semanticweb.owlapi.model.AddImport)10 Path (javax.ws.rs.Path)9 OntologySpace (org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace)8