Search in sources :

Example 1 with RegistryItem

use of org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem 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 2 with RegistryItem

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

the class TestOntologyRegistry method testPopulateRegistry.

/**
 * Verifies that a call to {@link RegistryManager#createModel(Set)} with a registry location creates the
 * object model accordingly.
 *
 * @throws Exception
 */
@Test
public void testPopulateRegistry() throws Exception {
    // Create the model from a single registry.
    OWLOntology oReg = virginOntologyManager.loadOntology(Locations._REGISTRY_TEST);
    Set<Registry> rs = regman.createModel(Collections.singleton(oReg));
    // There has to be a single registry, with the expected number of children.
    assertEquals(1, rs.size());
    Registry r = rs.iterator().next();
    assertTrue(r.hasChildren());
    // 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;
    assertEquals(count, r.getChildren().length);
    // There are no libraries without ontologies in the test registry.
    for (RegistryItem ri : r.getChildren()) assertTrue(ri.hasChildren());
}
Also used : OWLOntology(org.semanticweb.owlapi.model.OWLOntology) Registry(org.apache.stanbol.ontologymanager.registry.api.model.Registry) RegistryItem(org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem) Test(org.junit.Test)

Example 3 with RegistryItem

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

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

use of org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem 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)18 Registry (org.apache.stanbol.ontologymanager.registry.api.model.Registry)12 Library (org.apache.stanbol.ontologymanager.registry.api.model.Library)10 IRI (org.semanticweb.owlapi.model.IRI)8 RegistryOntology (org.apache.stanbol.ontologymanager.registry.api.model.RegistryOntology)7 Test (org.junit.Test)7 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)7 HashSet (java.util.HashSet)6 RegistryContentException (org.apache.stanbol.ontologymanager.registry.api.RegistryContentException)4 RegistryManagerImpl (org.apache.stanbol.ontologymanager.registry.impl.RegistryManagerImpl)4 OWLOntologyAlreadyExistsException (org.semanticweb.owlapi.model.OWLOntologyAlreadyExistsException)4 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)4 OWLIndividual (org.semanticweb.owlapi.model.OWLIndividual)3 OWLNamedObject (org.semanticweb.owlapi.model.OWLNamedObject)3 HashMap (java.util.HashMap)2 ClerezzaOntologyProvider (org.apache.stanbol.ontologymanager.multiplexer.clerezza.ontology.ClerezzaOntologyProvider)2 LibraryContentNotLoadedException (org.apache.stanbol.ontologymanager.registry.api.LibraryContentNotLoadedException)2 OWLAnnotationAssertionAxiom (org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom)2 OWLAnnotationValue (org.semanticweb.owlapi.model.OWLAnnotationValue)2 OWLDataFactory (org.semanticweb.owlapi.model.OWLDataFactory)2