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);
}
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();
}
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;
}
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)));
}
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));
}
Aggregations