ProvenanceReasonerWrapper { public void reason() throws OWLOntologyCreationException { OWLOntologyManager m = getManager(); OWLDataFactory df = m.getOWLDataFactory(); OWLAnnotationProperty requiresAP = df.getOWLAnnotationProperty(IRI.create(SOURCE_PROPERTY_IRI)); OWLReasoner reasoner = rf.createReasoner(ontology); edges = new HashSet<OWLEdge>(); for (OWLClass c : ontology.getClassesInSignature(Imports.EXCLUDED)) { for (OWLClass p : reasoner.getSuperClasses(c, true).getFlattened()) { if (ontology.getEquivalentClassesAxioms(p).size() > 0) { OWLEdge e = new OWLEdge(c,p); edges.add(e); LOG.info("Edge: "+e); } } } LOG.info("EDGES:"+edges.size()); for (OWLEdge e : edges) { if (!isEdgeEntailed(e, ontology, reasoner)) { e.isJustified = false; } } reasoner.dispose(); for (OWLOntology leaveOutOntology : ontology.getImportsClosure()) { reasonLeavingOneOut(leaveOutOntology); } Set<OWLSubClassOfAxiom> scas = new HashSet<OWLSubClassOfAxiom>(); for (OWLEdge e : edges) { LOG.info("FINAL EDGE: "+e+" REQUIRES: "+e.requires+" JUSTIFIED: "+e.isJustified); Set<OWLAnnotation> anns = new HashSet<OWLAnnotation>(); for (IRI r : e.requires) { anns.add(df.getOWLAnnotation(requiresAP, r)); } OWLSubClassOfAxiom sca = df.getOWLSubClassOfAxiom(e.c, e.p, anns); scas.add(sca); } LOG.info("Adding axioms: "+scas.size()); m.addAxioms(outputOntology, scas); } ProvenanceReasonerWrapper(OWLOntology ontology, OWLReasonerFactory rf); void reason(); void reasonLeavingOneOut(OWLOntology leaveOutOntology); boolean isEdgeEntailed(OWLEdge e, OWLOntology currentOntology, OWLReasoner reasoner); Set<OWLEdge> getEdges(); OWLOntologyManager getManager(); public OWLOntology outputOntology; }
@Test public void testReason() throws Exception { ParserWrapper pw = new ParserWrapper(); pw.getManager().getIRIMappers().add(new CatalogXmlIRIMapper(getResource("mooncat/eq-lattice/catalog-v001.xml"))); OWLOntology o = pw.parseOWL(getResourceIRIString("mooncat/eq-lattice/eq-with-imports.owl")); ProvenanceReasonerWrapper pr = new ProvenanceReasonerWrapper(o, new ElkReasonerFactory()); pr.reason(); assertEquals(143, pr.edges.size()); o.getOWLOntologyManager().saveOntology(o, new FileOutputStream("target/eq-inf.ttl")); }