org.semanticweb.elk.proofs.InternalProof Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of elk-proofs Show documentation
Show all versions of elk-proofs Show documentation
Utilities to present tracing results (encoded proofs) to the
user
/*-
* #%L
* ELK Proofs Package
* $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%
*/
package org.semanticweb.elk.proofs;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Set;
import org.liveontologies.puli.BaseProof;
import org.liveontologies.puli.Inference;
import org.liveontologies.puli.Inferences;
import org.liveontologies.puli.ModifiableProof;
import org.liveontologies.puli.Proof;
import org.semanticweb.elk.exceptions.ElkException;
import org.semanticweb.elk.owl.interfaces.ElkAxiom;
import org.semanticweb.elk.reasoner.Reasoner;
import org.semanticweb.elk.reasoner.entailments.model.Entailment;
import org.semanticweb.elk.reasoner.entailments.model.EntailmentInference;
import org.semanticweb.elk.reasoner.entailments.model.HasReason;
import org.semanticweb.elk.reasoner.proof.ReasonerProof;
import org.semanticweb.elk.reasoner.query.VerifiableQueryResult;
import org.semanticweb.elk.reasoner.tracing.Conclusion;
import org.semanticweb.elk.reasoner.tracing.TracingInference;
import org.semanticweb.elk.util.collections.ArrayHashSet;
/**
* Combines {@link org.semanticweb.elk.reasoner.tracing.TracingProof
* TracingProof} and a {@link Proof} over {@link EntailmentInference}s into a
* {@link Proof} over common conclusions and justifies the
* {@link TracingInference}s with their axioms.
*
* @author Peter Skocovsky
*/
public class InternalProof implements Proof> {
private final Reasoner reasoner_;
private final ElkAxiom goal_;
private final ModifiableProof> proof_ = new BaseProof>();
public InternalProof(final Reasoner reasoner, final ElkAxiom goal)
throws ElkException {
this.reasoner_ = reasoner;
this.goal_ = goal;
VerifiableQueryResult result = reasoner.checkEntailment(goal);
try {
final Entailment entailment = result.getEntailment();
if (entailment == null) {
// goal is not proved -> empty proof
return;
}
proof_.produce(Inferences.create("Goal inference", goal_,
Arrays.asList(entailment)));
processEntailment(entailment, result.getEvidence(false));
} finally {
result.unlock();
}
}
private void processEntailment(final Entailment goal,
final ReasonerProof evidence) throws ElkException {
final Set entailmentDone = new ArrayHashSet();
final Queue entailmentToDo = new LinkedList();
final Set tracingDone = new ArrayHashSet();
final Queue tracingToDo = new LinkedList();
if (entailmentDone.add(goal)) {
entailmentToDo.add(goal);
}
Entailment entailment;
while ((entailment = entailmentToDo.poll()) != null) {
for (final EntailmentInference inf : evidence
.getInferences(entailment)) {
final Conclusion reason = getReason(inf);
final List extends Entailment> premises = inf.getPremises();
final List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy