use of fr.lirmm.graphik.util.stream.IteratorException in project graal by graphik-team.
the class SccChase method next.
// /////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS
// /////////////////////////////////////////////////////////////////////////
@Override
public void next() throws ChaseException {
++this.level;
tmpAtom = new LinkedList<Atom>();
for (Integer scc : layers[level]) {
Set<Rule> component = this.sccg.getComponent(scc);
GraphOfRuleDependencies subGraph = this.grd.getSubGraph(component);
if (component.size() == 1 && !subGraph.hasCircuit()) {
try {
CloseableIterator<Atom> it = this.getRuleApplier().delegatedApply(component.iterator().next(), atomSet);
while (it.hasNext()) {
tmpAtom.add(it.next());
}
it.close();
} catch (RuleApplicationException e) {
throw new ChaseException("", e);
} catch (IteratorException e) {
throw new ChaseException("", e);
}
} else {
Chase chase = new ChaseWithGRD<T>(subGraph, atomSet, this.getRuleApplier());
chase.execute();
}
}
try {
atomSet.addAll(new CloseableIteratorAdapter<Atom>(tmpAtom.iterator()));
} catch (AtomSetException e) {
throw new ChaseException("", e);
}
}
use of fr.lirmm.graphik.util.stream.IteratorException in project graal by graphik-team.
the class FrontierRestrictedChaseHaltingCondition method apply.
@Override
public CloseableIterator<Atom> apply(Rule rule, Substitution substitution, AtomSet data) throws HomomorphismFactoryException, HomomorphismException {
Set<Term> fixedVars = substitution.getValues();
if (ruleIndex.get(rule) == null) {
ruleIndex.put(rule, _currentRuleIndex++);
}
final int index = ruleIndex.get(rule).intValue();
StringBuilder frontierSb = new StringBuilder();
SortedSet<Variable> frontierSet = new TreeSet<Variable>(rule.getFrontier());
for (Term t : frontierSet) {
frontierSb.append("_");
frontierSb.append(t.getLabel());
frontierSb.append(substitution.createImageOf(t).getLabel());
}
String frontier = frontierSb.toString();
for (Variable t : rule.getExistentials()) {
substitution.put(t, DefaultTermFactory.instance().createConstant("f_" + index + "_" + t.getIdentifier() + frontier));
}
InMemoryAtomSet newFacts = substitution.createImageOf(rule.getHead());
ConjunctiveQuery query = new ConjunctiveQueryWithFixedVariables(newFacts, fixedVars);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Fixed Query:" + query);
}
try {
if (SmartHomomorphism.instance().execute(query, data).hasNext()) {
return new CloseableIteratorAdapter<Atom>(Collections.<Atom>emptyList().iterator());
}
} catch (IteratorException e) {
throw new HomomorphismException("An errors occurs while iterating results", e);
}
return newFacts.iterator();
}
use of fr.lirmm.graphik.util.stream.IteratorException in project graal by graphik-team.
the class DefaultUCQHomomorphism method exist.
@Override
public boolean exist(UnionOfConjunctiveQueries q, AtomSet a) throws HomomorphismException {
try {
CloseableIterator<Substitution> execute = this.execute(q, a);
boolean res = execute.hasNext();
execute.close();
return res;
} catch (IteratorException e) {
throw new HomomorphismException(e);
}
}
use of fr.lirmm.graphik.util.stream.IteratorException 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.util.stream.IteratorException 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();
}
Aggregations