Search in sources :

Example 26 with DefaultAtom

use of fr.lirmm.graphik.graal.core.DefaultAtom 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)

Example 27 with DefaultAtom

use of fr.lirmm.graphik.graal.core.DefaultAtom in project graal by graphik-team.

the class MSAProperty method translateRuleToMSA.

public static List<Rule> translateRuleToMSA(final Rule r) {
    List<Rule> result = new LinkedList<Rule>();
    Substitution s = buildMSASubstitution(r);
    DefaultRule r2 = new DefaultRule(r);
    /*r2.setBody(r.getBody());
		r2.setHead(r.getHead());*/
    for (Term yi : r2.getExistentials()) {
        Predicate Fir = GraalConstant.freshPredicate(1);
        DefaultAtom f = new DefaultAtom(Fir);
        f.setTerm(0, yi);
        r2.getHead().add(f);
        for (Term xj : r2.getFrontier()) {
            DefaultAtom ss = new DefaultAtom(S);
            ss.setTerm(0, xj);
            ss.setTerm(1, yi);
            r2.getHead().add(ss);
        }
        DefaultRule r3 = new DefaultRule();
        DefaultAtom f1 = new DefaultAtom(Fir);
        f1.setTerm(0, DefaultTermFactory.instance().createVariable("X1"));
        DefaultAtom f2 = new DefaultAtom(Fir);
        f2.setTerm(0, DefaultTermFactory.instance().createVariable("X2"));
        DefaultAtom d = new DefaultAtom(D);
        d.setTerm(0, DefaultTermFactory.instance().createVariable("X1"));
        d.setTerm(1, DefaultTermFactory.instance().createVariable("X2"));
        r3.getBody().add(f1);
        r3.getBody().add(d);
        r3.getBody().add(f2);
        DefaultAtom c = new DefaultAtom(C);
        c.setTerm(0, FAKE);
        r3.getHead().add(c);
        result.add(r3);
    }
    r2.setHead(s.createImageOf(r2.getHead()));
    result.add(r2);
    return result;
}
Also used : DefaultRule(fr.lirmm.graphik.graal.core.DefaultRule) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) TreeMapSubstitution(fr.lirmm.graphik.graal.core.TreeMapSubstitution) DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) Rule(fr.lirmm.graphik.graal.api.core.Rule) DefaultRule(fr.lirmm.graphik.graal.core.DefaultRule) Term(fr.lirmm.graphik.graal.api.core.Term) LinkedList(java.util.LinkedList) Predicate(fr.lirmm.graphik.graal.api.core.Predicate)

Example 28 with DefaultAtom

use of fr.lirmm.graphik.graal.core.DefaultAtom in project graal by graphik-team.

the class MSAProperty method translateToMSA.

public static RuleSet translateToMSA(Iterable<Rule> rules) {
    RuleSet R = new LinkedListRuleSet();
    for (Rule r : rules) {
        for (Rule r2 : translateRuleToMSA(r)) R.add(r2);
    }
    DefaultRule rule = new DefaultRule();
    Atom s = new DefaultAtom(S);
    s.setTerm(0, DefaultTermFactory.instance().createVariable("X1"));
    s.setTerm(1, DefaultTermFactory.instance().createVariable("X2"));
    Atom d = new DefaultAtom(D);
    d.setTerm(0, DefaultTermFactory.instance().createVariable("X1"));
    d.setTerm(1, DefaultTermFactory.instance().createVariable("X2"));
    rule.getBody().add(s);
    rule.getHead().add(d);
    R.add(rule);
    s = new DefaultAtom(S);
    d = new DefaultAtom(D);
    Atom d2 = new DefaultAtom(D);
    d.setTerm(0, DefaultTermFactory.instance().createVariable("X1"));
    d.setTerm(1, DefaultTermFactory.instance().createVariable("X2"));
    s.setTerm(0, DefaultTermFactory.instance().createVariable("X2"));
    s.setTerm(1, DefaultTermFactory.instance().createVariable("X3"));
    d2.setTerm(0, DefaultTermFactory.instance().createVariable("X1"));
    d2.setTerm(1, DefaultTermFactory.instance().createVariable("X3"));
    rule = new DefaultRule();
    rule.getBody().add(d);
    rule.getBody().add(s);
    rule.getHead().add(d2);
    R.add(rule);
    return R;
}
Also used : DefaultRule(fr.lirmm.graphik.graal.core.DefaultRule) AnalyserRuleSet(fr.lirmm.graphik.graal.rulesetanalyser.util.AnalyserRuleSet) RuleSet(fr.lirmm.graphik.graal.api.core.RuleSet) LinkedListRuleSet(fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet) DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) LinkedListRuleSet(fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet) Rule(fr.lirmm.graphik.graal.api.core.Rule) DefaultRule(fr.lirmm.graphik.graal.core.DefaultRule) DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) Atom(fr.lirmm.graphik.graal.api.core.Atom)

Example 29 with DefaultAtom

use of fr.lirmm.graphik.graal.core.DefaultAtom in project graal by graphik-team.

the class RDF4jUtils method statementToAtom.

public Atom statementToAtom(Statement stat) {
    Predicate predicate = valueToPredicate(stat.getPredicate());
    Term term0 = valueToTerm(stat.getSubject());
    Term term1 = valueToTerm(stat.getObject());
    return new DefaultAtom(predicate, term0, term1);
}
Also used : DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) Term(fr.lirmm.graphik.graal.api.core.Term) Predicate(fr.lirmm.graphik.graal.api.core.Predicate)

Example 30 with DefaultAtom

use of fr.lirmm.graphik.graal.core.DefaultAtom in project graal by graphik-team.

the class OWLAxiomParser method visit.

@Override
public Iterable<? extends Object> visit(OWLReflexiveObjectPropertyAxiom arg) {
    InMemoryAtomSet head = arg.getProperty().accept(propertyVisiotrXX);
    InMemoryAtomSet body = GraalUtils.createAtomSet(new DefaultAtom(Predicate.TOP, glueVarX));
    return Collections.singleton(DefaultRuleFactory.instance().create(body, head));
}
Also used : DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)

Aggregations

DefaultAtom (fr.lirmm.graphik.graal.core.DefaultAtom)45 Predicate (fr.lirmm.graphik.graal.api.core.Predicate)25 Term (fr.lirmm.graphik.graal.api.core.Term)25 Atom (fr.lirmm.graphik.graal.api.core.Atom)21 Test (org.junit.Test)20 LinkedList (java.util.LinkedList)17 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)12 LinkedListRuleSet (fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)7 Rule (fr.lirmm.graphik.graal.api.core.Rule)7 RuleSet (fr.lirmm.graphik.graal.api.core.RuleSet)7 Variable (fr.lirmm.graphik.graal.api.core.Variable)6 ConversionException (fr.lirmm.graphik.util.stream.converter.ConversionException)6 Constant (fr.lirmm.graphik.graal.api.core.Constant)5 DefaultURI (fr.lirmm.graphik.util.DefaultURI)5 Pair (org.apache.commons.lang3.tuple.Pair)5 DefaultRule (fr.lirmm.graphik.graal.core.DefaultRule)4 AnalyserRuleSet (fr.lirmm.graphik.graal.rulesetanalyser.util.AnalyserRuleSet)4 RulesCompilation (fr.lirmm.graphik.graal.api.core.RulesCompilation)3