Search in sources :

Example 1 with AnalyserRuleSet

use of fr.lirmm.graphik.graal.rulesetanalyser.util.AnalyserRuleSet in project graal by graphik-team.

the class DefaultKnowledgeBase method analyse.

protected void analyse() {
    if (!this.isAnalysed) {
        this.analysedRuleSet = new AnalyserRuleSet(this.ruleset);
        Map<String, RuleSetProperty> properties = new HashMap<>();
        if (this.approach != Approach.REWRITING_ONLY) {
            properties.putAll(RuleSetPropertyHierarchy.generatePropertyMapSpecializationOf(FESProperty.instance()));
        }
        if (this.approach != Approach.SATURATION_ONLY) {
            properties.putAll(RuleSetPropertyHierarchy.generatePropertyMapSpecializationOf(FUSProperty.instance()));
        }
        this.analyse = new Analyser(analysedRuleSet);
        this.analyse.setProperties(properties.values());
        this.isAnalysed = true;
    }
}
Also used : HashMap(java.util.HashMap) Analyser(fr.lirmm.graphik.graal.rulesetanalyser.Analyser) RuleSetProperty(fr.lirmm.graphik.graal.rulesetanalyser.property.RuleSetProperty) AnalyserRuleSet(fr.lirmm.graphik.graal.rulesetanalyser.util.AnalyserRuleSet)

Example 2 with AnalyserRuleSet

use of fr.lirmm.graphik.graal.rulesetanalyser.util.AnalyserRuleSet in project graal by graphik-team.

the class Analyser method ruleProperties.

public List<Map<String, Integer>> ruleProperties() {
    if (this.ruleProperties == null) {
        this.ruleProperties = new LinkedList<Map<String, Integer>>();
        for (Rule r : this.ruleSet) {
            AnalyserRuleSet subAnalyser = new AnalyserRuleSet(r);
            this.ruleProperties.add(computeProperties(subAnalyser));
        }
    }
    return this.ruleProperties;
}
Also used : AnalyserRuleSet(fr.lirmm.graphik.graal.rulesetanalyser.util.AnalyserRuleSet) Rule(fr.lirmm.graphik.graal.api.core.Rule) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 3 with AnalyserRuleSet

use of fr.lirmm.graphik.graal.rulesetanalyser.util.AnalyserRuleSet in project graal by graphik-team.

the class MFAProperty method check.

/**
 */
@Override
public int check(AnalyserRuleSet ruleSet) {
    RuleSet R = translateToMFA(ruleSet);
    AtomSet A = Rules.criticalInstance(ruleSet);
    Chase chase = new ChaseWithGRD<AtomSet>(new DefaultGraphOfRuleDependencies(R), A, new DefaultRuleApplier<AtomSet>(new FrontierRestrictedChaseHaltingCondition()));
    DefaultConjunctiveQuery Q = new DefaultConjunctiveQuery();
    DefaultAtom q = new DefaultAtom(C);
    q.setTerm(0, FAKE);
    Q.getAtomSet().add(q);
    try {
        while (chase.hasNext()) {
            chase.next();
            if (SmartHomomorphism.instance().exist(Q, A)) {
                return -1;
            }
        }
    } catch (ChaseException e) {
        LOGGER.warn("An error occurs during the chase: ", e);
        return 0;
    } catch (HomomorphismException e) {
        LOGGER.warn("An error occurs during the homomorphism: ", e);
        return 0;
    }
    return 1;
}
Also used : AnalyserRuleSet(fr.lirmm.graphik.graal.rulesetanalyser.util.AnalyserRuleSet) RuleSet(fr.lirmm.graphik.graal.api.core.RuleSet) LinkedListRuleSet(fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet) DefaultConjunctiveQuery(fr.lirmm.graphik.graal.core.DefaultConjunctiveQuery) FrontierRestrictedChaseHaltingCondition(fr.lirmm.graphik.graal.forward_chaining.halting_condition.FrontierRestrictedChaseHaltingCondition) HomomorphismException(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException) DefaultGraphOfRuleDependencies(fr.lirmm.graphik.graal.core.grd.DefaultGraphOfRuleDependencies) AtomSet(fr.lirmm.graphik.graal.api.core.AtomSet) DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) ChaseWithGRD(fr.lirmm.graphik.graal.forward_chaining.ChaseWithGRD) ChaseException(fr.lirmm.graphik.graal.api.forward_chaining.ChaseException) Chase(fr.lirmm.graphik.graal.api.forward_chaining.Chase)

Example 4 with AnalyserRuleSet

use of fr.lirmm.graphik.graal.rulesetanalyser.util.AnalyserRuleSet in project graal by graphik-team.

the class MSAProperty method check.

@Override
public int check(AnalyserRuleSet ruleSet) {
    RuleSet R = translateToMSA(ruleSet);
    AtomSet A = Rules.criticalInstance(ruleSet);
    try {
        StaticChase.executeChase(A, R);
    } catch (ChaseException e) {
        LOGGER.warn("An error occurs during the chase: ", e);
        return 0;
    }
    DefaultConjunctiveQuery Q = new DefaultConjunctiveQuery();
    DefaultAtom q = new DefaultAtom(C);
    q.setTerm(0, FAKE);
    Q.getAtomSet().add(q);
    try {
        if (SmartHomomorphism.instance().exist(Q, A))
            return -1;
        return 1;
    } catch (HomomorphismException e) {
        LOGGER.warn("An error occurs during the homomorphism: ", e);
        return 0;
    }
}
Also used : AnalyserRuleSet(fr.lirmm.graphik.graal.rulesetanalyser.util.AnalyserRuleSet) RuleSet(fr.lirmm.graphik.graal.api.core.RuleSet) LinkedListRuleSet(fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet) DefaultConjunctiveQuery(fr.lirmm.graphik.graal.core.DefaultConjunctiveQuery) HomomorphismException(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException) AtomSet(fr.lirmm.graphik.graal.api.core.AtomSet) DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) ChaseException(fr.lirmm.graphik.graal.api.forward_chaining.ChaseException)

Aggregations

AnalyserRuleSet (fr.lirmm.graphik.graal.rulesetanalyser.util.AnalyserRuleSet)4 AtomSet (fr.lirmm.graphik.graal.api.core.AtomSet)2 RuleSet (fr.lirmm.graphik.graal.api.core.RuleSet)2 ChaseException (fr.lirmm.graphik.graal.api.forward_chaining.ChaseException)2 HomomorphismException (fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException)2 DefaultAtom (fr.lirmm.graphik.graal.core.DefaultAtom)2 DefaultConjunctiveQuery (fr.lirmm.graphik.graal.core.DefaultConjunctiveQuery)2 LinkedListRuleSet (fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet)2 Rule (fr.lirmm.graphik.graal.api.core.Rule)1 Chase (fr.lirmm.graphik.graal.api.forward_chaining.Chase)1 DefaultGraphOfRuleDependencies (fr.lirmm.graphik.graal.core.grd.DefaultGraphOfRuleDependencies)1 ChaseWithGRD (fr.lirmm.graphik.graal.forward_chaining.ChaseWithGRD)1 FrontierRestrictedChaseHaltingCondition (fr.lirmm.graphik.graal.forward_chaining.halting_condition.FrontierRestrictedChaseHaltingCondition)1 Analyser (fr.lirmm.graphik.graal.rulesetanalyser.Analyser)1 RuleSetProperty (fr.lirmm.graphik.graal.rulesetanalyser.property.RuleSetProperty)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1