Search in sources :

Example 6 with RegistryItem

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

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

the class RegistryManagerImpl method getLibraries.

@Override
public Set<Library> getLibraries(IRI ontologyID) {
    Set<Library> results = new HashSet<Library>();
    RegistryItem ri = population.get(ontologyID);
    if (ri != null)
        for (RegistryItem item : ri.getParents()) if (item instanceof Library)
            results.add((Library) item);
    return results;
}
Also used : Library(org.apache.stanbol.ontologymanager.registry.api.model.Library) RegistryItem(org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem) HashSet(java.util.HashSet)

Example 8 with RegistryItem

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

the class TestOntologyLibrary method testLibraryLoad.

/**
 * Uses a plain {@link RegistryManager} to load a single ontology library and checks for its expected hits
 * and misses.
 *
 * @throws Exception
 *             if any error occurs;
 */
@Test
public void testLibraryLoad() throws Exception {
    IRI localTestRegistry = IRI.create(getClass().getResource(registryResourcePath));
    Dictionary<String, Object> regmanConf = new Hashtable<String, Object>();
    regmanConf.put(RegistryManager.REGISTRY_LOCATIONS, new String[] { localTestRegistry.toString() });
    // Instantiating the registry manager will also load the registry data.
    regMgr = new RegistryManagerImpl(offline, new ClerezzaOntologyProvider(tcManager, offline, parser), regmanConf);
    // The resulting manager must exist and have exactly one registry.
    assertNotNull(regMgr);
    Set<Registry> registries = regMgr.getRegistries();
    assertFalse(registries.isEmpty());
    assertEquals(1, registries.size());
    Registry reg = registries.iterator().next();
    assertTrue(reg.hasChildren());
    Library lib = null;
    // Look for test #Library2
    for (RegistryItem item : reg.getChildren()) {
        if (Locations.LIBRARY_TEST2.equals(item.getIRI())) {
            lib = (Library) item;
            break;
        }
    }
    assertNotNull(lib);
    // Should be in the library.
    boolean hasShould = RegistryUtils.containsOntologyRecursive(lib, Locations.CHAR_DROPPED);
    // Should NOT be in the library (belongs to another library in the same registry).
    boolean hasShouldNot = RegistryUtils.containsOntologyRecursive(lib, Locations.CHAR_ACTIVE);
    assertTrue(hasShould);
    assertFalse(hasShouldNot);
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) Hashtable(java.util.Hashtable) 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) ClerezzaOntologyProvider(org.apache.stanbol.ontologymanager.multiplexer.clerezza.ontology.ClerezzaOntologyProvider) Test(org.junit.Test)

Example 9 with RegistryItem

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

Example 10 with RegistryItem

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

the class TestRegistryManager method testLoadingEager.

/**
 * Verifies that by setting the loading policy to eager (LAZY_LOADING = false), any random library will
 * respond true to a call to {@link Library#isLoaded()} without ever "touching" its content.
 *
 * @throws Exception
 */
@Test
public void testLoadingEager() throws Exception {
    // Change the caching policy and setup a new registry manager.
    configuration.put(RegistryManager.CACHING_POLICY, CachingPolicy.DISTRIBUTED);
    configuration.put(RegistryManager.LAZY_LOADING, false);
    regman = new RegistryManagerImpl(offline, provider, configuration);
    // Check that the configuration was set.
    assertNotNull(regman);
    // Now pick a library.
    Registry reg;
    do reg = regman.getRegistries().iterator().next(); while (!reg.hasChildren());
    assertNotNull(reg);
    // There has to be at least one non-empty library from the test registries...
    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);
    // ...and its ontologies must already be loaded without having to request them.
    assertTrue(lib.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

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