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