default Optional<OWLHelper> getHelper(final OWLOntologyID ontologyID) { Optional<OWLOntology> ontology = getVolatileOntology(ontologyID); if (ontology.isPresent()) return Optional.of(new OWLGenericTools(this, getVolatileManager(), ontology.get())); ontology = getPersistentOntology(ontologyID); if (ontology.isPresent()) return Optional.of(new OWLGenericTools(this, getPersistentManager(), ontology.get())); return Optional.empty(); }
/** * Seek the asked ontology. First in the volatile ontologies, then in the stored ontologies that are already stored. * * @param ontologyID the id of the ontology you are looking for. * @param isVolatile * @return an ontology if found. * @since 2.6.0 */ default Optional<OWLHelper> getOntology(final OWLOntologyID ontologyID, final boolean isVolatile) { try { return Optional.of(new OWLGenericTools(this, ontologyID, isVolatile)); } catch (final Exception e) { getLogger().log(Level.WARNING, "Can't load " + ontologyID + " in volatile=" + isVolatile + " mode", e); return Optional.empty(); } }
default Optional<OWLHelper> getHelper(final OWLOntologyID ontologyID) { Optional<OWLOntology> ontology = getVolatileOntology(ontologyID); if (ontology.isPresent()) return Optional.of(new OWLGenericTools(this, getVolatileManager(), ontology.get())); ontology = getPersistentOntology(ontologyID); if (ontology.isPresent()) return Optional.of(new OWLGenericTools(this, getPersistentManager(), ontology.get())); return Optional.empty(); }
default Optional<OWLHelper> getHelper(final OWLOntologyID ontologyID) { Optional<OWLOntology> ontology = getVolatileOntology(ontologyID); if (ontology.isPresent()) return Optional.of(new OWLGenericTools(this, getVolatileManager(), ontology.get())); ontology = getPersistentOntology(ontologyID); if (ontology.isPresent()) return Optional.of(new OWLGenericTools(this, getPersistentManager(), ontology.get())); return Optional.empty(); }
default Stream<OWLHelper> getPersistentsHelper() { if (!havePersistentManager()) return Stream.empty(); final OWLOntologyManager vm = getPersistentManager(); return vm.ontologies().map(ontology -> new OWLGenericTools(this, vm, ontology)); }
default Stream<OWLHelper> getVolatilesHelper() { if (!haveVolatileManager()) return Stream.empty(); final OWLOntologyManager vm = getVolatileManager(); return vm.ontologies().map(ontology -> new OWLGenericTools(this, vm, ontology)); }
default Stream<OWLHelper> getPersistentsHelper() { if (!havePersistentManager()) return Stream.empty(); final OWLOntologyManager vm = getPersistentManager(); return vm.ontologies().map(ontology -> new OWLGenericTools(this, vm, ontology)); }
default Stream<OWLHelper> getVolatilesHelper() { if (!haveVolatileManager()) return Stream.empty(); final OWLOntologyManager vm = getVolatileManager(); return vm.ontologies().map(ontology -> new OWLGenericTools(this, vm, ontology)); }
default Stream<OWLHelper> getVolatilesHelper() { if (!haveVolatileManager()) return Stream.empty(); final OWLOntologyManager vm = getVolatileManager(); return vm.ontologies().map(ontology -> new OWLGenericTools(this, vm, ontology)); }
default Stream<OWLHelper> getPersistentsHelper() { if (!havePersistentManager()) return Stream.empty(); final OWLOntologyManager vm = getPersistentManager(); return vm.ontologies().map(ontology -> new OWLGenericTools(this, vm, ontology)); }
@Override public void run() { while (!_allAxioms.isEmpty()) try (final OWLManagerGroup group = new OWLManagerGroup()) { test(new OWLGenericTools(group, OWLHelper.getVersion(IRI.create(NS), _tryCount), true)); } catch (final Exception e) { e.printStackTrace(); } } }
@Test public void testSubProperties() throws OWLOntologyCreationException { try (final OWLManagerGroup group = new OWLManagerGroup()) { final OWLOntologyID ontId = OWLHelper.getVersion(IRI.create(NS + "owlapi.inc.properties"), 1.0); final OWLHelper owl = new OWLGenericTools(group, ontId, true); owl.addAxiom(OWL.subPropertyOf(o.apply("P2"), o.apply("P1"))); // p2 extends p1 owl.addAxiom(OWL.propertyAssertion(i.apply("I1"), o.apply("P1"), i.apply("I2"))); owl.addAxiom(OWL.propertyAssertion(i.apply("I3"), o.apply("P2"), i.apply("I4"))); assertFalse(owl.getObject(i.apply("I1"), o.apply("P2")).isPresent()); assertTrue(owl.getObject(i.apply("I3"), o.apply("P1")).get().equals(i.apply("I4"))); } }
@Test public void testSubProperties() throws OWLOntologyCreationException { try (final OWLManagerGroup group = new OWLManagerGroup()) { final OWLOntologyID ontId = OWLHelper.getVersion(IRI.create(NS + "owlapi.inc.properties"), 1.0); final OWLHelper owl = new OWLGenericTools(group, ontId, true); owl.addAxiom(OWL.subPropertyOf(o.apply("P2"), o.apply("P1"))); // p2 extends p1 owl.addAxiom(OWL.propertyAssertion(i.apply("I1"), o.apply("P1"), i.apply("I2"))); owl.addAxiom(OWL.propertyAssertion(i.apply("I3"), o.apply("P2"), i.apply("I4"))); assertFalse(owl.getObject(i.apply("I1"), o.apply("P2")).isPresent()); assertTrue(owl.getObject(i.apply("I3"), o.apply("P1")).get().equals(i.apply("I4"))); } }
@Test public void testOnlyProperties() throws OWLOntologyCreationException { try (final OWLManagerGroup group = new OWLManagerGroup()) { final OWLOntologyID ontId = OWLHelper.getVersion(IRI.create(NS + "owlapi.only.properties"), 1.0); final OWLHelper owl = new OWLGenericTools(group, ontId, true); // final OWLNamedIndividual x1 = i.apply("I1"); // final OWLNamedIndividual x2 = i.apply("I2"); //owl.addAxiom(OWL.propertyAssertion(x1, propA, x2)); owl.addAxiom(OWL.inverseProperties(o.apply("A"), o.apply("B"))); //owl.addAxiom(OWL.declaration(ClsA)); owl.getReasoner().getObjectPropertyDomains(o.apply("A")); } // The test is just about not crash. }
@Test public void testRestrictionConjonction3() throws OWLOntologyCreationException { try (final OWLManagerGroup group = new OWLManagerGroup()) { final OWLOntology ontology = group.getVolatileManager().loadOntologyFromOntologyDocument(new File("src/test/resources/test_data/restriction_conjonction.owl")); final OWLHelper owl = new OWLGenericTools(group, ontology, true); final OWLReasoner r = owl.getReasoner(); assertTrue(r.isConsistent()); ontology.individualsInSignature().forEach(r::getTypes); ontology.classesInSignature().forEach(r::getInstances); } }
@Test public void testOnlyProperties() throws OWLOntologyCreationException { try (final OWLManagerGroup group = new OWLManagerGroup()) { final OWLOntologyID ontId = OWLHelper.getVersion(IRI.create(NS + "owlapi.only.properties"), 1.0); final OWLHelper owl = new OWLGenericTools(group, ontId, true); // final OWLNamedIndividual x1 = i.apply("I1"); // final OWLNamedIndividual x2 = i.apply("I2"); //owl.addAxiom(OWL.propertyAssertion(x1, propA, x2)); owl.addAxiom(OWL.inverseProperties(o.apply("A"), o.apply("B"))); //owl.addAxiom(OWL.declaration(ClsA)); owl.getReasoner().getObjectPropertyDomains(o.apply("A")); } // The test is just about not crash. }
@Test public void testRestrictionConjonction3() throws OWLOntologyCreationException { try (final OWLManagerGroup group = new OWLManagerGroup()) { final OWLOntology ontology = group.getVolatileManager().loadOntologyFromOntologyDocument(new File("src/test/resources/test_data/restriction_conjonction.owl")); final OWLHelper owl = new OWLGenericTools(group, ontology, true); final OWLReasoner r = owl.getReasoner(); assertTrue(r.isConsistent()); ontology.individualsInSignature().forEach(r::getTypes); ontology.classesInSignature().forEach(r::getInstances); } }
@Test public void testRestriction() throws OWLOntologyCreationException { try (final OWLManagerGroup group = new OWLManagerGroup()) { final OWLOntologyID ontId = OWLHelper.getVersion(IRI.create(NS + "owlapi.inc.integer-float.restriction"), 1.0); final OWLHelper owl = new OWLGenericTools(group, ontId, true); final OWLNamedIndividual x1 = i.apply("I1"); final OWLNamedIndividual x2 = i.apply("I2"); owl.addAxiom(OWL.equivalentClasses(ClsA, OWL.some(propB, XSD.INTEGER))); owl.addAxiom(OWL.propertyAssertion(x1, propB, OWL.constant(1))); owl.addAxiom(OWL.propertyAssertion(x2, propB, OWL.constant(1.))); final OWLReasoner r = owl.getReasoner(); assertTrue(r.isEntailed(OWL.classAssertion(x1, ClsA))); assertFalse(r.isEntailed(OWL.classAssertion(x2, ClsA))); } }
@Test public void testRestriction() throws OWLOntologyCreationException { try (final OWLManagerGroup group = new OWLManagerGroup()) { final OWLOntologyID ontId = OWLHelper.getVersion(IRI.create(NS + "owlapi.inc.integer-float.restriction"), 1.0); final OWLHelper owl = new OWLGenericTools(group, ontId, true); final OWLNamedIndividual x1 = i.apply("I1"); final OWLNamedIndividual x2 = i.apply("I2"); owl.addAxiom(OWL.equivalentClasses(ClsA, OWL.some(propB, XSD.INTEGER))); owl.addAxiom(OWL.propertyAssertion(x1, propB, OWL.constant(1))); owl.addAxiom(OWL.propertyAssertion(x2, propB, OWL.constant(1.))); final OWLReasoner r = owl.getReasoner(); assertTrue(r.isEntailed(OWL.classAssertion(x1, ClsA))); assertFalse(r.isEntailed(OWL.classAssertion(x2, ClsA))); } }
@Test public void testRegexRestriction() throws OWLOntologyCreationException { try (final OWLManagerGroup group = new OWLManagerGroup()) { final OWLOntologyID ontId = OWLHelper.getVersion(IRI.create(NS + "owlapi.inc.regex.restriction"), 1.0); final OWLHelper owl = new OWLGenericTools(group, ontId, true); final OWLNamedIndividual x1 = i.apply("I1"); final OWLNamedIndividual x2 = i.apply("I2"); owl.addAxiom(OWL.equivalentClasses(ClsA, OWL.some(propB, OWL.restrict(XSD.STRING, OWL.facetRestriction(OWLFacet.PATTERN, OWL.constant("A.A")))))); owl.addAxiom(OWL.propertyAssertion(x1, propB, OWL.constant("AAA"))); owl.addAxiom(OWL.propertyAssertion(x2, propB, OWL.constant("BBB"))); owl.addAxiom(OWL.differentFrom(x1, x2)); final OWLReasoner r = owl.getReasoner(); assertTrue(r.isEntailed(OWL.classAssertion(x1, ClsA))); assertFalse(r.isEntailed(OWL.classAssertion(x2, ClsA))); } }