Search in sources :

Example 46 with Predicate

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

the class MFAProperty method translateRuleToMFA.

public static List<Rule> translateRuleToMFA(final Rule r) {
    List<Rule> result = new LinkedList<Rule>();
    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);
    }
    result.add(r2);
    return result;
}
Also used : DefaultRule(fr.lirmm.graphik.graal.core.DefaultRule) 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 47 with Predicate

use of fr.lirmm.graphik.graal.api.core.Predicate 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 48 with Predicate

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

the class StoreTest method sizeTest.

@Theory
public void sizeTest(AtomSet atomset) throws ParseException, AtomSetException {
    Assume.assumeTrue(atomset instanceof Store);
    Store store = (Store) atomset;
    // given
    store.add(DlgpParser.parseAtom("<P>(b,a)."));
    store.add(DlgpParser.parseAtom("<P>(a,a)."));
    store.add(DlgpParser.parseAtom("<P>(b,b)."));
    store.add(DlgpParser.parseAtom("<P>(a,c)."));
    store.add(DlgpParser.parseAtom("<Q>(a,a)."));
    store.add(DlgpParser.parseAtom("<Q>(a,b)."));
    // when
    int sizeP = store.size(new Predicate("P", 2));
    int sizeQ = store.size(new Predicate("Q", 2));
    // then
    Assert.assertTrue(4 <= sizeP);
    Assert.assertTrue(2 <= sizeQ);
}
Also used : RdbmsStore(fr.lirmm.graphik.graal.store.rdbms.RdbmsStore) Store(fr.lirmm.graphik.graal.api.store.Store) TripleStore(fr.lirmm.graphik.graal.api.store.TripleStore) Predicate(fr.lirmm.graphik.graal.api.core.Predicate) Theory(org.junit.experimental.theories.Theory)

Example 49 with Predicate

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

the class StoreTest method termsByPredicatePosition.

@Theory
public void termsByPredicatePosition(AtomSet store) throws AtomSetException, IteratorException, ParseException {
    store.add(DlgpParser.parseAtom("<P>(d,a)."));
    store.add(DlgpParser.parseAtom("<P>(d,a)."));
    store.add(DlgpParser.parseAtom("<P>(d,b)."));
    store.add(DlgpParser.parseAtom("<P>(d,c)."));
    store.add(DlgpParser.parseAtom("<Q>(e,e)."));
    CloseableIterator<?> it = store.termsByPredicatePosition(new Predicate("P", 2), 1);
    int cpt = 0;
    while (it.hasNext()) {
        ++cpt;
        it.next();
    }
    Assert.assertEquals(3, cpt);
}
Also used : Predicate(fr.lirmm.graphik.graal.api.core.Predicate) Theory(org.junit.experimental.theories.Theory)

Example 50 with Predicate

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

Aggregations

Predicate (fr.lirmm.graphik.graal.api.core.Predicate)77 Atom (fr.lirmm.graphik.graal.api.core.Atom)35 DefaultAtom (fr.lirmm.graphik.graal.core.DefaultAtom)28 Term (fr.lirmm.graphik.graal.api.core.Term)27 Test (org.junit.Test)25 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)16 LinkedList (java.util.LinkedList)16 Theory (org.junit.experimental.theories.Theory)14 AtomSetException (fr.lirmm.graphik.graal.api.core.AtomSetException)9 Rule (fr.lirmm.graphik.graal.api.core.Rule)9 IteratorException (fr.lirmm.graphik.util.stream.IteratorException)9 LinkedListRuleSet (fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet)7 DefaultURI (fr.lirmm.graphik.util.DefaultURI)7 TreeSet (java.util.TreeSet)7 ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)6 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)6 RuleSet (fr.lirmm.graphik.graal.api.core.RuleSet)6 Variable (fr.lirmm.graphik.graal.api.core.Variable)6 ConversionException (fr.lirmm.graphik.util.stream.converter.ConversionException)6 Pair (org.apache.commons.lang3.tuple.Pair)6