Search in sources :

Example 6 with RegistryManagerImpl

use of org.apache.stanbol.ontologymanager.registry.impl.RegistryManagerImpl 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 7 with RegistryManagerImpl

use of org.apache.stanbol.ontologymanager.registry.impl.RegistryManagerImpl in project stanbol by apache.

the class TestOntologyLibrary method testLibrarySourceCreation.

/**
     * Tests the creation of an ontology input source from a single library. Because the test is run offline,
     * import statements might be file URIs, so tests should not fail on this.
     * 
     * @throws Exception
     */
@Test
public void testLibrarySourceCreation() 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);
    assertNotNull(regMgr);
    // Now use this registry manager to instantiate an input source.
    OntologyInputSource<OWLOntology> src = new LibrarySource(Locations.LIBRARY_TEST1, regMgr, virginOntologyManager);
    OWLOntology o = src.getRootOntology();
    boolean hasImporting = false, hasImported = false;
    for (OWLImportsDeclaration ax : o.getImportsDeclarations()) {
        // Since we added a local IRI mapping, import statements might be using file: IRIs instead of
        // HTTP, in which case IRI equality would fail. So it is enough here to just check the filename.
        String tmpstr = ax.getIRI().toString();
        if (!hasImporting && tmpstr.endsWith("characters_all.owl"))
            hasImporting = true;
        else if (!hasImported && tmpstr.endsWith("maincharacters.owl"))
            hasImported = true;
        if (hasImporting && hasImported)
            break;
    }
    assertTrue(hasImporting);
    assertTrue(hasImported);
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) Hashtable(java.util.Hashtable) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) LibrarySource(org.apache.stanbol.ontologymanager.registry.io.LibrarySource) RegistryManagerImpl(org.apache.stanbol.ontologymanager.registry.impl.RegistryManagerImpl) OWLImportsDeclaration(org.semanticweb.owlapi.model.OWLImportsDeclaration) ClerezzaOntologyProvider(org.apache.stanbol.ontologymanager.multiplexer.clerezza.ontology.ClerezzaOntologyProvider) Test(org.junit.Test)

Aggregations

RegistryManagerImpl (org.apache.stanbol.ontologymanager.registry.impl.RegistryManagerImpl)7 Test (org.junit.Test)6 Library (org.apache.stanbol.ontologymanager.registry.api.model.Library)5 Registry (org.apache.stanbol.ontologymanager.registry.api.model.Registry)4 RegistryItem (org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem)4 Hashtable (java.util.Hashtable)3 ClerezzaOntologyProvider (org.apache.stanbol.ontologymanager.multiplexer.clerezza.ontology.ClerezzaOntologyProvider)3 IRI (org.semanticweb.owlapi.model.IRI)2 SimpleTcProvider (org.apache.clerezza.rdf.simple.storage.SimpleTcProvider)1 OfflineConfigurationImpl (org.apache.stanbol.ontologymanager.core.OfflineConfigurationImpl)1 LibrarySource (org.apache.stanbol.ontologymanager.registry.io.LibrarySource)1 OfflineConfiguration (org.apache.stanbol.ontologymanager.servicesapi.OfflineConfiguration)1 BeforeClass (org.junit.BeforeClass)1 OWLImportsDeclaration (org.semanticweb.owlapi.model.OWLImportsDeclaration)1 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)1