Skip to content

Commit

Permalink
Adapt to changes in the Proof interface of puli
Browse files Browse the repository at this point in the history
+ some resulting simplifications
  • Loading branch information
ykazakov committed Oct 6, 2017
1 parent 7cf796d commit 934a965
Show file tree
Hide file tree
Showing 43 changed files with 414 additions and 419 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.Set;

import org.liveontologies.owlapi.proof.OWLProver;
import org.liveontologies.puli.DynamicProof;
import org.liveontologies.puli.Inference;
import org.liveontologies.puli.Proof;
import org.semanticweb.elk.owlapi.ElkProverFactory;
Expand Down Expand Up @@ -74,34 +75,34 @@ public static void main(String[] args) throws OWLOntologyCreationException {
OWLAxiom entailment = getEntailment();

// Get the inferences used to prove the entailment
Proof<OWLAxiom> inferences = prover.getProof(entailment);
DynamicProof<? extends Inference<OWLAxiom>> proof = prover.getProof(entailment);

// Now we can recursively request inferences and their premises. Print them to std.out in this example.
unwindProofs(inferences, entailment);
unwindProof(proof, entailment);

// Terminate the worker threads used by the reasoner.
prover.dispose();
}

private static <C> void unwindProofs(Proof<C> inferences, C entailment) {
// Start recursive unwinding
LinkedList<C> toDo = new LinkedList<C>();
Set<C> done = new HashSet<C>();
private static void unwindProof(Proof<?> proof, Object entailment) {
// Start recursive unwinding of conclusions
LinkedList<Object> toDo = new LinkedList<Object>();
Set<Object> done = new HashSet<Object>();

toDo.add(entailment);
done.add(entailment);

for (;;) {
C next = toDo.poll();
Object next = toDo.poll();

if (next == null) {
break;
}

for (Inference<C> inf : inferences.getInferences(next)) {
for (Inference<?> inf : proof.getInferences(next)) {
System.out.println(inf);
// Recursively unwind premise inferences
for (C premise : inf.getPremises()) {
for (Object premise : inf.getPremises()) {

if (done.add(premise)) {
toDo.addFirst(premise);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import org.liveontologies.owlapi.proof.OWLProver;
import org.liveontologies.puli.DynamicProof;
import org.semanticweb.elk.owlapi.proofs.ElkOwlInference;
import org.semanticweb.elk.owlapi.proofs.ElkOwlProof;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.reasoner.UnsupportedEntailmentTypeException;
Expand All @@ -35,7 +36,7 @@ public ElkProver(ElkReasoner elkReasoner) {
}

@Override
public DynamicProof<OWLAxiom> getProof(OWLAxiom entailment)
public DynamicProof<ElkOwlInference> getProof(OWLAxiom entailment)
throws UnsupportedEntailmentTypeException {
return ElkOwlProof.create(getDelegate(), entailment);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
import java.util.Collection;

import org.liveontologies.puli.BaseProof;
import org.liveontologies.puli.GenericDynamicProof;
import org.liveontologies.puli.DynamicProof;
import org.liveontologies.puli.Proof;
import org.liveontologies.puli.Proofs;
import org.semanticweb.elk.exceptions.ElkException;
import org.semanticweb.elk.exceptions.ElkRuntimeException;
Expand All @@ -36,15 +37,15 @@
import org.semanticweb.elk.owlapi.ElkConverter;
import org.semanticweb.elk.owlapi.ElkReasoner;
import org.semanticweb.elk.owlapi.wrapper.OwlConverter;
import org.semanticweb.elk.reasoner.entailments.model.EntailmentProof;
import org.semanticweb.elk.reasoner.entailments.model.EntailmentInference;
import org.semanticweb.elk.reasoner.query.EntailmentQueryResult;
import org.semanticweb.elk.reasoner.query.ProperEntailmentQueryResult;
import org.semanticweb.elk.reasoner.query.UnsupportedIndexingEntailmentQueryResult;
import org.semanticweb.elk.reasoner.query.UnsupportedQueryTypeEntailmentQueryResult;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.reasoner.UnsupportedEntailmentTypeException;

public class ElkOwlProof extends BaseProof<OWLAxiom, ElkOwlInference>
public class ElkOwlProof extends BaseProof<ElkOwlInference>
implements ElkReasoner.ChangeListener {

private final ElkReasoner elkReasoner_;
Expand All @@ -70,7 +71,7 @@ private ElkOwlProof(ElkReasoner elkReasoner, OWLAxiom elkEntailment) {

@Override
public synchronized Collection<? extends ElkOwlInference> getInferences(
OWLAxiom conclusion) {
Object conclusion) {
ensureSync();
return super.getInferences(conclusion);
}
Expand Down Expand Up @@ -123,7 +124,7 @@ public Void visit(final ProperEntailmentQueryResult properResult)
ElkOwlProof.this);
final ElkInference.Factory factory = new ElkInferenceOptimizedProducingFactory(
producer);
final EntailmentProof evidence = properResult
final Proof<EntailmentInference> evidence = properResult
.getEvidence(false);
new ElkProofGenerator(evidence,
elkReasoner_.getInternalReasoner(), factory)
Expand Down Expand Up @@ -153,9 +154,8 @@ public Void visit(

};

public static GenericDynamicProof<OWLAxiom, ElkOwlInference> create(
ElkReasoner reasoner, OWLAxiom entailment)
throws UnsupportedEntailmentTypeException {
public static DynamicProof<ElkOwlInference> create(ElkReasoner reasoner,
OWLAxiom entailment) throws UnsupportedEntailmentTypeException {
if (reasoner == null) {
return Proofs.emptyProof();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.semanticweb.elk.owlapi.proofs;

/*-
* #%L
* ELK OWL API Binding
* $Id:$
* $HeadURL:$
* %%
* Copyright (C) 2011 - 2017 Department of Computer Science, University of Oxford
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/

import java.util.Set;

import org.liveontologies.puli.Inference;
import org.liveontologies.puli.InferenceJustifier;
import org.semanticweb.elk.owl.interfaces.ElkAxiom;
import org.semanticweb.elk.owlapi.ElkConverter;
import org.semanticweb.elk.proofs.InternalJustifier;
import org.semanticweb.owlapi.model.OWLAxiom;

import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;

public class OwlInternalJustifier
implements InferenceJustifier<Inference<?>, Set<OWLAxiom>>,
Function<ElkAxiom, OWLAxiom> {

private final InferenceJustifier<Inference<?>, Set<? extends ElkAxiom>> internalJustifier_ = new InternalJustifier();

private final ElkConverter elkConverter_ = ElkConverter.getInstance();

@Override
public Set<OWLAxiom> getJustification(Inference<?> inference) {
return ImmutableSet.copyOf(Iterables.transform(
internalJustifier_.getJustification(inference), this));
}

@Override
public OWLAxiom apply(final ElkAxiom input) {
return elkConverter_.convert(input);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@

import java.util.Arrays;
import java.util.Collection;
import java.util.Set;

import org.liveontologies.puli.Inference;
import org.liveontologies.puli.InferenceJustifier;
import org.liveontologies.puli.InferenceJustifiers;
import org.liveontologies.puli.Inferences;
import org.liveontologies.puli.Proof;
import org.semanticweb.elk.exceptions.ElkException;
Expand All @@ -41,18 +38,14 @@
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.reasoner.UnsupportedEntailmentTypeException;

import com.google.common.base.Function;

public class OwlInternalProof implements Proof<Object>,
InferenceJustifier<Object, Set<? extends OWLAxiom>> {
public class OwlInternalProof implements Proof<Inference<Object>> {

private final OwlConverter owlConverter_ = OwlConverter.getInstance();
private final ElkConverter elkConverter_ = ElkConverter.getInstance();

private final OWLAxiom goal_;
private final Inference<Object> goalInference_;
private final InternalProofExtension proof_;
private final InferenceJustifier<Object, ? extends Set<? extends OWLAxiom>> justifier_;

public OwlInternalProof(final Reasoner reasoner, final OWLAxiom goal) {
this.goal_ = goal;
Expand All @@ -62,13 +55,6 @@ public OwlInternalProof(final Reasoner reasoner, final OWLAxiom goal) {
try {
this.proof_ = new InternalProofExtension(reasoner,
owlConverter_.convert(goal));
this.justifier_ = InferenceJustifiers.transform(proof_,
new Function<ElkAxiom, OWLAxiom>() {
@Override
public OWLAxiom apply(final ElkAxiom input) {
return elkConverter_.convert(input);
}
});
} catch (final ElkException e) {
throw elkConverter_.convert(e);
} catch (final ElkRuntimeException e) {
Expand All @@ -93,12 +79,6 @@ public Collection<? extends Inference<Object>> getInferences(
return proof_.getInferences(conclusion);
}

@Override
public Set<? extends OWLAxiom> getJustification(
Inference<Object> inference) {
return justifier_.getJustification(inference);
}

private class InternalProofExtension extends InternalProof {

public InternalProofExtension(final Reasoner reasoner,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,22 @@ public class OwlInternalProofTest {

// @formatter:off
static final String[] IGNORE_LIST = {
ElkTestUtils.TEST_INPUT_LOCATION + "/query/entailment/AssertionRanges.owl",// Ranges not supported with assertions
ElkTestUtils.TEST_INPUT_LOCATION + "/query/entailment/HasValueRanges.owl",// Ranges not supported with ObjectHasValue
};
ElkTestUtils.TEST_INPUT_LOCATION
+ "/query/entailment/AssertionRanges.owl", // Ranges not
// supported
// with
// assertions
ElkTestUtils.TEST_INPUT_LOCATION
+ "/query/entailment/HasValueRanges.owl",// Ranges not
// supported
// with
// ObjectHasValue
};
static final String[] IGNORE_COMPLETENESS_LIST = {
ElkTestUtils.TEST_INPUT_LOCATION + "/query/entailment/EmptyOntology.owl",// All entailments are tautologies.
};
ElkTestUtils.TEST_INPUT_LOCATION
+ "/query/entailment/EmptyOntology.owl",// All entailments
// are tautologies.
};
// @formatter:on

static {
Expand Down Expand Up @@ -103,7 +113,7 @@ public void testProofCompleteness() throws Exception {
Assume.assumeFalse(TestUtils.ignore(manifest_.getInput(),
ElkTestUtils.TEST_INPUT_LOCATION, IGNORE_COMPLETENESS_LIST));
ProofTestUtils.proofCompletenessTest(prover_, query_,
adapter_.getGoal(), adapter_, adapter_, true);
adapter_.getGoal(), adapter_, new OwlInternalJustifier(), true);
}

@Config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.junit.Test;
import org.liveontologies.owlapi.proof.OWLProver;
import org.liveontologies.puli.DynamicProof;
import org.liveontologies.puli.Inference;
import org.liveontologies.puli.ProofNode;
import org.liveontologies.puli.ProofNodes;
import org.liveontologies.puli.ProofStep;
Expand Down Expand Up @@ -388,7 +389,8 @@ public void proofListener() throws Exception {
final OWLProver prover = OWLAPITestUtils.createProver(
OWLAPITestUtils.createReasoner(ontology, bufferringMode));
OWLSubClassOfAxiom entailment = factory.getOWLSubClassOfAxiom(a, b);
DynamicProof<OWLAxiom> proof = prover.getProof(entailment);
DynamicProof<? extends Inference<OWLAxiom>> proof = prover
.getProof(entailment);
ProofChangeTracker tracker = new ProofChangeTracker();
proof.addListener(tracker);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.Set;

import org.liveontologies.owlapi.proof.OWLProver;
import org.liveontologies.puli.Inference;
import org.liveontologies.puli.InferenceJustifier;
import org.liveontologies.puli.InferenceJustifiers;
import org.liveontologies.puli.Proof;
Expand Down Expand Up @@ -66,14 +67,14 @@
*/
public class ProofTestUtils {

public static <C> void provabilityTest(final Proof<C> proof,
final C conclusion) {
public static void provabilityTest(final Proof<?> proof,
final Object conclusion) {
assertTrue(String.format("Conclusion %s not derivable!", conclusion),
isDerivable(proof, conclusion));
}

public static <C> boolean isDerivable(final Proof<C> proof,
final C conclusion) {
public static boolean isDerivable(final Proof<?> proof,
final Object conclusion) {
return Proofs.isDerivable(proof, conclusion);
}

Expand Down Expand Up @@ -163,25 +164,27 @@ public static void proofCompletenessTest(final OWLProver prover,
public static void proofCompletenessTest(final OWLProver prover,
final OWLAxiom conclusion, final boolean mustNotBeATautology) {
final OWLOntology ontology = prover.getRootOntology();
final Proof<OWLAxiom> proof = Proofs.addAssertedInferences(
Proof<Inference<OWLAxiom>> proof = Proofs.removeAssertedInferences(
prover.getProof(conclusion),
ontology.getAxioms(Imports.INCLUDED));
final InferenceJustifier<OWLAxiom, ? extends Set<? extends OWLAxiom>> justifier = InferenceJustifiers
final InferenceJustifier<Inference<OWLAxiom>, ? extends Set<? extends OWLAxiom>> justifier = InferenceJustifiers
.justifyAssertedInferences();
proofCompletenessTest(prover, conclusion, conclusion, proof, justifier,
mustNotBeATautology);
}

public static <C> void proofCompletenessTest(final OWLProver prover,
final OWLAxiom entailment, final C conclusion, final Proof<C> proof,
final InferenceJustifier<C, ? extends Set<? extends OWLAxiom>> justifier) {
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) {
proofCompletenessTest(prover, entailment, conclusion, proof, justifier,
false);
}

public static <C> void proofCompletenessTest(final OWLProver prover,
final OWLAxiom entailment, final C conclusion, final Proof<C> proof,
final InferenceJustifier<C, ? extends Set<? extends OWLAxiom>> justifier,
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
package org.semanticweb.elk.owl.inferences;

import org.liveontologies.puli.Proof;
import org.semanticweb.elk.owl.interfaces.ElkAxiom;

public interface ElkProof extends Proof<ElkAxiom> {
public interface ElkProof extends Proof<ElkInference> {

}
Loading

0 comments on commit 934a965

Please sign in to comment.