private void test(final OWLHelper owl) { final int index = _random.nextInt(_allAxioms.size()); final OWLAxiom axiom = _allAxioms.remove(index); _removedAxioms.add(axiom); owl.getOntology().add(_allAxioms); final OpenlletReasoner r = (OpenlletReasoner) owl.getReasoner(); try { r.isConsistent(); final KnowledgeBase kb = r.getKB(); kb.realize(); kb.classify(); // The error have disappear; lets roll back. final OWLAxiom correct = _removedAxioms.remove(_removedAxioms.size() - 1); System.out.println(correct + "\t may be part of the problem"); _allAxioms.add(correct); } catch (@SuppressWarnings("unused") final Exception e) { // So the error is still present. We have a new minimal ontology. registerOntology(owl.getOntology()); } }
/** * Compute the types of an individual. Use this function only if you mix Named and Anonymous individuals. * * @param ind the individual named _or_ anonymous * @return the classes of the individual. * @since 2.5.1 */ default public NodeSet<OWLClass> getTypes(final OWLIndividual ind) { if (ind instanceof OWLAnonymousIndividual) { // We create a temporary named Individual to allow the reasoner to work. final OWLNamedIndividual individual = getFactory().getOWLNamedIndividual(IRI.create(_protocol + OWLHelper.class.getPackage().getName() + _webSeparator + OWLHelper.class.getSimpleName() + _entitySeparator + IRIUtils.randId(OWLHelper.class.getSimpleName()))); final Stream<OWLAxiom> axioms = Stream.of( // getFactory().getOWLDeclarationAxiom(individual), // getFactory().getOWLSameIndividualAxiom(individual, ind) // The temporary named is the same as the anonymous one. ); getManager().addAxioms(getOntology(), axioms); final NodeSet<OWLClass> result = getReasoner().getTypes(individual, false); getManager().removeAxioms(getOntology(), axioms); return result; } else return getReasoner().getTypes((OWLNamedIndividual) ind, false); }
/** * Compute the types of an individual. Use this function only if you mix Named and Anonymous individuals. * * @param ind the individual named _or_ anonymous * @return the classes of the individual. * @since 2.5.1 */ default public NodeSet<OWLClass> getTypes(final OWLIndividual ind) { if (ind instanceof OWLAnonymousIndividual) { // We create a temporary named Individual to allow the reasoner to work. final OWLNamedIndividual individual = getFactory().getOWLNamedIndividual(IRI.create(_protocol + OWLHelper.class.getPackage().getName() + _webSeparator + OWLHelper.class.getSimpleName() + _entitySeparator + IRIUtils.randId(OWLHelper.class.getSimpleName()))); final Stream<OWLAxiom> axioms = Stream.of( // getFactory().getOWLDeclarationAxiom(individual), // getFactory().getOWLSameIndividualAxiom(individual, ind) // The temporary named is the same as the anonymous one. ); getManager().addAxioms(getOntology(), axioms); final NodeSet<OWLClass> result = getReasoner().getTypes(individual, false); getManager().removeAxioms(getOntology(), axioms); return result; } else return getReasoner().getTypes((OWLNamedIndividual) ind, false); }
/** * Compute the types of an individual. Use this function only if you mix Named and Anonymous individuals. * * @param ind the individual named _or_ anonymous * @return the classes of the individual. * @since 2.5.1 */ default public NodeSet<OWLClass> getTypes(final OWLIndividual ind) { if (ind instanceof OWLAnonymousIndividual) { // We create a temporary named Individual to allow the reasoner to work. final OWLNamedIndividual individual = getFactory().getOWLNamedIndividual(IRI.create(_protocol + OWLHelper.class.getPackage().getName() + _webSeparator + OWLHelper.class.getSimpleName() + _entitySeparator + IRIUtils.randId(OWLHelper.class.getSimpleName()))); final Stream<OWLAxiom> axioms = Stream.of( // getFactory().getOWLDeclarationAxiom(individual), // getFactory().getOWLSameIndividualAxiom(individual, ind) // The temporary named is the same as the anonymous one. ); getManager().addAxioms(getOntology(), axioms); final NodeSet<OWLClass> result = getReasoner().getTypes(individual, false); getManager().removeAxioms(getOntology(), axioms); return result; } else return getReasoner().getTypes((OWLNamedIndividual) ind, false); }
@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 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. }
@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))); } }
final Set<OWLLiteral> results = owl.getReasoner().getDataPropertyValues(individual, property); assertTrue(results.size() == 1); final OWLLiteral literal = results.iterator().next();
final Set<OWLLiteral> results = owl.getReasoner().getDataPropertyValues(individual, property); assertTrue(results.size() == 1); final OWLLiteral literal = results.iterator().next();
@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))); } }
SWRL.consequent(SWRL.propertyAtom(dpB, swrlIndA, inf)))); final OWLReasoner reasoner = owl.getReasoner(); assertFalse(reasoner.isEntailed(OWL.propertyAssertion(a, dpB, OWL.constant("sup")))); assertTrue(reasoner.isEntailed(OWL.propertyAssertion(a, dpB, OWL.constant("inf"))));
SWRL.consequent(SWRL.propertyAtom(dpB, swrlIndA, inf)))); final OWLReasoner reasoner = owl.getReasoner(); assertFalse(reasoner.isEntailed(OWL.propertyAssertion(a, dpB, OWL.constant("sup")))); assertTrue(reasoner.isEntailed(OWL.propertyAssertion(a, dpB, OWL.constant("inf"))));