Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 585ad5e2 authored by Federico Ulliana's avatar Federico Ulliana
Browse files

added example of refactoring for StaticGRIBasedExplainer

parent 1ad6ae31
No related branches found
No related tags found
1 merge request!68Resolve "add explanation module"
Pipeline #1115608 failed
package fr.boreal.explanation.explainers;
import fr.boreal.explanation.GRI.dynamicProcessing.RELTracer;
import fr.boreal.explanation.GRI.staticProcessing.GRIBuilder;
import fr.boreal.explanation.ruleFactories.StaticGRIRuleTransformer;
import fr.boreal.explanation.solving_enumerating.gmus_processors.FactSupportGMUSProcessor;
import fr.boreal.model.kb.api.FactBase;
import fr.boreal.model.kb.api.KnowledgeBase;
import fr.boreal.model.logicalElements.api.Atom;
import org.apache.commons.lang3.tuple.Pair;
import java.util.Set;
public abstract class AbstractStaticGRIBasedExplainer {
/*
* A KB whose factbase will contain the GRI and whose rulebase the rules needed to compute the GRI
*/
protected KnowledgeBase griKB;
/*
* The factory for transforming rules
*/
StaticGRIRuleTransformer ruleTransformer = StaticGRIRuleTransformer.instance();
/**
* Sets the initial KB and compute the GRI
*
* @param kb the current kb
*/
public AbstractStaticGRIBasedExplainer(KnowledgeBase kb) {
Pair<KnowledgeBase, StaticGRIRuleTransformer> pair = GRIBuilder.buildGRI(kb);
this.griKB = pair.getLeft();
}
public Set<KnowledgeBase> explain(Atom query) {
RELTracer tracer = new RELTracer();
FactBase filteredGRI = tracer.computeQueryRelevant(griKB, ruleTransformer, query);
FactSupportGMUSProcessor gmusProcessor = getGMUSProcessor();
return gmusProcessor.computeExplanations(filteredGRI, ruleTransformer, query);
}
abstract FactSupportGMUSProcessor getGMUSProcessor();
}
package fr.boreal.explanation.explainers;
import fr.boreal.explanation.GRI.dynamicProcessing.RELTracer;
import fr.boreal.explanation.GRI.staticProcessing.GRIBuilder;
import fr.boreal.explanation.api.AtomicQueryExplanationEnumerator;
import fr.boreal.explanation.ruleFactories.StaticGRIRuleTransformer;
import fr.boreal.explanation.solving_enumerating.gmus_processors.FactSupportGMUSProcessor;
import fr.boreal.model.kb.api.FactBase;
import fr.boreal.model.kb.api.KnowledgeBase;
import fr.boreal.model.logicalElements.api.Atom;
import org.apache.commons.lang3.tuple.Pair;
import java.util.Set;
/**
* Computes kb-support explanations for a knowledge base and a ground atomic query
*/
public class NewFactSupportExplainer extends AbstractStaticGRIBasedExplainer implements AtomicQueryExplanationEnumerator<KnowledgeBase> {
KnowledgeBase gri;
StaticGRIRuleTransformer ruleTransformer;
/**
* Sets the initial KB and compute the GRI
*
* @param kb the current kb
*/
public NewFactSupportExplainer(KnowledgeBase kb) {
super(kb);
}
@Override
FactSupportGMUSProcessor getGMUSProcessor() {
return new FactSupportGMUSProcessor();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment