Search in sources :

Example 16 with Predicate

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

the class RDF4jStore 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 error occurs during iteration over 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)

Example 17 with Predicate

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

the class AbstractRdbmsStore method clear.

@Override
public void clear() throws AtomSetException {
    CloseableIterator<Predicate> it = this.predicatesIterator();
    Statement stat = null;
    try {
        try {
            stat = this.createStatement();
            while (it.hasNext()) {
                Predicate p = it.next();
                this.removePredicate(stat, p);
            }
            this.getConnection().commit();
        } catch (IteratorException e) {
            this.getConnection().rollback();
            throw new AtomSetException(e);
        } catch (SQLException e) {
            this.getConnection().rollback();
            throw new AtomSetException(e);
        } finally {
            if (stat != null)
                stat.close();
        }
    } catch (SQLException e) {
        throw new AtomSetException(e);
    }
}
Also used : IteratorException(fr.lirmm.graphik.util.stream.IteratorException) SQLException(java.sql.SQLException) Statement(java.sql.Statement) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException) Predicate(fr.lirmm.graphik.graal.api.core.Predicate)

Example 18 with Predicate

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

the class StoreTest method removeAllTest.

@Theory
public void removeAllTest(AtomSet store) throws AtomSetException, IteratorException {
    // 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
    try {
        store.removeAll(DlgpParser.parseAtomSet("<P>(a,c), <Q>(a,a)."));
    } catch (MethodNotImplementedError e) {
        return;
    }
    // then
    Assert.assertFalse(store.contains(DlgpParser.parseAtom("<P>(a,c).")));
    Assert.assertFalse(store.contains(DlgpParser.parseAtom("<Q>(a,a).")));
    Assert.assertEquals(3, Iterators.count(store.atomsByPredicate(new Predicate("P", 2))));
    Assert.assertEquals(1, Iterators.count(store.atomsByPredicate(new Predicate("Q", 2))));
}
Also used : MethodNotImplementedError(fr.lirmm.graphik.util.MethodNotImplementedError) Predicate(fr.lirmm.graphik.graal.api.core.Predicate) Theory(org.junit.experimental.theories.Theory)

Example 19 with Predicate

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

the class StoreTest method removeTest.

@Theory
public void removeTest(AtomSet store) throws AtomSetException, IteratorException {
    // 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
    try {
        store.remove(DlgpParser.parseAtom("<P>(a,c)."));
    } catch (MethodNotImplementedError e) {
        return;
    }
    // then
    Assert.assertFalse(store.contains(DlgpParser.parseAtom("<P>(a,c).")));
    Assert.assertEquals(3, Iterators.count(store.atomsByPredicate(new Predicate("P", 2))));
    Assert.assertEquals(2, Iterators.count(store.atomsByPredicate(new Predicate("Q", 2))));
}
Also used : MethodNotImplementedError(fr.lirmm.graphik.util.MethodNotImplementedError) Predicate(fr.lirmm.graphik.graal.api.core.Predicate) Theory(org.junit.experimental.theories.Theory)

Example 20 with Predicate

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

the class StoreTest method caseSensitivityTest.

@Theory
public void caseSensitivityTest(AtomSet store) throws AtomSetException, IteratorException, ParseException, SQLException {
    Assume.assumeTrue(!(store instanceof RdbmsStore) || ((RdbmsStore) store).getDriver().isCaseSensitive());
    Atom toAdd = DlgpParser.parseAtom("<P>(a,b).");
    Atom toCheck = DlgpParser.parseAtom("<p>(a,b).");
    Predicate predicateToCheck = new Predicate("p", 2);
    store.add(toAdd);
    Assert.assertTrue(store.contains(toAdd));
    Assert.assertFalse(store.contains(toCheck));
    CloseableIterator<?> it = store.termsByPredicatePosition(predicateToCheck, 0);
    Assert.assertFalse(it.hasNext());
    it = store.atomsByPredicate(predicateToCheck);
    Assert.assertFalse(it.hasNext());
    it = store.match(DlgpParser.parseAtom("<p>(X,Y)."));
    Assert.assertFalse(it.hasNext());
}
Also used : RdbmsStore(fr.lirmm.graphik.graal.store.rdbms.RdbmsStore) Atom(fr.lirmm.graphik.graal.api.core.Atom) Predicate(fr.lirmm.graphik.graal.api.core.Predicate) Theory(org.junit.experimental.theories.Theory)

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