Search in sources :

Example 1 with ParentPathInputSource

use of org.apache.stanbol.ontologymanager.sources.owlapi.ParentPathInputSource in project stanbol by apache.

the class TestClerezzaSpaces method setup.

@BeforeClass
public static void setup() throws Exception {
    offline = new OfflineConfigurationImpl(new Hashtable<String, Object>());
    ScopeRegistry reg = new ScopeRegistryImpl();
    // This one is created from scratch
    Graph ont2 = ClerezzaOWLUtils.createOntology(baseIri2.toString());
    minorSrc = new GraphSource(ont2.getImmutableGraph());
    dropSrc = getLocalSource("/ontologies/droppedcharacters.owl");
    nonexSrc = getLocalSource("/ontologies/nonexistentcharacters.owl");
    inMemorySrc = new ParentPathInputSource(new File(TestClerezzaSpaces.class.getResource("/ontologies/maincharacters.owl").toURI()));
    OWLDataFactory df = OWLManager.getOWLDataFactory();
    OWLClass cHuman = df.getOWLClass(IRI.create(baseIri + "/" + Constants.humanBeing));
    OWLIndividual iLinus = df.getOWLNamedIndividual(IRI.create(baseIri + "/" + Constants.linus));
    linusIsHuman = df.getOWLClassAssertionAxiom(cHuman, iLinus);
    factory = new ClerezzaCollectorFactory(new ClerezzaOntologyProvider(tcManager, offline, parser), new Hashtable<String, Object>());
    factory.setDefaultNamespace(IRI.create("http://stanbol.apache.org/ontology/"));
}
Also used : Hashtable(java.util.Hashtable) OfflineConfigurationImpl(org.apache.stanbol.ontologymanager.core.OfflineConfigurationImpl) ClerezzaOntologyProvider(org.apache.stanbol.ontologymanager.multiplexer.clerezza.ontology.ClerezzaOntologyProvider) Graph(org.apache.clerezza.commons.rdf.Graph) ScopeRegistryImpl(org.apache.stanbol.ontologymanager.core.scope.ScopeRegistryImpl) GraphSource(org.apache.stanbol.ontologymanager.sources.clerezza.GraphSource) ParentPathInputSource(org.apache.stanbol.ontologymanager.sources.owlapi.ParentPathInputSource) OWLClass(org.semanticweb.owlapi.model.OWLClass) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory) File(java.io.File) ScopeRegistry(org.apache.stanbol.ontologymanager.servicesapi.scope.ScopeRegistry) OWLIndividual(org.semanticweb.owlapi.model.OWLIndividual) ClerezzaCollectorFactory(org.apache.stanbol.ontologymanager.multiplexer.clerezza.collector.ClerezzaCollectorFactory) BeforeClass(org.junit.BeforeClass)

Example 2 with ParentPathInputSource

use of org.apache.stanbol.ontologymanager.sources.owlapi.ParentPathInputSource in project stanbol by apache.

the class TestStorage method storageOnScopeCreation.

@Test
public void storageOnScopeCreation() throws Exception {
    assertEquals(1, ontologyProvider.getStore().listGraphs().size());
    // This one has an import that we want to hijack locally, so we use the ParentPathInputSource.
    OntologyInputSource<?> ois = new ParentPathInputSource(new File(getClass().getResource("/ontologies/minorcharacters.owl").toURI()));
    Scope sc = onManager.createOntologyScope(scopeId, ois);
    Set<Triple> triples = new HashSet<Triple>();
    for (IRI iri : ontologyProvider.getStore().listGraphs()) {
        log.info("{}", iri.toString());
        IRI entity = new IRI(Constants.PEANUTS_MINOR_BASE + "#" + Constants.truffles);
        ImmutableGraph ctx = new GraphNode(entity, ontologyProvider.getStore().getGraph(iri)).getNodeContext();
        Iterator<Triple> it = ctx.iterator();
        while (it.hasNext()) triples.add(it.next());
    }
    assertFalse(ontologyProvider.getStore().listGraphs().isEmpty());
    assertEquals(3, triples.size());
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) IRI(org.apache.clerezza.commons.rdf.IRI) Scope(org.apache.stanbol.ontologymanager.servicesapi.scope.Scope) ParentPathInputSource(org.apache.stanbol.ontologymanager.sources.owlapi.ParentPathInputSource) GraphNode(org.apache.clerezza.rdf.utils.GraphNode) File(java.io.File) ImmutableGraph(org.apache.clerezza.commons.rdf.ImmutableGraph) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with ParentPathInputSource

use of org.apache.stanbol.ontologymanager.sources.owlapi.ParentPathInputSource in project stanbol by apache.

the class TestOntologyCollectors method spacePreservesImports.

@Test
public void spacePreservesImports() throws Exception {
    InputStream content = getClass().getResourceAsStream("/ontologies/characters_all.owl");
    URL url = getClass().getResource("/ontologies/characters_all.owl");
    OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
    mgr.addOntologyLoaderListener(new OWLOntologyLoaderListener() {

        @Override
        public void startedLoadingOntology(LoadingStartedEvent arg0) {
        }

        @Override
        public void finishedLoadingOntology(LoadingFinishedEvent arg0) {
            log.info((arg0.isSuccessful() ? "Loaded" : "Failed") + (arg0.isImported() ? " imported " : " ") + "ontology " + arg0.getDocumentIRI());
        }
    });
    mgr.addIRIMapper(new PhonyIRIMapper(null));
    File f = new File(url.toURI());
    OntologyInputSource<OWLOntology> src = new ParentPathInputSource(f, mgr);
    // OntologyInputSource<OWLOntology> src = new RootOntologyIRISource(IRI.create(f), mgr);
    // OntologyInputSource<OWLOntology> src = new OntologyContentInputSource(content,mgr);
    OWLOntology original = src.getRootOntology();
    Assert.assertNotNull(original);
    OntologySpace spc = new CustomSpaceImpl("Test", scopeNs, ontologyProvider);
    spc.addOntology(src);
}
Also used : InputStream(java.io.InputStream) URL(java.net.URL) CustomSpaceImpl(org.apache.stanbol.ontologymanager.multiplexer.clerezza.impl.CustomSpaceImpl) OWLOntologyLoaderListener(org.semanticweb.owlapi.model.OWLOntologyLoaderListener) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OntologySpace(org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace) PhonyIRIMapper(org.apache.stanbol.commons.owl.PhonyIRIMapper) ParentPathInputSource(org.apache.stanbol.ontologymanager.sources.owlapi.ParentPathInputSource) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) File(java.io.File) Test(org.junit.Test)

Example 4 with ParentPathInputSource

use of org.apache.stanbol.ontologymanager.sources.owlapi.ParentPathInputSource in project stanbol by apache.

the class TestOntologySpaces method getLocalSource.

private static OntologyInputSource<OWLOntology> getLocalSource(String resourcePath, OWLOntologyManager mgr) throws OWLOntologyCreationException, URISyntaxException {
    URL url = TestOntologySpaces.class.getResource(resourcePath);
    File f = new File(url.toURI());
    return new ParentPathInputSource(f, mgr != null ? mgr : OWLOntologyManagerFactory.createOWLOntologyManager(onManager.getOfflineConfiguration().getOntologySourceLocations().toArray(new IRI[0])));
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) ParentPathInputSource(org.apache.stanbol.ontologymanager.sources.owlapi.ParentPathInputSource) File(java.io.File) URL(java.net.URL)

Aggregations

File (java.io.File)4 ParentPathInputSource (org.apache.stanbol.ontologymanager.sources.owlapi.ParentPathInputSource)4 URL (java.net.URL)2 Test (org.junit.Test)2 InputStream (java.io.InputStream)1 HashSet (java.util.HashSet)1 Hashtable (java.util.Hashtable)1 Graph (org.apache.clerezza.commons.rdf.Graph)1 IRI (org.apache.clerezza.commons.rdf.IRI)1 ImmutableGraph (org.apache.clerezza.commons.rdf.ImmutableGraph)1 Triple (org.apache.clerezza.commons.rdf.Triple)1 GraphNode (org.apache.clerezza.rdf.utils.GraphNode)1 PhonyIRIMapper (org.apache.stanbol.commons.owl.PhonyIRIMapper)1 OfflineConfigurationImpl (org.apache.stanbol.ontologymanager.core.OfflineConfigurationImpl)1 ScopeRegistryImpl (org.apache.stanbol.ontologymanager.core.scope.ScopeRegistryImpl)1 ClerezzaCollectorFactory (org.apache.stanbol.ontologymanager.multiplexer.clerezza.collector.ClerezzaCollectorFactory)1 CustomSpaceImpl (org.apache.stanbol.ontologymanager.multiplexer.clerezza.impl.CustomSpaceImpl)1 ClerezzaOntologyProvider (org.apache.stanbol.ontologymanager.multiplexer.clerezza.ontology.ClerezzaOntologyProvider)1 OntologySpace (org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace)1 Scope (org.apache.stanbol.ontologymanager.servicesapi.scope.Scope)1