/** * Seek the asked ontology. First in the volatile ontologies, then in the stored ontologies that are already stored. * * @param ontology the iri of the ontology you are looking for. * @param version of the ontology * @param isVolatile * @return an ontology if found. * @since 2.6.0 */ default Optional<OWLHelper> getOntology(final IRI ontology, final double version, final boolean isVolatile) { return getOntology(OWLHelper.getVersion(ontology, version), isVolatile); }
/** * Seek the asked ontology. First in the volatile ontologies, then in the stored ontologies that are already stored. * * @param ontology the iri of the ontology you are looking for. * @param version of the ontology * @param isVolatile * @return an ontology if found. * @since 2.6.0 */ default Optional<OWLHelper> getOntology(final IRI ontology, final double version, final boolean isVolatile) { return getOntology(OWLHelper.getVersion(ontology, version), isVolatile); }
/** * Seek the asked ontology. First in the volatile ontologies, then in the stored ontologies that are already stored. * * @param ontology the iri of the ontology you are looking for. * @param version of the ontology * @param isVolatile * @return an ontology if found. * @since 2.6.0 */ default Optional<OWLHelper> getOntology(final IRI ontology, final double version, final boolean isVolatile) { return getOntology(OWLHelper.getVersion(ontology, version), isVolatile); }
@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(); } } }
/** * Clone into another ontology with the same axioms and same manager. NB : In a future version this function may return an ontology that share axiom with * previous for memory saving. * * @param version that will have the new ontology. * @return a new ontology with the axioms of the given one. * @throws OWLOntologyCreationException if we can't create the ontology. * @since 2.5.1 */ default public OWLHelper derivate(final double version) throws OWLOntologyCreationException { final Optional<OWLHelper> result = look(this.getOntology().getOntologyID().getOntologyIRI().get(), version); if (!result.isPresent()) throw new OWLOntologyCreationException("Can't derivate to version " + version); if (result.get().getOntology().getAxiomCount() != 0) getLogger().warning(() -> "The ontology you try to derivate from " + getVersion() + " to version " + version + " already exist."); result.get().addAxioms(getOntology().axioms()); return result.get(); }
/** * Clone into another ontology with the same axioms and same manager. NB : In a future version this function may return an ontology that share axiom with * previous for memory saving. * * @param version that will have the new ontology. * @return a new ontology with the axioms of the given one. * @throws OWLOntologyCreationException if we can't create the ontology. * @since 2.5.1 */ default public OWLHelper derivate(final double version) throws OWLOntologyCreationException { final Optional<OWLHelper> result = look(this.getOntology().getOntologyID().getOntologyIRI().get(), version); if (!result.isPresent()) throw new OWLOntologyCreationException("Can't derivate to version " + version); if (result.get().getOntology().getAxiomCount() != 0) getLogger().warning(() -> "The ontology you try to derivate from " + getVersion() + " to version " + version + " already exist."); result.get().addAxioms(getOntology().axioms()); return result.get(); }
/** * Clone into another ontology with the same axioms and same manager. NB : In a future version this function may return an ontology that share axiom with * previous for memory saving. * * @param version that will have the new ontology. * @return a new ontology with the axioms of the given one. * @throws OWLOntologyCreationException if we can't create the ontology. * @since 2.5.1 */ default public OWLHelper derivate(final double version) throws OWLOntologyCreationException { final Optional<OWLHelper> result = look(this.getOntology().getOntologyID().getOntologyIRI().get(), version); if (!result.isPresent()) throw new OWLOntologyCreationException("Can't derivate to version " + version); if (result.get().getOntology().getAxiomCount() != 0) getLogger().warning(() -> "The ontology you try to derivate from " + getVersion() + " to version " + version + " already exist."); result.get().addAxioms(getOntology().axioms()); return result.get(); }
@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 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 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))); } }
@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))); } }
@Test public void testMaxLengthRestriction() throws OWLOntologyCreationException { try (final OWLManagerGroup group = new OWLManagerGroup()) { final OWLOntologyID ontId = OWLHelper.getVersion(IRI.create(NS + "owlapi.inc.maxLength.restriction"), 1.0); final OWLHelper owl = new OWLGenericTools(group, ontId, true); final OWLNamedIndividual x0 = i.apply("I0"); 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.MAX_LENGTH, OWL.constant(3L)))))); owl.addAxiom(OWL.propertyAssertion(x0, propB, OWL.constant(""))); owl.addAxiom(OWL.propertyAssertion(x1, propB, OWL.constant("AA"))); owl.addAxiom(OWL.propertyAssertion(x2, propB, OWL.constant("AAAAA"))); owl.addAxiom(OWL.differentFrom(SetUtils.create(x0, x1, x2))); final OWLReasoner r = owl.getReasoner(); assertTrue(r.isEntailed(OWL.classAssertion(x0, ClsA))); assertTrue(r.isEntailed(OWL.classAssertion(x1, ClsA))); assertFalse(r.isEntailed(OWL.classAssertion(x2, ClsA))); } }
@Test public void testMaxLengthRestriction() throws OWLOntologyCreationException { try (final OWLManagerGroup group = new OWLManagerGroup()) { final OWLOntologyID ontId = OWLHelper.getVersion(IRI.create(NS + "owlapi.inc.maxLength.restriction"), 1.0); final OWLHelper owl = new OWLGenericTools(group, ontId, true); final OWLNamedIndividual x0 = i.apply("I0"); 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.MAX_LENGTH, OWL.constant(3L)))))); owl.addAxiom(OWL.propertyAssertion(x0, propB, OWL.constant(""))); owl.addAxiom(OWL.propertyAssertion(x1, propB, OWL.constant("AA"))); owl.addAxiom(OWL.propertyAssertion(x2, propB, OWL.constant("AAAAA"))); owl.addAxiom(OWL.differentFrom(SetUtils.create(x0, x1, x2))); final OWLReasoner r = owl.getReasoner(); assertTrue(r.isEntailed(OWL.classAssertion(x0, ClsA))); assertTrue(r.isEntailed(OWL.classAssertion(x1, ClsA))); assertFalse(r.isEntailed(OWL.classAssertion(x2, ClsA))); } }
@Test public void testAddAndRemove() throws OWLOntologyCreationException { try (final OWLManagerGroup group = new OWLManagerGroup()) { final OWLOntologyID ontId = OWLHelper.getVersion(IRI.create(NS + "owlapi.add.remove"), 1.0); final OWLHelper owl = new OWLGenericTools(group, ontId, true); owl.addAxiom(OWL.declaration(OWL.DataProperty(NS + "propA"))); owl.addAxiom(OWL.declaration(OWL.Class(NS + "clsA"))); owl.addAxiom(OWL.equivalentClasses(OWL.Class(NS + "clsA"), // OWL.value(OWL.DataProperty(NS + "propA"), OWL.constant(12))// )); assertTrue(owl.getReasoner().instances(OWL.Class(NS + "clsA")).count() == 0); final OWLNamedIndividual x1 = OWL.Individual(NS + "I1"); owl.addAxiom(OWL.classAssertion(x1, OWL.Class(NS + "clsA"))); assertTrue(owl.getReasoner().instances(OWL.Class(NS + "clsA")).count() == 1); owl.removeAxiom(OWL.classAssertion(x1, OWL.Class(NS + "clsA"))); assertTrue(owl.getReasoner().instances(OWL.Class(NS + "clsA")).count() == 0); } // The test is just about not crash. }
@Test public void testAddAndRemove() throws OWLOntologyCreationException { try (final OWLManagerGroup group = new OWLManagerGroup()) { final OWLOntologyID ontId = OWLHelper.getVersion(IRI.create(NS + "owlapi.add.remove"), 1.0); final OWLHelper owl = new OWLGenericTools(group, ontId, true); owl.addAxiom(OWL.declaration(OWL.DataProperty(NS + "propA"))); owl.addAxiom(OWL.declaration(OWL.Class(NS + "clsA"))); owl.addAxiom(OWL.equivalentClasses(OWL.Class(NS + "clsA"), // OWL.value(OWL.DataProperty(NS + "propA"), OWL.constant(12))// )); assertTrue(owl.getReasoner().instances(OWL.Class(NS + "clsA")).count() == 0); final OWLNamedIndividual x1 = OWL.Individual(NS + "I1"); owl.addAxiom(OWL.classAssertion(x1, OWL.Class(NS + "clsA"))); assertTrue(owl.getReasoner().instances(OWL.Class(NS + "clsA")).count() == 1); owl.removeAxiom(OWL.classAssertion(x1, OWL.Class(NS + "clsA"))); assertTrue(owl.getReasoner().instances(OWL.Class(NS + "clsA")).count() == 0); } // The test is just about not crash. }
final OWLOntologyID ontId = OWLHelper.getVersion(IRI.create(NS + "swrl-build-in"), 1.01); final OWLHelper owl = new OWLGenericTools(group, ontId, true);