Search in sources :

Example 1 with HomomorphismException

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;
}
Also used : Variable(fr.lirmm.graphik.graal.api.core.Variable) HomomorphismException(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException) TreeSet(java.util.TreeSet) Term(fr.lirmm.graphik.graal.api.core.Term) VarSharedData(fr.lirmm.graphik.graal.homomorphism.VarSharedData)

Example 2 with HomomorphismException

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;
}
Also used : HomomorphismException(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)

Example 3 with HomomorphismException

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);
    }
}
Also used : HomomorphismException(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) SqlHomomorphism(fr.lirmm.graphik.graal.store.rdbms.homomorphism.SqlHomomorphism) SubstitutionIterator2AtomIterator(fr.lirmm.graphik.graal.core.stream.SubstitutionIterator2AtomIterator) Atom(fr.lirmm.graphik.graal.api.core.Atom) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)

Example 4 with HomomorphismException

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();
}
Also used : DefaultVariableGenerator(fr.lirmm.graphik.graal.core.DefaultVariableGenerator) IteratorException(fr.lirmm.graphik.util.stream.IteratorException) HomomorphismException(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException) DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) SqlHomomorphism(fr.lirmm.graphik.graal.store.rdbms.homomorphism.SqlHomomorphism) Term(fr.lirmm.graphik.graal.api.core.Term) SubstitutionIterator2AtomIterator(fr.lirmm.graphik.graal.core.stream.SubstitutionIterator2AtomIterator) LinkedList(java.util.LinkedList) DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) Atom(fr.lirmm.graphik.graal.api.core.Atom) Predicate(fr.lirmm.graphik.graal.api.core.Predicate) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) DefaultVariableGenerator(fr.lirmm.graphik.graal.core.DefaultVariableGenerator) VariableGenerator(fr.lirmm.graphik.graal.api.core.VariableGenerator) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)

Example 5 with HomomorphismException

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;
}
Also used : HomomorphismException(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException) RdbmsConjunctiveQueryTranslator(fr.lirmm.graphik.graal.store.rdbms.RdbmsConjunctiveQueryTranslator) SQLQuery(fr.lirmm.graphik.graal.store.rdbms.util.SQLQuery) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery) HomomorphismException(fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException)

Aggregations

HomomorphismException (fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException)35 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)17 ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)15 Atom (fr.lirmm.graphik.graal.api.core.Atom)14 IteratorException (fr.lirmm.graphik.util.stream.IteratorException)13 AtomSetException (fr.lirmm.graphik.graal.api.core.AtomSetException)11 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)8 Variable (fr.lirmm.graphik.graal.api.core.Variable)8 Term (fr.lirmm.graphik.graal.api.core.Term)7 LinkedListAtomSet (fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet)7 LinkedList (java.util.LinkedList)6 ChaseException (fr.lirmm.graphik.graal.api.forward_chaining.ChaseException)5 RuleApplicationException (fr.lirmm.graphik.graal.api.forward_chaining.RuleApplicationException)5 SubstitutionIterator2AtomIterator (fr.lirmm.graphik.graal.core.stream.SubstitutionIterator2AtomIterator)5 SqlHomomorphism (fr.lirmm.graphik.graal.store.rdbms.homomorphism.SqlHomomorphism)5 RuleSet (fr.lirmm.graphik.graal.api.core.RuleSet)4 HomomorphismFactoryException (fr.lirmm.graphik.graal.api.homomorphism.HomomorphismFactoryException)4 HashMapSubstitution (fr.lirmm.graphik.graal.core.HashMapSubstitution)4 LinkedListRuleSet (fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet)4 AnalyserRuleSet (fr.lirmm.graphik.graal.rulesetanalyser.util.AnalyserRuleSet)4