static private void recursiveBuild(final Taxonomy<OWLClass> taxonomy, final Node<OWLClass> eqClasses, final OpenlletReasoner reasoner) { assert eqClasses.entities().findAny().isPresent() : "Equivalents empty as passed"; final OWLClass cls = eqClasses.iterator().next(); if (taxonomy.contains(cls)) return; final Set<OWLClass> emptySet = Collections.emptySet(); taxonomy.addNode(eqClasses.entities().collect(Collectors.toList()), emptySet, emptySet, /* hidden =*/false); for (final Node<OWLClass> subEq : reasoner.getSubClasses(cls, true)) { recursiveBuild(taxonomy, subEq, reasoner); taxonomy.addSuper(subEq.iterator().next(), cls); } }
static private void recursiveBuild(final Taxonomy<OWLClass> taxonomy, final Node<OWLClass> eqClasses, final OpenlletReasoner reasoner) { assert eqClasses.entities().findAny().isPresent() : "Equivalents empty as passed"; final OWLClass cls = eqClasses.iterator().next(); if (taxonomy.contains(cls)) return; final Set<OWLClass> emptySet = Collections.emptySet(); taxonomy.addNode(eqClasses.entities().collect(Collectors.toList()), emptySet, emptySet, /* hidden =*/false); for (final Node<OWLClass> subEq : reasoner.getSubClasses(cls, true)) { recursiveBuild(taxonomy, subEq, reasoner); taxonomy.addSuper(subEq.iterator().next(), cls); } }
/** * Build the class hierarchy based on the results from the _reasoner */ static public Taxonomy<OWLClass> buildClassHierarchy(final OpenlletReasoner reasoner) { final Taxonomy<OWLClass> taxonomy = new TaxonomyImpl<>(null, OWL.Thing, OWL.Nothing); final Set<OWLClass> things = reasoner.getEquivalentClasses(OWL.Thing).entities().collect(Collectors.toSet()); things.remove(OWL.Thing); if (!things.isEmpty()) taxonomy.addEquivalents(OWL.Thing, things); final Set<OWLClass> nothings = reasoner.getEquivalentClasses(OWL.Nothing).entities().collect(Collectors.toSet()); nothings.remove(OWL.Nothing); if (!nothings.isEmpty()) taxonomy.addEquivalents(OWL.Nothing, nothings); for (final Node<OWLClass> subEq : reasoner.getSubClasses(OWL.Thing, true)) recursiveBuild(taxonomy, subEq, reasoner); return taxonomy; }
/** * Build the class hierarchy based on the results from the _reasoner */ static public Taxonomy<OWLClass> buildClassHierarchy(final OpenlletReasoner reasoner) { final Taxonomy<OWLClass> taxonomy = new TaxonomyImpl<>(null, OWL.Thing, OWL.Nothing); final Set<OWLClass> things = reasoner.getEquivalentClasses(OWL.Thing).entities().collect(Collectors.toSet()); things.remove(OWL.Thing); if (!things.isEmpty()) taxonomy.addEquivalents(OWL.Thing, things); final Set<OWLClass> nothings = reasoner.getEquivalentClasses(OWL.Nothing).entities().collect(Collectors.toSet()); nothings.remove(OWL.Nothing); if (!nothings.isEmpty()) taxonomy.addEquivalents(OWL.Nothing, nothings); for (final Node<OWLClass> subEq : reasoner.getSubClasses(OWL.Thing, true)) recursiveBuild(taxonomy, subEq, reasoner); return taxonomy; }
private void explainClassHierarchy(final OWLClass cls, final Node<OWLClass> eqClasses, final Set<OWLClass> visited) throws OWLException { if (visited.contains(cls)) { return; } visited.add(cls); visited.addAll(eqClasses.entities().collect(Collectors.toList())); for (final OWLClass eqClass : eqClasses) { _monitor.incrementProgress(); explainEquivalentClass(cls, eqClass); } _reasoner.getInstances(cls, true).entities().forEach(ind -> explainInstance(ind, cls)); final NodeSet<OWLClass> subClasses = _reasoner.getSubClasses(cls, true); final Map<OWLClass, Node<OWLClass>> subClassEqs = new HashMap<>(); for (final Node<OWLClass> equivalenceSet : subClasses) { if (equivalenceSet.isBottomNode()) { continue; } final OWLClass subClass = equivalenceSet.getRepresentativeElement(); subClassEqs.put(subClass, equivalenceSet); explainSubClass(subClass, cls); } for (final Map.Entry<OWLClass, Node<OWLClass>> entry : subClassEqs.entrySet()) { explainClassHierarchy(entry.getKey(), entry.getValue(), visited); } }
@Test public void testSubClassDirectParameter() { final OWLAxiom[] axioms = { OWL.subClassOf(_E, _D), OWL.subClassOf(_D, _C) }; final OWLOntology ont = OWL.Ontology(axioms); final OpenlletReasoner pellet = OpenlletReasonerFactory.getInstance().createReasoner(ont); assertTrue(pellet.getSubClasses(_C, true).nodes().count() == 1); assertTrue(pellet.getSubClasses(_C, false).nodes().count() == 3); // includes owl:Nothing }
@Test public void testQualifiedCardinality1() { final String ns = "http://www.example.org/test#"; final OWLOntology ont = loadOntology(OWLManager.createOWLOntologyManager(), _base + "qcr.owl"); final OpenlletReasoner reasoner = OpenlletReasonerFactory.getInstance().createReasoner(ont); final OWLClass sub = Class(ns + "sub"); final OWLClass sup = Class(ns + "sup"); assertTrue(reasoner.isConsistent()); assertTrue(reasoner.isEntailed(subClassOf(sub, sup))); assertTrue(reasoner.getSubClasses(sup, false).entities().filter(x -> x.equals(sub)).findAny().isPresent()); assertTrue(reasoner.getSuperClasses(sub, false).entities().filter(x -> x.equals(sup)).findAny().isPresent()); }
@Ignore @Test public void testSetTheory() // This test doesn't work, the url isn't available. { final String ns = "http://www.integratedmodelling.org/ks/tarassandbox/set-theory.owl#"; final OWLOntology ont = loadOntology(OWLManager.createOWLOntologyManager(), _base + "set-theory.owl"); final OpenlletReasoner reasoner = OpenlletReasonerFactory.getInstance().createReasoner(ont); reasoner.getKB().classify(); assertStreamAsSetEquals(Stream.of(OWL.Class(ns + "SetOfXSets"), OWL.Class(ns + "XSet"), OWL.Class(ns + "XThing")), reasoner.getSubClasses(OWL.Class(ns + "XSetTheoryClass"), true).entities()); }
for (final OWLSubClassOfAxiom axiom : it) final boolean entailed = reasoner.getSubClasses(axiom.getSuperClass(), true).containsEntity((OWLClass) axiom.getSubClass());
@Test public void testAnonInverse() { final String ns = "http://www.example.org/test#"; final OWLOntology ont = loadOntology(OWLManager.createOWLOntologyManager(), _base + "anon_inverse.owl"); final OpenlletReasoner reasoner = OpenlletReasonerFactory.getInstance().createReasoner(ont); final OWLClass C = Class(ns + "C"); final OWLClass D = Class(ns + "D"); final OWLObjectProperty r = ObjectProperty(ns + "r"); final OWLClassExpression desc = some(inverse(r), D); assertStreamAsSetEquals(Stream.of(C), reasoner.getSubClasses(desc, true).entities()); assertTrue(reasoner.isEntailed(inverseFunctional(ObjectProperty(ns + "functionalP")))); assertTrue(reasoner.isEntailed(functional(ObjectProperty(ns + "inverseFunctionalP")))); assertTrue(reasoner.isEntailed(transitive(ObjectProperty(ns + "transitiveP")))); assertTrue(reasoner.isEntailed(symmetric(ObjectProperty(ns + "symmetricP")))); assertTrue(reasoner.isEntailed(reflexive(ObjectProperty(ns + "reflexiveP")))); assertTrue(reasoner.isEntailed(irreflexive(ObjectProperty(ns + "irreflexiveP")))); assertTrue(reasoner.isEntailed(asymmetric(ObjectProperty(ns + "asymmetricP")))); final OWLObjectProperty p1 = ObjectProperty(ns + "p1"); final OWLObjectProperty p2 = ObjectProperty(ns + "p2"); final OWLObjectProperty p3 = ObjectProperty(ns + "p3"); assertTrue(reasoner.isEntailed(equivalentProperties(p1, p2))); assertTrue(reasoner.isEntailed(equivalentProperties(p1, p3))); assertTrue(reasoner.isEntailed(equivalentProperties(p2, p3))); }