Search in sources :

Example 6 with OWLOntologyID

use of org.semanticweb.owlapi.model.OWLOntologyID in project webprotege by protegeproject.

the class OntologyIdData_CustomFieldSerializer method serialize.

public static void serialize(SerializationStreamWriter streamWriter, OntologyIdData instance) throws SerializationException {
    OWLOntologyID ontologyID = instance.getObject();
    streamWriter.writeBoolean(ontologyID.isAnonymous());
    if (!ontologyID.isAnonymous()) {
        streamWriter.writeString(ontologyID.getOntologyIRI().toString());
        if (ontologyID.getVersionIRI() != null) {
            streamWriter.writeString(ontologyID.getVersionIRI().toString());
        } else {
            streamWriter.writeString("");
        }
    }
    streamWriter.writeString(instance.getBrowserText());
}
Also used : OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID)

Example 7 with OWLOntologyID

use of org.semanticweb.owlapi.model.OWLOntologyID in project stanbol by apache.

the class TestClerezzaSpaces method testCreateSpace.

@Test
public void testCreateSpace() throws Exception {
    OntologySpace space = factory.createCustomOntologySpace(scopeId, dropSrc);
    OWLOntologyID logicalId = null;
    Object o = dropSrc.getRootOntology();
    if (o instanceof Graph)
        logicalId = OWLUtils.extractOntologyID((Graph) o);
    else if (o instanceof OWLOntology)
        logicalId = OWLUtils.extractOntologyID((OWLOntology) o);
    assertNotNull(logicalId);
    assertTrue(space.hasOntology(logicalId));
}
Also used : Graph(org.apache.clerezza.commons.rdf.Graph) OntologySpace(org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) Test(org.junit.Test)

Example 8 with OWLOntologyID

use of org.semanticweb.owlapi.model.OWLOntologyID in project stanbol by apache.

the class LibraryImpl method loadOntologies.

@Override
public synchronized void loadOntologies(OntologyProvider<?> loader) {
    if (loader == null)
        throw new IllegalArgumentException("A null loader is not allowed.");
    for (RegistryItem item : getChildren()) {
        if (item instanceof RegistryOntology) {
            RegistryOntology o = (RegistryOntology) item;
            IRI id = o.getIRI();
            try {
                // No preferred key, we don't have a prefix here.
                OWLOntologyID key = loader.loadInStore(id, null, false);
                if (key == null || key.isAnonymous())
                    log.error("Empty storage key. Ontology {} was apparently not stored.", id);
            } catch (IOException ex) {
                log.error("I/O error occurred loading {}", id);
            }
        }
    }
    loaded = true;
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) RegistryOntology(org.apache.stanbol.ontologymanager.registry.api.model.RegistryOntology) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) IOException(java.io.IOException) RegistryItem(org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem)

Example 9 with OWLOntologyID

use of org.semanticweb.owlapi.model.OWLOntologyID in project stanbol by apache.

the class HermitReasoningServiceTest method testRun.

private void testRun(String testID, String expectedID) {
    log.info("Testing the run() method");
    OWLOntologyManager manager = TestData.manager;
    // We prepare the input ontology
    try {
        OWLOntology testOntology = manager.createOntology();
        OWLOntologyID testOntologyID = testOntology.getOntologyID();
        log.debug("Created test ontology with ID: {}", testOntologyID);
        AddImport addImport = new AddImport(testOntology, TestData.factory.getOWLImportsDeclaration(IRI.create(testID)));
        manager.applyChange(addImport);
        // We just test class assertions
        List<InferredAxiomGenerator<? extends OWLAxiom>> gens = new ArrayList<InferredAxiomGenerator<? extends OWLAxiom>>();
        gens.add(new InferredClassAssertionAxiomGenerator());
        // Maybe we want to see what is in before
        if (log.isDebugEnabled())
            TestUtils.debug(manager.getOntology(testOntologyID), log);
        // Now we test the method
        log.debug("Running HermiT");
        Set<OWLAxiom> inferred = this.theinstance.run(manager.getOntology(testOntologyID), gens);
        // Maybe we want to see the inferred axiom list
        if (log.isDebugEnabled()) {
            TestUtils.debug(inferred, log);
        }
        // These are the set of expected axioms
        Set<OWLLogicalAxiom> expectedAxioms = manager.getOntology(IRI.create(expectedID)).getLogicalAxioms();
        Set<OWLAxiom> missing = new HashSet<OWLAxiom>();
        for (OWLAxiom expected : expectedAxioms) {
            if (!inferred.contains(expected)) {
                log.error("missing expected axiom: {}", expected);
                missing.add(expected);
            }
        }
        log.info("Are all expected axioms in the result (true)? {}", missing.isEmpty());
        assertTrue(missing.isEmpty());
        // We want to remove the ontology from the manager
        manager.removeOntology(testOntology);
    } catch (OWLOntologyCreationException e) {
        log.error("An {} have been thrown while creating the input ontology for test", e.getClass());
        assertTrue(false);
    } catch (org.apache.stanbol.reasoners.servicesapi.ReasoningServiceException e) {
        log.error("An {} have been thrown while executing the reasoning", e.getClass());
        assertTrue(false);
    } catch (org.apache.stanbol.reasoners.servicesapi.InconsistentInputException e) {
        log.error("An {} have been thrown while executing the reasoning", e.getClass());
        assertTrue(false);
    }
}
Also used : OWLLogicalAxiom(org.semanticweb.owlapi.model.OWLLogicalAxiom) InferredAxiomGenerator(org.semanticweb.owlapi.util.InferredAxiomGenerator) ArrayList(java.util.ArrayList) AddImport(org.semanticweb.owlapi.model.AddImport) ReasoningServiceException(org.apache.stanbol.reasoners.servicesapi.ReasoningServiceException) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) InconsistentInputException(org.apache.stanbol.reasoners.servicesapi.InconsistentInputException) InferredClassAssertionAxiomGenerator(org.semanticweb.owlapi.util.InferredClassAssertionAxiomGenerator) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) OWLAxiom(org.semanticweb.owlapi.model.OWLAxiom) HashSet(java.util.HashSet)

Example 10 with OWLOntologyID

use of org.semanticweb.owlapi.model.OWLOntologyID in project stanbol by apache.

the class TestOWLUtils method lookaheadVersionedDistance100Reversed.

/*
     * Guessing the ID of an ontology whose ontology IRI is declared >100 triples after its version IRI.
     */
@Test
public void lookaheadVersionedDistance100Reversed() throws Exception {
    // Actual distance is 102
    String location = "/owl/versioned_distance-100-reversed.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_distance-100-reversed.owl");
    OWLOntologyID expectedOntId = new OWLOntologyID(ontologyIri, incubatedVersion);
    // No triple limit but offset < 102 : guessing should fail.
    InputStream content = getClass().getResourceAsStream(location);
    OWLOntologyID id = OWLUtils.guessOntologyID(content, parser, TURTLE, -1, 99);
    assertTrue(id.isAnonymous());
    // Try again, setting limit = 1024 (offset = 102) should work.
    content = getClass().getResourceAsStream(location);
    id = OWLUtils.guessOntologyID(content, parser, TURTLE, 1024);
    assertNotNull(id);
    assertFalse(id.isAnonymous());
    assertEquals(expectedOntId, id);
}
Also used : InputStream(java.io.InputStream) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) Test(org.junit.Test)

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