use of fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException in project graal by graphik-team.
the class FixedOrderScheduler method execute.
// /////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS
// /////////////////////////////////////////////////////////////////////////
@Override
public VarSharedData[] execute(InMemoryAtomSet h, List<Term> ans, AtomSet data, RulesCompilation rc) throws HomomorphismException {
Set<Variable> terms = h.getVariables();
VarSharedData[] vars = new VarSharedData[terms.size() + 2];
int level = 0;
vars[level] = new VarSharedData(level);
Set<Term> alreadyAffected = new TreeSet<Term>();
for (Variable v : this.order) {
if (!terms.contains(v)) {
throw new HomomorphismException("Try to schedule a variable which is not in the query :" + v);
}
if (alreadyAffected.contains(v)) {
throw new HomomorphismException("There is two occurences of the same variable in the specified order.");
}
++level;
vars[level] = new VarSharedData(level);
vars[level].value = v;
alreadyAffected.add(v);
}
terms.removeAll(alreadyAffected);
if (!terms.isEmpty()) {
throw new HomomorphismException("Some variables of the query are not scheduled :" + terms);
}
++level;
vars[level] = new VarSharedData(level);
vars[level].previousLevel = level - 1;
return vars;
}
use of fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException in project graal by graphik-team.
the class Utils method isMoreGeneralThan.
/**
* Returns true if AtomSet h is more general than AtomSet f, and mark all
* the atom of h if h is a marked fact; else return false
*
* @param h
* @param f
* @param compilation
* @return true if AtomSet h is more general than AtomSet f, and mark all
* the atom of h if h is a marked fact, false otherwise.
*/
public static boolean isMoreGeneralThan(InMemoryAtomSet h, InMemoryAtomSet f, RulesCompilation compilation) {
boolean moreGen = false;
if (testInclu && AtomSetUtils.contains(f, h)) {
moreGen = true;
} else {
try {
InMemoryAtomSet fCopy = Utils.getSafeCopy(f);
moreGen = PureHomomorphism.instance().exist(h, fCopy, compilation);
} catch (HomomorphismException e) {
}
}
return moreGen;
}
use of fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException in project graal by graphik-team.
the class NaturalRDBMSStore method match.
// /////////////////////////////////////////////////////////////////////////
// METHODS
// /////////////////////////////////////////////////////////////////////////
@Override
public CloseableIterator<Atom> match(Atom atom) throws AtomSetException {
if (!this.check(atom)) {
return Iterators.<Atom>emptyIterator();
}
ConjunctiveQuery query = DefaultConjunctiveQueryFactory.instance().create(new LinkedListAtomSet(atom));
SqlHomomorphism solver = SqlHomomorphism.instance();
try {
return new SubstitutionIterator2AtomIterator(atom, solver.execute(query, this));
} catch (HomomorphismException e) {
throw new AtomSetException(e);
}
}
use of fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException in project graal by graphik-team.
the class RdbmsAtomIterator method hasNext.
// /////////////////////////////////////////////////////////////////////////
// METHODS
// /////////////////////////////////////////////////////////////////////////
@Override
public boolean hasNext() throws IteratorException {
if (!this.hasNextCallDone) {
this.hasNextCallDone = true;
while (this.predicateIt.hasNext() && (this.atomIt == null || !this.atomIt.hasNext())) {
Predicate p = predicateIt.next();
List<Term> terms = new LinkedList<Term>();
VariableGenerator gen = new DefaultVariableGenerator("X");
for (int i = 0; i < p.getArity(); ++i) {
terms.add(gen.getFreshSymbol());
}
InMemoryAtomSet atomSet = new LinkedListAtomSet();
Atom atom = new DefaultAtom(p, terms);
atomSet.add(atom);
ConjunctiveQuery query = DefaultConjunctiveQueryFactory.instance().create(atomSet);
SqlHomomorphism solver = SqlHomomorphism.instance();
try {
this.atomIt = new SubstitutionIterator2AtomIterator(atom, solver.execute(query, this.store));
} catch (HomomorphismException e) {
throw new IteratorException(e);
}
}
}
return this.atomIt != null && this.atomIt.hasNext();
}
use of fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException in project graal by graphik-team.
the class SqlUCQHomomorphism method preprocessing.
private static SQLQuery preprocessing(UnionOfConjunctiveQueries queries, RdbmsStore store) throws HomomorphismException {
boolean emptyQuery = false;
CloseableIterator<ConjunctiveQuery> it = queries.iterator();
StringBuilder ucq = new StringBuilder();
RdbmsConjunctiveQueryTranslator translator = store.getConjunctiveQueryTranslator();
try {
if (!it.hasNext())
return SQLQuery.hasSchemaErrorInstance();
while (it.hasNext()) {
SQLQuery query = translator.translate(it.next());
if (!query.hasSchemaError()) {
if (ucq.length() > 0)
ucq.append("\nUNION\n");
ucq.append(query.toString());
} else if (query.isEmpty()) {
emptyQuery = true;
}
}
} catch (Exception e) {
throw new HomomorphismException("Error during query translation to SQL", e);
}
SQLQuery query = new SQLQuery(ucq.toString());
if (query.isEmpty() && !emptyQuery) {
return SQLQuery.hasSchemaErrorInstance();
}
return query;
}
Aggregations