org.semanticweb.owlapi.model.RemoveAxiom Java Examples
The following examples show how to use
org.semanticweb.owlapi.model.RemoveAxiom.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReasonerUtil.java From SciGraph with Apache License 2.0 | 6 votes |
void removeRedundantAxioms() { final List<RemoveAxiom> changes = new ArrayList<RemoveAxiom>(); Set<OWLClass> allClasses = ont.getClassesInSignature(true); logger.info("Check classes for redundant super class axioms, all OWL classes count: " + allClasses.size()); for (OWLClass cls: allClasses) { final Set<OWLClass> directSuperClasses = reasoner.getSuperClasses(cls, true).getFlattened(); for (final OWLOntology importedOntology: ont.getImportsClosure()) { Set<OWLSubClassOfAxiom> subClassAxioms = importedOntology.getSubClassAxiomsForSubClass(cls); for (final OWLSubClassOfAxiom subClassAxiom : subClassAxioms) { subClassAxiom.getSuperClass().accept(new OWLClassExpressionVisitorAdapter(){ @Override public void visit(OWLClass desc) { if (directSuperClasses.contains(desc) == false) { changes.add(new RemoveAxiom(importedOntology, subClassAxiom)); } } }); } } } logger.info("Found redundant axioms: " + changes.size()); List<OWLOntologyChange> result = manager.applyChanges(changes); logger.info("Removed axioms: " + result.size()); }
Example #2
Source File: OwlChangesLoaderFactory.java From elk-reasoner with Apache License 2.0 | 5 votes |
Set<OWLAxiom> getPendingAxiomRemovals() { Set<OWLAxiom> removed = new HashSet<OWLAxiom>(); for (OWLOntologyChange change : pendingChanges_) { if (change instanceof RemoveAxiom) { removed.add(change.getAxiom()); } } return removed; }
Example #3
Source File: TemplatedTransformer.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
public Set<OWLOntologyChange> tr(OWLAxiom inAxiom, Mapping m) { Set<OWLOntologyChange> chgs = new HashSet<OWLOntologyChange>(); boolean isModified = false; OWLAxiom newAxiom = null; if (inAxiom instanceof OWLEquivalentClassesAxiom) { OWLEquivalentClassesAxiom aa = (OWLEquivalentClassesAxiom)inAxiom; Set<OWLClassExpression> xs = new HashSet<OWLClassExpression>(); for (OWLClassExpression x : aa.getClassExpressions()) { OWLClassExpression x2 = replace(x, m); if (x2 == null) { xs.add(x); } else { isModified = true; xs.add(x2); LOG.info(" TR : "+x+ " ---> "+x2); } } if (isModified) { newAxiom = getOWLDataFactory().getOWLEquivalentClassesAxiom(xs); } } if (isModified) { if (m.isReplace) { chgs.add(new RemoveAxiom(ontology, inAxiom)); } chgs.add(new AddAxiom(ontology, newAxiom)); } return chgs; }
Example #4
Source File: OboOntologyReleaseRunner.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Remove inferred axioms, which are marked by the appropriate axiom annotation. * * @param removedSubClassOfAxioms * @param removedSubClassOfAxiomChanges * * @see AxiomAnnotationTools#isMarkedAsInferredAxiom(OWLAxiom) */ private void removeInferredAxioms(Set<OWLSubClassOfAxiom> removedSubClassOfAxioms, Set<RemoveAxiom> removedSubClassOfAxiomChanges) { final OWLOntology ont = mooncat.getGraph().getSourceOntology(); for (OWLSubClassOfAxiom a : ont.getAxioms(AxiomType.SUBCLASS_OF)) { if (AxiomAnnotationTools.isMarkedAsInferredAxiom(a)) { RemoveAxiom rmax = new RemoveAxiom(ont, a); removedSubClassOfAxiomChanges.add(rmax); removedSubClassOfAxioms.add(a); } } }
Example #5
Source File: ProofTestUtils.java From elk-reasoner with Apache License 2.0 | 4 votes |
public static <I extends Inference<?>> void proofCompletenessTest( final OWLProver prover, final OWLAxiom entailment, final Object conclusion, final Proof<? extends I> proof, final InferenceJustifier<? super I, ? extends Set<? extends OWLAxiom>> justifier, final boolean mustNotBeATautology) { final OWLOntology ontology = prover.getRootOntology(); final OWLOntologyManager manager = ontology.getOWLOntologyManager(); // compute repairs final Set<Set<? extends OWLAxiom>> repairs = new HashSet<Set<? extends OWLAxiom>>(); MinimalSubsetEnumerators.enumerateRepairs(conclusion, proof, justifier, InterruptMonitor.DUMMY, new MinimalSubsetCollector<OWLAxiom>(repairs)); if (mustNotBeATautology) { assertFalse("Entailment is a tautology; there are no repairs!", repairs.isEmpty()); } for (final Set<? extends OWLAxiom> repair : repairs) { final List<OWLOntologyChange> deletions = new ArrayList<OWLOntologyChange>(); final List<OWLOntologyChange> additions = new ArrayList<OWLOntologyChange>(); for (final OWLAxiom axiom : repair) { deletions.add(new RemoveAxiom(ontology, axiom)); additions.add(new AddAxiom(ontology, axiom)); } manager.applyChanges(deletions); final boolean conclusionDerived = prover.isEntailed(entailment); manager.applyChanges(additions); assertFalse("Not all proofs were found!\n" + "Conclusion: " + conclusion + "\n" + "Repair: " + repair, conclusionDerived); } }
Example #6
Source File: ProofTest.java From elk-reasoner with Apache License 2.0 | 4 votes |
@Test public void proofsUnderOntologyUpdate() throws Exception { // loading and classifying via the OWL API OWLOntology ontology = loadOntology( ProofTest.class.getClassLoader().getResourceAsStream( "ontologies/PropertyCompositionsWithHierarchy.owl")); final OWLProver prover = OWLAPITestUtils.createProver(ontology); prover.precomputeInferences(InferenceType.CLASS_HIERARCHY); OWLClass sub = factory.getOWLClass(IRI.create("http://example.org/A")); OWLClass sup = factory.getOWLClass(IRI.create("http://example.org/G")); // printInferences(reasoner, sub, sup); // OWLExpression root = // reasoner.getDerivedExpression(factory.getOWLSubClassOfAxiom(sub, // sup)); // System.err.println(OWLProofUtils.printProofTree(root)); ProofTestUtils.provabilityTest(prover, factory.getOWLSubClassOfAxiom(sub, sup)); // now convert C <= R3 some D to C < S3 some D OWLClass c = factory.getOWLClass(IRI.create("http://example.org/C")); OWLClass d = factory.getOWLClass(IRI.create("http://example.org/D")); OWLObjectProperty r3 = factory .getOWLObjectProperty(IRI.create("http://example.org/R3")); OWLObjectProperty s3 = factory .getOWLObjectProperty(IRI.create("http://example.org/S3")); OWLAxiom oldAx = factory.getOWLSubClassOfAxiom(c, factory.getOWLObjectSomeValuesFrom(r3, d)); OWLAxiom newAx = factory.getOWLSubClassOfAxiom(c, factory.getOWLObjectSomeValuesFrom(s3, d)); OWLOntologyManager manager = ontology.getOWLOntologyManager(); manager.applyChanges(Arrays.asList(new RemoveAxiom(ontology, oldAx), new AddAxiom(ontology, newAx))); prover.precomputeInferences(InferenceType.CLASS_HIERARCHY); // printInferences(reasoner, sub, sup); // root = // reasoner.getDerivedExpression(factory.getOWLSubClassOfAxiom(sub, // sup)); // System.err.println(OWLProofUtils.printProofTree(root)); ProofTestUtils.provabilityTest(prover, factory.getOWLSubClassOfAxiom(sub, sup)); }
Example #7
Source File: ProofTest.java From elk-reasoner with Apache License 2.0 | 4 votes |
@Test public void proofListener() throws Exception { OWLOntologyManager owlManager = OWLManager .createConcurrentOWLOntologyManager(); OWLClass a = factory.getOWLClass(IRI.create("http://example.org/A")); OWLClass b = factory.getOWLClass(IRI.create("http://example.org/B")); OWLClass c = factory.getOWLClass(IRI.create("http://example.org/C")); OWLObjectProperty r = factory .getOWLObjectProperty(IRI.create("http://example.org/R")); OWLObjectProperty s = factory .getOWLObjectProperty(IRI.create("http://example.org/S")); OWLAxiom ax1 = factory.getOWLSubClassOfAxiom(a, c); OWLAxiom ax2 = factory.getOWLSubClassOfAxiom(c, b); OWLAxiom ax3 = factory.getOWLSubClassOfAxiom(a, factory.getOWLObjectSomeValuesFrom(r, c)); OWLAxiom ax4 = factory.getOWLSubClassOfAxiom( factory.getOWLObjectSomeValuesFrom(s, c), b); OWLAxiom ax5 = factory.getOWLSubObjectPropertyOfAxiom(r, s); boolean changed = false; // means entailment has changed for (boolean bufferringMode : Arrays.asList(true, false)) { // creating an ontology final OWLOntology ontology = owlManager.createOntology(); final OWLProver prover = OWLAPITestUtils.createProver( OWLAPITestUtils.createReasoner(ontology, bufferringMode)); OWLSubClassOfAxiom entailment = factory.getOWLSubClassOfAxiom(a, b); DynamicProof<? extends Inference<OWLAxiom>> proof = prover .getProof(entailment); ProofChangeTracker tracker = new ProofChangeTracker(); proof.addListener(tracker); assertFalse(Proofs.isDerivable(proof, entailment)); // add ax1 and ax2 => ENTAIL owlManager.applyChanges(Arrays.asList(new AddAxiom(ontology, ax1), new AddAxiom(ontology, ax2))); // derivable only in non-buffering mode changed = tracker.changed(); assertEquals(!bufferringMode, changed); assertEquals(!bufferringMode, Proofs.isDerivable(proof, entailment)); // but always derivable after flush prover.flush(); changed |= tracker.changed(); assertTrue(changed); assertTrue(Proofs.isDerivable(proof, entailment)); // remove ax1, add ax3, ax4 => NOT ENTAIL owlManager.applyChanges(Arrays.asList( new RemoveAxiom(ontology, ax1), new AddAxiom(ontology, ax3), new AddAxiom(ontology, ax4))); // still derivable only in bufferring mode changed = tracker.changed(); assertEquals(!bufferringMode, changed); assertEquals(bufferringMode, Proofs.isDerivable(proof, entailment)); // always non derivable after flush prover.flush(); changed |= tracker.changed(); assertTrue(changed); assertFalse(Proofs.isDerivable(proof, entailment)); // add ax5 => ENTAIL owlManager.applyChanges(Arrays.asList(new AddAxiom(ontology, ax5))); // derivable only in non-buffering mode changed = tracker.changed(); assertEquals(!bufferringMode, changed); assertEquals(!bufferringMode, Proofs.isDerivable(proof, entailment)); // but always derivable after flush prover.flush(); changed |= tracker.changed(); assertTrue(changed); assertTrue(Proofs.isDerivable(proof, entailment)); } }
Example #8
Source File: OWLGraphManipulator.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Relaxes all {@code OWLObjectIntersectionOf}s. This method will relax * {@code OWLSubClassOfAxiom}s, whose superclass is an {@code OWLObjectIntersectionOf}, * into multiple {@code OWLSubClassOfAxiom}s, using a <a * href='http://owlapi.sourceforge.net/javadoc/org/semanticweb/owlapi/SplitSubClassAxioms.html'> * SplitSubClassAxioms</a>. It will also relax {@code OWLSubClassOfAxiom}s, whose * superclass is an {@code OWLObjectSomeValuesFrom} with a filler being an * {@code OWLObjectIntersectionOf}, into multiple {@code OWLSubClassOfAxiom}s with * an {@code OWLObjectSomeValuesFrom} as superclass, with the same * {@code OWLPropertyExpression}, and individual operands as filler. * <p> * Note that it is likely that the {@code OWLObjectIntersectionOf}s where used in * {@code OWLEquivalentClassesAxiom}s, rather than in {@code OWLSubClassOfAxiom}s. * But the method {@link #convertEquivalentClassesToSuperClasses()} would have transformed * them into {@code OWLSubClassOfAxiom}s. It must be called before this method. * * @see #performDefaultModifications() * @see #convertEquivalentClassesToSuperClasses() */ private void splitSubClassAxioms() { log.info("Relaxing OWLSubClassOfAxioms whose superclass is an OWLObjectIntersectionOf"); //first, split subClassOf axioms whose superclass is an OWLObjectIntersectionOf SplitSubClassAxioms split = new SplitSubClassAxioms( this.getOwlGraphWrapper().getAllOntologies(), this.getOwlGraphWrapper().getDataFactory()); this.getOwlGraphWrapper().getManager().applyChanges(split.getChanges()); this.triggerWrapperUpdate(); //some ontologies use an OWLObjectIntersectionOf as the filler of //an OWLObjectSomeValuesFrom class expression. We go only one level down //(i.e., we would not translate another OWLObjectSomeValuesFrom part of the //OWLObjectIntersectionOf) OWLDataFactory dataFactory = this.getOwlGraphWrapper().getDataFactory(); List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>(); for (OWLOntology ont : this.getOwlGraphWrapper().getAllOntologies()) { for (OWLSubClassOfAxiom ax : ont.getAxioms(AxiomType.SUBCLASS_OF)) { OWLClassExpression superClsExpr = ax.getSuperClass(); if (superClsExpr instanceof OWLObjectSomeValuesFrom) { OWLObjectSomeValuesFrom someValuesFrom = (OWLObjectSomeValuesFrom) superClsExpr; if (someValuesFrom.getFiller() instanceof OWLObjectIntersectionOf) { //remove original axiom changes.add(new RemoveAxiom(ont, ax)); OWLObjectIntersectionOf filler = (OWLObjectIntersectionOf) someValuesFrom.getFiller(); for (OWLClassExpression op : filler.getOperands()) { //we accept only OWLClasses, otherwise we would need to compose //OWLObjectPropertyExpressions if (op instanceof OWLClass) { OWLAxiom replAx = dataFactory. getOWLSubClassOfAxiom(ax.getSubClass(), dataFactory.getOWLObjectSomeValuesFrom( someValuesFrom.getProperty(), op)); changes.add(new AddAxiom(ont, replAx)); } } } } } } this.getOwlGraphWrapper().getManager().applyChanges(changes); this.triggerWrapperUpdate(); log.info("OWLObjectIntersectionOf relaxation done."); }
Example #9
Source File: OWLGraphManipulatorTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Test that two {@code OWLClass}es that are equal have a same hashcode, * because the OWLGraphEdge bug get me paranoid. */ @Test public void testOWLOntologyChangeHashCode() { OWLOntology ont = this.graphManipulator.getOwlGraphWrapper().getSourceOntology(); OWLDataFactory factory = this.graphManipulator.getOwlGraphWrapper(). getManager().getOWLDataFactory(); OWLClass source = this.graphManipulator.getOwlGraphWrapper().getOWLClassByIdentifier("FOO:0005"); OWLClass target = this.graphManipulator.getOwlGraphWrapper().getOWLClassByIdentifier("FOO:0001"); OWLGraphEdge checkEdge = new OWLGraphEdge(source, target, ont); OWLAxiom axiom = factory.getOWLSubClassOfAxiom(source, (OWLClassExpression) this.graphManipulator.getOwlGraphWrapper(). edgeToTargetExpression(checkEdge)); OWLAxiomChange rm1 = new RemoveAxiom(ont, axiom); OWLGraphEdge checkEdge2 = new OWLGraphEdge(source, target, ont); OWLAxiom axiom2 = factory.getOWLSubClassOfAxiom(source, (OWLClassExpression) this.graphManipulator.getOwlGraphWrapper(). edgeToTargetExpression(checkEdge2)); OWLAxiomChange rm2 = new RemoveAxiom(ont, axiom2); assertTrue("The two OWLAxiomChange objects are equal", rm1.equals(rm2)); //then of course the hashcodes will be the same... assertTrue("Two OWLAxiomChange are equal but have different hashcode", rm1.equals(rm2) && rm1.hashCode() == rm2.hashCode()); source = this.graphManipulator.getOwlGraphWrapper().getOWLClassByIdentifier("FOO:0014"); target = this.graphManipulator.getOwlGraphWrapper().getOWLClassByIdentifier("FOO:0001"); checkEdge = new OWLGraphEdge(source, target, ont); axiom = factory.getOWLSubClassOfAxiom(source, (OWLClassExpression) this.graphManipulator.getOwlGraphWrapper(). edgeToTargetExpression(checkEdge)); OWLAxiomChange rm3 = new RemoveAxiom(ont, axiom); assertFalse("Different OWLAxiomChange objects are equal", rm1.equals(rm3)); //then of course the hashcodes will be the same... assertFalse("Different OWLAxiomChanges have same hashcode", rm1.hashCode() == rm3.hashCode()); }
Example #10
Source File: OwlOntologyChangeProcessorVisitor.java From elk-reasoner with Apache License 2.0 | 3 votes |
@Override public void visit(RemoveAxiom arg) { ElkAxiom elkAxiom = OWL_CONVERTER_.convert(arg.getAxiom()); axiomDeleter_.visit(elkAxiom); if (LOGGER_.isTraceEnabled()) LOGGER_.trace("removing " + arg.getAxiom()); }