Search in sources :

Example 1 with RegistryOntology

use of org.apache.stanbol.ontologymanager.registry.api.model.RegistryOntology in project stanbol by apache.

the class RegistryManagerImpl method populateOntology.

protected RegistryOntology populateOntology(OWLNamedObject ind, Set<OWLOntology> registries) throws RegistryContentException {
    IRI ontId = ind.getIRI();
    RegistryItem ront = null;
    if (population.containsKey(ontId)) {
        // We are not allowing multityping either.
        ront = population.get(ontId);
        if (!(ront instanceof RegistryOntology))
            throw new RegistryContentException("Inconsistent multityping: for item " + ontId + " : {" + RegistryOntology.class + ", " + ront.getClass() + "}");
    } else {
        ront = riFactory.createRegistryOntology(ind);
        try {
            population.put(ront.getIRI(), ront);
        } catch (Exception e) {
            log.error("Invalid identifier for library item " + ront, e);
            return null;
        }
    }
    // EXIT nodes.
    Set<OWLNamedObject> libs = new HashSet<OWLNamedObject>();
    OWLDataFactory df = OWLManager.getOWLDataFactory();
    for (OWLOntology o : registries) {
        if (ind instanceof OWLIndividual) {
            // Get usages of isOntologyOf as an object property
            for (OWLIndividual value : ((OWLIndividual) ind).getObjectPropertyValues(isOntologyOf, o)) if (value.isNamed())
                libs.add(value.asOWLNamedIndividual());
            // Get usages of isOntologyOf as an annotation property
            for (OWLAnnotationAssertionAxiom ann : o.getAnnotationAssertionAxioms(ind.getIRI())) if (isOntologyOfAnn.equals(ann.getProperty())) {
                OWLAnnotationValue value = ann.getValue();
                if (value instanceof OWLNamedObject)
                    libs.add((OWLNamedObject) value);
                else if (value instanceof IRI)
                    libs.add(df.getOWLNamedIndividual((IRI) value));
            }
        }
    }
    for (OWLNamedObject ilib : libs) {
        IRI parentId = ilib.getIRI();
        // If some populate*() method has created it, it will be there.
        RegistryItem rlib = population.get(parentId);
        // Otherwise populating it will also put it in population.
        if (rlib == null)
            rlib = populateLibrary(ilib, registries);
        ront.addParent(rlib);
        if (ontologyIndex.get(ontId) == null)
            ontologyIndex.put(ontId, new HashSet<IRI>());
        ontologyIndex.get(ontId).add(parentId);
    }
    return (RegistryOntology) ront;
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) OWLAnnotationAssertionAxiom(org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom) RegistryOntology(org.apache.stanbol.ontologymanager.registry.api.model.RegistryOntology) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLOntologyAlreadyExistsException(org.semanticweb.owlapi.model.OWLOntologyAlreadyExistsException) RegistryContentException(org.apache.stanbol.ontologymanager.registry.api.RegistryContentException) OWLNamedObject(org.semanticweb.owlapi.model.OWLNamedObject) OWLAnnotationValue(org.semanticweb.owlapi.model.OWLAnnotationValue) RegistryContentException(org.apache.stanbol.ontologymanager.registry.api.RegistryContentException) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory) RegistryItem(org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem) HashSet(java.util.HashSet) OWLIndividual(org.semanticweb.owlapi.model.OWLIndividual)

Example 2 with RegistryOntology

use of org.apache.stanbol.ontologymanager.registry.api.model.RegistryOntology in project stanbol by apache.

the class TestOntologyRegistry method testRegistryUnion.

/**
 * Verifies that, when loading multiple registries that add library information to each other, the overall
 * model reflects the union of these registries.
 *
 * @throws Exception
 */
@Test
public void testRegistryUnion() throws Exception {
    // Create the model from two overlapping registries.
    Set<OWLOntology> regs = new HashSet<OWLOntology>();
    regs.add(virginOntologyManager.loadOntology(Locations._REGISTRY_TEST));
    regs.add(virginOntologyManager.loadOntology(Locations._REGISTRY_TEST_ADDITIONS));
    Set<Registry> rs = regman.createModel(regs);
    for (Registry r : rs) {
        // The nonexistent library should also be included, if using the more powerful algorithm.
        // set to 2 if using the less powerful algorithm.
        int count = 3;
        if (Locations._REGISTRY_TEST.equals(r.getIRI()))
            assertEquals(count, r.getChildren().length);
        else if (Locations._REGISTRY_TEST_ADDITIONS.equals(r.getIRI()))
            assertEquals(1, r.getChildren().length);
        // Check that we find the expected ontology in the expected library.
        for (RegistryItem lib : r.getChildren()) {
            if (Locations.LIBRARY_TEST1.equals(lib.getIRI())) {
                boolean found = false;
                for (RegistryItem child : lib.getChildren()) {
                    if (child instanceof RegistryOntology && Locations.ONT_TEST1.equals(child.getIRI())) {
                        found = true;
                        break;
                    }
                }
                assertTrue(found);
                break;
            }
        }
    }
}
Also used : RegistryOntology(org.apache.stanbol.ontologymanager.registry.api.model.RegistryOntology) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) Registry(org.apache.stanbol.ontologymanager.registry.api.model.Registry) RegistryItem(org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with RegistryOntology

use of org.apache.stanbol.ontologymanager.registry.api.model.RegistryOntology in project stanbol by apache.

the class TestOntologyRegistry method testLoopInLibrary.

@Test
public void testLoopInLibrary() throws Exception {
    // Create the model from the looping registry.
    OWLOntology oReg = virginOntologyManager.loadOntology(Locations._REGISTRY_TEST_LOOP);
    Set<Registry> rs = regman.createModel(Collections.singleton(oReg));
    // There has to be a single registry, with the expected number of children (one).
    assertEquals(1, rs.size());
    Registry r = rs.iterator().next();
    assertTrue(r.hasChildren());
    int count = 1;
    assertEquals(count, r.getChildren().length);
    // There are no libreries without ontologies in the test registry.
    for (RegistryItem child : r.getChildren()) {
        assertTrue(child instanceof Library);
        // Check both parent-child relations.
        assertTrue(child.hasChildren());
        for (RegistryItem grandchild : child.getChildren()) {
            assertTrue(grandchild instanceof RegistryOntology);
            assertTrue(grandchild.hasParents());
            assertTrue(Arrays.asList(grandchild.getParents()).contains(child));
        }
    }
}
Also used : RegistryOntology(org.apache.stanbol.ontologymanager.registry.api.model.RegistryOntology) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) Registry(org.apache.stanbol.ontologymanager.registry.api.model.Registry) Library(org.apache.stanbol.ontologymanager.registry.api.model.Library) RegistryItem(org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem) Test(org.junit.Test)

Example 4 with RegistryOntology

use of org.apache.stanbol.ontologymanager.registry.api.model.RegistryOntology in project stanbol by apache.

the class LibraryImpl method getOntology.

@Override
public <O> O getOntology(IRI id, Class<O> returnType) throws RegistryContentException {
    /*
         * Note that this implementation is not synchronized. Listeners may indefinitely be notified before or
         * after the rest of this method is executed. If listeners call loadOntologies(), they could still get
         * a RegistryContentException, which however they can catch by calling loadOntologies() and
         * getOntologies() in sequence.
         */
    fireContentRequested(this);
    // If no listener has saved the day by loading the ontologies by now, an exception will be thrown.
    if (!loaded)
        throw new LibraryContentNotLoadedException(this);
    O ontology = null;
    RegistryItem child = getChild(id);
    if (child instanceof RegistryOntology) {
        ontology = getCache().getStoredOntology(child.getIRI(), returnType);
    }
    return ontology;
}
Also used : RegistryOntology(org.apache.stanbol.ontologymanager.registry.api.model.RegistryOntology) LibraryContentNotLoadedException(org.apache.stanbol.ontologymanager.registry.api.LibraryContentNotLoadedException) RegistryItem(org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem)

Example 5 with RegistryOntology

use of org.apache.stanbol.ontologymanager.registry.api.model.RegistryOntology 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)

Aggregations

RegistryItem (org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem)7 RegistryOntology (org.apache.stanbol.ontologymanager.registry.api.model.RegistryOntology)7 HashSet (java.util.HashSet)3 Registry (org.apache.stanbol.ontologymanager.registry.api.model.Registry)3 IRI (org.semanticweb.owlapi.model.IRI)3 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)3 LibraryContentNotLoadedException (org.apache.stanbol.ontologymanager.registry.api.LibraryContentNotLoadedException)2 Library (org.apache.stanbol.ontologymanager.registry.api.model.Library)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 RegistryContentException (org.apache.stanbol.ontologymanager.registry.api.RegistryContentException)1 RegistryOntologyNotLoadedException (org.apache.stanbol.ontologymanager.registry.api.RegistryOntologyNotLoadedException)1 OWLAnnotationAssertionAxiom (org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom)1 OWLAnnotationValue (org.semanticweb.owlapi.model.OWLAnnotationValue)1 OWLDataFactory (org.semanticweb.owlapi.model.OWLDataFactory)1 OWLIndividual (org.semanticweb.owlapi.model.OWLIndividual)1 OWLNamedObject (org.semanticweb.owlapi.model.OWLNamedObject)1 OWLOntologyAlreadyExistsException (org.semanticweb.owlapi.model.OWLOntologyAlreadyExistsException)1 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)1 OWLOntologyID (org.semanticweb.owlapi.model.OWLOntologyID)1