use of com.vaticle.typedb.core.test.behaviour.reasoner.verification.CorrectnessVerifier.SoundnessException in project grakn by graknlabs.
the class SoundnessVerifier method verifyExplanation.
private void verifyExplanation(Explanation explanation) {
ConceptMap recordedWhen = mapInferredConcepts(explanation.conditionAnswer());
Optional<ConceptMap> recordedThen = materialiser.conditionMaterialisations(explanation.rule(), recordedWhen).map(materialisation -> materialisation.boundConclusion().pattern().bounds());
if (recordedThen.isPresent()) {
// Update the inferred variables mapping between the two reasoners
assert recordedThen.get().concepts().keySet().equals(explanation.conclusionAnswer().concepts().keySet());
recordedThen.get().concepts().forEach((var, recordedConcept) -> {
Concept inferredConcept = explanation.conclusionAnswer().concepts().get(var);
if (inferredConceptMapping.containsKey(inferredConcept)) {
// Check that the mapping stored is one-to-one
assert inferredConceptMapping.get(inferredConcept).equals(recordedConcept);
} else {
inferredConceptMapping.put(inferredConcept, recordedConcept);
}
});
} else {
throw new SoundnessException(String.format("Soundness testing found an answer within an explanation that " + "should not be present for rule \"%s\"" + ".\nAnswer:\n%s\nIncorrectly derived from " + "condition:\n%s", explanation.rule().getLabel(), explanation.conclusionAnswer(), explanation.conditionAnswer()));
}
}
Aggregations