Search in sources :

Example 1 with AtomSetException

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

the class TestUtil method getAtomSet.

public static AtomSet[] getAtomSet() {
    if (neo4jStore != null) {
        neo4jStore.close();
    }
    try {
        if (defaultRDBMSStore != null) {
            defaultRDBMSStore.close();
        }
        if (plainTableRDBMSStore != null) {
            plainTableRDBMSStore.close();
        }
        defaultRDBMSStore = new AdHocRdbmsStore(new HSQLDBDriver(DEFAULT_RDBMS_TEST, null));
        plainTableRDBMSStore = new NaturalRDBMSStore(new HSQLDBDriver(PLAIN_TABLE_RDBMS_TEST, null));
        defaultRDBMSStore.clear();
        plainTableRDBMSStore.clear();
        rm(NEO4J_TEST);
        neo4jStore = new Neo4jStore(NEO4J_TEST);
        if (sailStore != null) {
            sailStore.close();
        }
        try {
            sailStore = new RDF4jStore(new SailRepository(new MemoryStore()));
        } catch (AtomSetException e) {
            Assert.assertTrue("Error while creating SailStore", false);
        }
        return new AtomSet[] { new DefaultInMemoryGraphStore(), new LinkedListAtomSet(), defaultRDBMSStore, plainTableRDBMSStore, neo4jStore, sailStore };
    } catch (SQLException e) {
        throw new Error(e);
    } catch (AtomSetException e) {
        throw new Error(e);
    }
}
Also used : Neo4jStore(fr.lirmm.graphik.graal.store.gdb.Neo4jStore) RDF4jStore(fr.lirmm.graphik.graal.store.triplestore.rdf4j.RDF4jStore) SailRepository(org.eclipse.rdf4j.repository.sail.SailRepository) SQLException(java.sql.SQLException) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) AtomSet(fr.lirmm.graphik.graal.api.core.AtomSet) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) IOError(java.io.IOError) NaturalRDBMSStore(fr.lirmm.graphik.graal.store.rdbms.natural.NaturalRDBMSStore) AdHocRdbmsStore(fr.lirmm.graphik.graal.store.rdbms.adhoc.AdHocRdbmsStore) MemoryStore(org.eclipse.rdf4j.sail.memory.MemoryStore) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException) HSQLDBDriver(fr.lirmm.graphik.graal.store.rdbms.driver.HSQLDBDriver) DefaultInMemoryGraphStore(fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore)

Example 2 with AtomSetException

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

the class StatBootstrapper method exec.

// /////////////////////////////////////////////////////////////////////////
// 
// /////////////////////////////////////////////////////////////////////////
@Override
public CloseableIterator<Term> exec(final VarSharedData v, Collection<Atom> preAtoms, Collection<Atom> postAtoms, final AtomSet data, RulesCompilation rc) throws BacktrackException {
    if (!(data instanceof Store)) {
        return fallback.exec(v, preAtoms, postAtoms, data, rc);
    }
    Store store = (Store) data;
    Set<Term> terms = null;
    if (this.getProfiler() != null) {
        this.getProfiler().start("BootstrapTime");
        this.getProfiler().start("BootstrapTimeFirstPart");
    }
    Iterator<Atom> it;
    Collection<Constant> constants = null;
    Atom aa = null;
    it = postAtoms.iterator();
    while (it.hasNext()) {
        Atom a = it.next();
        if (constants == null || constants.isEmpty()) {
            constants = a.getConstants();
            aa = a;
        }
    }
    it = preAtoms.iterator();
    while (it.hasNext()) {
        Atom a = it.next();
        if (constants == null || constants.isEmpty()) {
            constants = a.getConstants();
            aa = a;
        }
    }
    try {
        if (constants != null && !constants.isEmpty()) {
            terms = new HashSet<Term>();
            for (Pair<Atom, Substitution> im : rc.getRewritingOf(aa)) {
                int pos = im.getLeft().indexOf(im.getRight().createImageOf(v.value));
                CloseableIterator<Atom> match = data.match(im.getLeft());
                while (match.hasNext()) {
                    terms.add(match.next().getTerm(pos));
                }
            }
        }
        if (this.getProfiler() != null) {
            this.getProfiler().stop("BootstrapTimeFirstPart");
        }
        if (terms == null) {
            Atom a = null, tmp;
            double probaA = 1.1;
            it = postAtoms.iterator();
            while (it.hasNext()) {
                tmp = it.next();
                double p = ProbaUtils.computeProba(tmp, store, rc);
                if (p < probaA) {
                    a = tmp;
                    p = probaA;
                }
            }
            it = preAtoms.iterator();
            while (it.hasNext()) {
                tmp = it.next();
                double p = ProbaUtils.computeProba(tmp, store, rc);
                if (p < probaA) {
                    a = tmp;
                    p = probaA;
                }
            }
            terms = BootstrapperUtils.computeCandidatesOverRewritings(a, v, data, rc);
        }
        if (this.getProfiler() != null) {
            this.getProfiler().stop("BootstrapTime");
        }
        if (terms == null) {
            return data.termsIterator();
        } else {
            return new CloseableIteratorAdapter<Term>(terms.iterator());
        }
    } catch (AtomSetException e) {
        throw new BacktrackException(e);
    } catch (IteratorException e) {
        throw new BacktrackException(e);
    }
}
Also used : IteratorException(fr.lirmm.graphik.util.stream.IteratorException) Constant(fr.lirmm.graphik.graal.api.core.Constant) Store(fr.lirmm.graphik.graal.api.store.Store) Term(fr.lirmm.graphik.graal.api.core.Term) CloseableIteratorAdapter(fr.lirmm.graphik.util.stream.CloseableIteratorAdapter) Atom(fr.lirmm.graphik.graal.api.core.Atom) BacktrackException(fr.lirmm.graphik.graal.homomorphism.BacktrackException) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException)

Example 3 with AtomSetException

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

the class AbstractSubstitution method apply.

@Override
public void apply(AtomSet src, AtomSet dest) throws AtomSetException {
    CloseableIterator<Atom> it = src.iterator();
    try {
        while (it.hasNext()) {
            Atom a = it.next();
            dest.add(this.createImageOf(a));
        }
    } catch (IteratorException e) {
        throw new AtomSetException("Error during the iteration over src");
    }
}
Also used : IteratorException(fr.lirmm.graphik.util.stream.IteratorException) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException) Atom(fr.lirmm.graphik.graal.api.core.Atom)

Example 4 with AtomSetException

use of fr.lirmm.graphik.graal.api.core.AtomSetException 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 5 with AtomSetException

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

the class NaturalRDBMSStore method getPredicateTableIfExist.

@Override
protected DBTable getPredicateTableIfExist(Predicate predicate) throws AtomSetException {
    try {
        String tableName = predicate.getIdentifier().toString();
        DBTable table = this.getDriver().getTable(tableName);
        if (table != null && predicate.getArity() == table.getColumns().size()) {
            return table;
        } else {
            return null;
        }
    } catch (SQLException e) {
        throw new AtomSetException(e);
    }
}
Also used : DBTable(fr.lirmm.graphik.graal.store.rdbms.util.DBTable) SQLException(java.sql.SQLException) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException)

Aggregations

AtomSetException (fr.lirmm.graphik.graal.api.core.AtomSetException)69 IteratorException (fr.lirmm.graphik.util.stream.IteratorException)26 SQLException (java.sql.SQLException)26 Atom (fr.lirmm.graphik.graal.api.core.Atom)25 Term (fr.lirmm.graphik.graal.api.core.Term)23 HomomorphismException (fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException)12 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)11 Statement (java.sql.Statement)11 DBTable (fr.lirmm.graphik.graal.store.rdbms.util.DBTable)10 Predicate (fr.lirmm.graphik.graal.api.core.Predicate)9 BacktrackException (fr.lirmm.graphik.graal.homomorphism.BacktrackException)9 ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)7 TreeSet (java.util.TreeSet)7 SQLQuery (fr.lirmm.graphik.graal.store.rdbms.util.SQLQuery)6 CloseableIteratorAdapter (fr.lirmm.graphik.util.stream.CloseableIteratorAdapter)6 RuleApplicationException (fr.lirmm.graphik.graal.api.forward_chaining.RuleApplicationException)5 LinkedListAtomSet (fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet)5 TreeMap (java.util.TreeMap)5 AtomSet (fr.lirmm.graphik.graal.api.core.AtomSet)4 Variable (fr.lirmm.graphik.graal.api.core.Variable)4