Search in sources :

Example 11 with Predicate

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;
}
Also used : AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException) Predicate(fr.lirmm.graphik.graal.api.core.Predicate) HashSet(java.util.HashSet)

Example 12 with Predicate

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;
}
Also used : TreeSet(java.util.TreeSet) AtomicHeadRule(fr.lirmm.graphik.graal.core.unifier.AtomicHeadRule) Rule(fr.lirmm.graphik.graal.api.core.Rule) Predicate(fr.lirmm.graphik.graal.api.core.Predicate)

Example 13 with Predicate

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);
}
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 14 with Predicate

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();
}
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 15 with Predicate

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;
}
Also used : IteratorException(fr.lirmm.graphik.util.stream.IteratorException) TreeSet(java.util.TreeSet) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException) 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