Search in sources :

Example 1 with Registry

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

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

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

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

the class TestRegistryManager method testCachingCentralised.

/**
     * Verifies that by instantiating a new {@link RegistryManager} with a centralised caching policy and
     * loading two registries, they share the same cache ontology manager.
     * 
     * @throws Exception
     */
@Test
public void testCachingCentralised() throws Exception {
    // Change the caching policy and setup a new registry manager.
    configuration.put(RegistryManager.CACHING_POLICY, CachingPolicy.CENTRALISED);
    regman = new RegistryManagerImpl(offline, provider, configuration);
    // Check that the configuration was set.
    assertNotNull(regman);
    assertSame(CachingPolicy.CENTRALISED, regman.getCachingPolicy());
    // All registries must have the same cache.
    Iterator<Library> it = regman.getLibraries().iterator();
    OntologyProvider<?> cache = it.next().getCache();
    while (it.hasNext()) assertSame(cache, it.next().getCache());
    // Now "touch" a library.
    Registry reg;
    do reg = regman.getRegistries().iterator().next(); while (!reg.hasChildren());
    assertNotNull(reg);
    // There has to be at least one non-empty lib from the test ontologies.
    Library lib = null;
    RegistryItem[] children = reg.getChildren();
    for (int i = 0; i < children.length && lib == null; i++) if (children[i] instanceof Library)
        lib = (Library) (children[i]);
    assertNotNull(lib);
    // Touch the library. Also test that the listener system works.
    assertFalse(lib.getOntologies(OWLOntology.class).isEmpty());
}
Also used : RegistryManagerImpl(org.apache.stanbol.ontologymanager.registry.impl.RegistryManagerImpl) Library(org.apache.stanbol.ontologymanager.registry.api.model.Library) Registry(org.apache.stanbol.ontologymanager.registry.api.model.Registry) RegistryItem(org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem) Test(org.junit.Test)

Example 5 with Registry

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

the class TestRegistryManager method testLoadingLazy.

/**
     * Verifies that by setting the loading policy to lazy (LAZY_LOADING = true), any random library will
     * respond false to a call to {@link Library#isLoaded()}, until its content is "touched" via a call to
     * {@link Library#getOntologies()}, only after which will it return true.
     * 
     * @throws Exception
     */
@Test
public void testLoadingLazy() throws Exception {
    // Change the caching policy and setup a new registry manager.
    configuration.put(RegistryManager.CACHING_POLICY, CachingPolicy.CENTRALISED);
    configuration.put(RegistryManager.LAZY_LOADING, true);
    regman = new RegistryManagerImpl(offline, provider, configuration);
    // Check that the configuration was set.
    assertNotNull(regman);
    // Now pick a library.
    Registry reg;
    Iterator<Registry> it = regman.getRegistries().iterator();
    do reg = it.next(); while (// We need a registry with at least 2 libraries to check that only one will be loaded.
    it.hasNext() && !reg.hasChildren() || reg.getChildren().length < 2);
    assertNotNull(reg);
    // There has to be at least one library with 2 children or more from the test registries...
    Library lib1 = null, lib2 = null;
    RegistryItem[] children = reg.getChildren();
    assertTrue(children.length >= 2);
    for (int i = 0; i < children.length - 1 && lib1 == null && lib2 == null; i++) {
        if (children[i] instanceof Library)
            lib1 = (Library) (children[i]);
        if (children[i + 1] instanceof Library)
            lib2 = (Library) (children[i + 1]);
    }
    assertFalse(lib1 == lib2);
    assertNotNull(lib1);
    // ...but its ontologies must not be loaded yet.
    assertFalse(lib1.isLoaded());
    assertFalse(lib2.isLoaded());
    // Touch the library. Also test that the listener system works.
    assertFalse(lib1.getOntologies(OWLOntology.class).isEmpty());
    assertTrue(lib1.isLoaded());
    assertFalse(lib2.isLoaded());
}
Also used : RegistryManagerImpl(org.apache.stanbol.ontologymanager.registry.impl.RegistryManagerImpl) 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)

Aggregations

Registry (org.apache.stanbol.ontologymanager.registry.api.model.Registry)13 RegistryItem (org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem)12 Library (org.apache.stanbol.ontologymanager.registry.api.model.Library)8 Test (org.junit.Test)7 IRI (org.semanticweb.owlapi.model.IRI)6 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)6 RegistryManagerImpl (org.apache.stanbol.ontologymanager.registry.impl.RegistryManagerImpl)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 RegistryContentException (org.apache.stanbol.ontologymanager.registry.api.RegistryContentException)3 RegistryOntology (org.apache.stanbol.ontologymanager.registry.api.model.RegistryOntology)3 ClerezzaOntologyProvider (org.apache.stanbol.ontologymanager.multiplexer.clerezza.ontology.ClerezzaOntologyProvider)2 OWLIndividual (org.semanticweb.owlapi.model.OWLIndividual)2 OWLObject (org.semanticweb.owlapi.model.OWLObject)2 OWLOntologyAlreadyExistsException (org.semanticweb.owlapi.model.OWLOntologyAlreadyExistsException)2 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)2 Hashtable (java.util.Hashtable)1 Type (org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem.Type)1 IRIDocumentSource (org.semanticweb.owlapi.io.IRIDocumentSource)1 OWLOntologyDocumentSource (org.semanticweb.owlapi.io.OWLOntologyDocumentSource)1