use of fr.lirmm.graphik.graal.api.core.Predicate in project graal by graphik-team.
the class AbstractAtomSet method getPredicates.
@Override
public Set<Predicate> getPredicates() throws AtomSetException {
Set<Predicate> predicates = new HashSet<Predicate>();
CloseableIterator<Predicate> it = this.predicatesIterator();
try {
while (it.hasNext()) {
predicates.add(it.next());
}
} catch (Exception e) {
throw new AtomSetException(e);
}
return predicates;
}
use of fr.lirmm.graphik.graal.api.core.Predicate in project graal by graphik-team.
the class AbstractRewritingOperator method getUnifiableRules.
protected Collection<Rule> getUnifiableRules(CloseableIteratorWithoutException<Predicate> preds, IndexedByHeadPredicatesRuleSet ruleSet, RulesCompilation compilation) {
TreeSet<Rule> res = new TreeSet<Rule>(RuleOrder.instance());
TreeSet<Predicate> unifiablePreds = new TreeSet<Predicate>();
while (preds.hasNext()) {
unifiablePreds.addAll(compilation.getUnifiablePredicate(preds.next()));
}
for (Predicate pred : unifiablePreds) {
for (Rule r : ruleSet.getRulesByHeadPredicate(pred)) {
res.add(r);
}
}
return res;
}
use of fr.lirmm.graphik.graal.api.core.Predicate 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.api.core.Predicate 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.api.core.Predicate in project graal by graphik-team.
the class Neo4jStore method getPredicates.
@Override
public Set<Predicate> getPredicates() throws AtomSetException {
TreeSet<Predicate> set = new TreeSet<Predicate>();
CloseableIterator<Predicate> it = this.predicatesIterator();
try {
while (it.hasNext()) {
set.add(it.next());
}
} catch (IteratorException e) {
throw new AtomSetException("An errors occurs while iterating predicates", e);
}
return set;
}
Aggregations