use of fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException in project graal by graphik-team.
the class RuleApplierIterator method hasNext.
@Override
public boolean hasNext() throws IteratorException {
if (!this.hasNextCallDone) {
this.hasNextCallDone = true;
if (this.localIt != null && !this.localIt.hasNext()) {
this.localIt.close();
this.localIt = null;
}
while ((this.localIt == null || !this.localIt.hasNext()) && this.substitutionIt.hasNext()) {
try {
localIt = haltingCondition.apply(rule, substitutionIt.next(), atomset);
} catch (HomomorphismFactoryException e) {
throw new IteratorException("Error during rule application", e);
} catch (HomomorphismException e) {
throw new IteratorException("Error during rule application", e);
}
}
}
return this.localIt != null && this.localIt.hasNext();
}
use of fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException in project graal by graphik-team.
the class RecursiveBacktrackHomomorphism method execute.
// /////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS
// /////////////////////////////////////////////////////////////////////////
@Override
public CloseableIterator<Substitution> execute(ConjunctiveQuery query, AtomSet facts) throws HomomorphismException {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace(query.toString());
}
if (profiler != null) {
profiler.start("preprocessing time");
}
Pair<ConjunctiveQuery, Substitution> pair = EqualityUtils.processEquality(query);
List<Variable> orderedVars = order(pair.getLeft().getAtomSet().getVariables());
Collection<Atom>[] queryAtomRanked = getAtomRank(pair.getLeft().getAtomSet(), orderedVars);
if (profiler != null) {
profiler.stop("preprocessing time");
}
try {
this.domain = facts.getTerms();
if (profiler != null) {
profiler.start("backtracking time");
}
CloseableIterator<Substitution> results;
if (isHomomorphism(queryAtomRanked[0], facts, new HashMapSubstitution())) {
results = new CloseableIteratorAdapter<Substitution>(homomorphism(pair.getLeft(), queryAtomRanked, facts, new HashMapSubstitution(), orderedVars, 1).iterator());
} else {
// return false
results = new CloseableIteratorAdapter<Substitution>(Collections.<Substitution>emptyList().iterator());
}
if (profiler != null) {
profiler.stop("backtracking time");
}
if (!pair.getRight().getTerms().isEmpty()) {
results = new ConverterCloseableIterator<Substitution, Substitution>(results, new EqualityHandlerConverter(pair.getRight()));
}
return results;
} catch (Exception e) {
throw new HomomorphismException(e.getMessage(), e);
}
}
use of fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException in project graal by graphik-team.
the class UnionConjunctiveQueriesSubstitutionIterator method hasNext.
@Override
public boolean hasNext() throws IteratorException {
if (!this.hasNextCallDone) {
this.hasNextCallDone = true;
if (this.tmpIt != null && !this.tmpIt.hasNext()) {
this.tmpIt.close();
this.tmpIt = null;
this.getProfiler().stop("SubQuery" + i++);
}
while ((this.tmpIt == null || !this.tmpIt.hasNext()) && this.cqueryIterator.hasNext()) {
ConjunctiveQuery q = this.cqueryIterator.next();
this.getProfiler().start("SubQuery" + i);
try {
if (this.homomorphism == null) {
this.tmpIt = SmartHomomorphism.instance().execute(q, this.atomSet, this.compilation);
} else {
if (this.compilation != null && !(this.compilation instanceof NoCompilation)) {
if (this.homomorphism instanceof HomomorphismWithCompilation) {
this.tmpIt = ((HomomorphismWithCompilation<ConjunctiveQuery, AtomSet>) this.homomorphism).execute(q, this.atomSet, this.compilation);
} else {
throw new IteratorException("There is a compilation and selected homomorphism can't handle it : " + this.homomorphism.getClass());
}
} else {
this.tmpIt = this.homomorphism.execute(q, this.atomSet);
}
}
if (this.isBooleanQuery && this.tmpIt.hasNext()) {
this.cqueryIterator.close();
}
} catch (HomomorphismException e) {
return false;
}
}
}
return this.tmpIt != null && this.tmpIt.hasNext();
}
use of fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException in project graal by graphik-team.
the class AtomicQueryHomomorphism method execute.
@Override
public CloseableIterator<Substitution> execute(ConjunctiveQuery q, AtomSet a, RulesCompilation rc) throws HomomorphismException {
try {
List<CloseableIterator<Substitution>> iteratorsList = new LinkedList<CloseableIterator<Substitution>>();
Atom atom = q.getAtomSet().iterator().next();
for (Pair<Atom, Substitution> im : rc.getRewritingOf(atom)) {
iteratorsList.add(new ConverterCloseableIterator<Atom, Substitution>(a.match(im.getLeft()), new Atom2SubstitutionConverter(im.getLeft(), q.getAnswerVariables(), im.getRight())));
}
return new CloseableIteratorAggregator<Substitution>(new CloseableIteratorAdapter<CloseableIterator<Substitution>>(iteratorsList.iterator()));
} catch (AtomSetException e) {
throw new HomomorphismException(e);
}
}
use of fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException in project graal by graphik-team.
the class AbstractHomomorphism method exist.
// /////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS
// /////////////////////////////////////////////////////////////////////////
@Override
public boolean exist(T1 q, T2 a) throws HomomorphismException {
CloseableIterator<Substitution> results = this.execute(q, a);
boolean val;
try {
val = results.hasNext();
} catch (IteratorException e) {
throw new HomomorphismException(e);
}
results.close();
return val;
}
Aggregations