Search in sources :

Example 16 with DefaultAtom

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

the class TripleStoreTest method simpleTest.

@Theory
public void simpleTest(AtomSet store) throws AtomSetException, IteratorException {
    Assume.assumeTrue(store instanceof TripleStore);
    Term t1 = DefaultTermFactory.instance().createConstant("http://to.to/b");
    Term t2 = DefaultTermFactory.instance().createConstant("http://to.to/a");
    Predicate p = new Predicate("http://to.to/p", 2);
    Atom atom1 = new DefaultAtom(p, t1, t2);
    store.add(atom1);
    int i = 0;
    for (CloseableIterator<Atom> it = store.iterator(); it.hasNext(); it.next()) {
        ++i;
    }
    Assert.assertEquals(1, i);
}
Also used : TripleStore(fr.lirmm.graphik.graal.api.store.TripleStore) DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) Term(fr.lirmm.graphik.graal.api.core.Term) DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) Atom(fr.lirmm.graphik.graal.api.core.Atom) Predicate(fr.lirmm.graphik.graal.api.core.Predicate) Theory(org.junit.experimental.theories.Theory)

Example 17 with DefaultAtom

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

the class RdbmsAtomIterator method hasNext.

// /////////////////////////////////////////////////////////////////////////
// METHODS
// /////////////////////////////////////////////////////////////////////////
@Override
public boolean hasNext() throws IteratorException {
    if (!this.hasNextCallDone) {
        this.hasNextCallDone = true;
        while (this.predicateIt.hasNext() && (this.atomIt == null || !this.atomIt.hasNext())) {
            Predicate p = predicateIt.next();
            List<Term> terms = new LinkedList<Term>();
            VariableGenerator gen = new DefaultVariableGenerator("X");
            for (int i = 0; i < p.getArity(); ++i) {
                terms.add(gen.getFreshSymbol());
            }
            InMemoryAtomSet atomSet = new LinkedListAtomSet();
            Atom atom = new DefaultAtom(p, terms);
            atomSet.add(atom);
            ConjunctiveQuery query = DefaultConjunctiveQueryFactory.instance().create(atomSet);
            SqlHomomorphism solver = SqlHomomorphism.instance();
            try {
                this.atomIt = new SubstitutionIterator2AtomIterator(atom, solver.execute(query, this.store));
            } catch (HomomorphismException e) {
                throw new IteratorException(e);
            }
        }
    }
    return this.atomIt != null && this.atomIt.hasNext();
}
Also used : DefaultVariableGenerator(fr.lirmm.graphik.graal.core.DefaultVariableGenerator) IteratorException(fr.lirmm.graphik.util.stream.IteratorException) HomomorphismException(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException) DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) SqlHomomorphism(fr.lirmm.graphik.graal.store.rdbms.homomorphism.SqlHomomorphism) Term(fr.lirmm.graphik.graal.api.core.Term) SubstitutionIterator2AtomIterator(fr.lirmm.graphik.graal.core.stream.SubstitutionIterator2AtomIterator) LinkedList(java.util.LinkedList) DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) Atom(fr.lirmm.graphik.graal.api.core.Atom) Predicate(fr.lirmm.graphik.graal.api.core.Predicate) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) DefaultVariableGenerator(fr.lirmm.graphik.graal.core.DefaultVariableGenerator) VariableGenerator(fr.lirmm.graphik.graal.api.core.VariableGenerator) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)

Example 18 with DefaultAtom

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

the class MFAProperty method translateToMFA.

public static RuleSet translateToMFA(Iterable<Rule> rules) {
    RuleSet R = new LinkedListRuleSet();
    for (Rule r : rules) {
        for (Rule r2 : translateRuleToMFA(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 19 with DefaultAtom

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

the class AtomTest method constructorTest.

@Test
public void constructorTest() {
    Predicate predicate = new Predicate("pred", 3);
    Term[] terms = new Term[3];
    terms[0] = new DefaultVariable("X");
    terms[1] = new DefaultConstant("a");
    terms[2] = new DefaultConstant("b");
    Atom atom = new DefaultAtom(predicate, Arrays.asList(terms));
    Assert.assertTrue(atom.getPredicate().equals(predicate));
    Assert.assertTrue(atom.getTerm(0).equals(terms[0]));
    Assert.assertTrue(atom.getTerm(1).equals(terms[1]));
    Assert.assertTrue(atom.getTerm(2).equals(terms[2]));
    Assert.assertTrue("The list eiuae ", atom.getTerms().equals(Arrays.asList(terms)));
}
Also used : DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) Term(fr.lirmm.graphik.graal.api.core.Term) DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) Atom(fr.lirmm.graphik.graal.api.core.Atom) Predicate(fr.lirmm.graphik.graal.api.core.Predicate) Test(org.junit.Test)

Example 20 with DefaultAtom

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

the class AtomTest method setterTest.

@Test
public void setterTest() {
    Predicate predicate = new Predicate("pred", 3);
    Term[] terms = new Term[3];
    terms[0] = new DefaultVariable("X");
    terms[1] = new DefaultConstant("a");
    terms[2] = new DefaultConstant("b");
    Atom atom = new DefaultAtom(predicate, Arrays.asList(terms));
    Term newTerm = new DefaultConstant("new");
    Predicate newPredicate = new Predicate("newPred", 3);
    atom.setPredicate(newPredicate);
    Assert.assertTrue(atom.getPredicate().equals(newPredicate));
    atom.setTerm(2, newTerm);
    Assert.assertTrue(atom.getTerm(2).equals(newTerm));
}
Also used : DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) Term(fr.lirmm.graphik.graal.api.core.Term) DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) Atom(fr.lirmm.graphik.graal.api.core.Atom) Predicate(fr.lirmm.graphik.graal.api.core.Predicate) Test(org.junit.Test)

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