Search in sources :

Example 1 with NeqPredicate

use of ai.grakn.graql.internal.reasoner.atom.predicate.NeqPredicate in project grakn by graknlabs.

the class ResolutionPlan method isValid.

/**
 * @return true if the plan doesn't lead to any non-ground neq predicate
 */
private boolean isValid() {
    // check for neq groundness
    Set<NeqPredicate> nonGroundPredicates = new HashSet<>();
    Set<Var> mappedVars = new HashSet<>();
    for (Atom atom : plan) {
        mappedVars.addAll(atom.getVarNames());
        atom.getPredicates(NeqPredicate.class).forEach(neq -> {
            // look for non-local non-ground predicates
            if (!mappedVars.containsAll(neq.getVarNames()) && !atom.getVarNames().containsAll(neq.getVarNames())) {
                nonGroundPredicates.add(neq);
            } else {
                // if this is ground for this atom but non-ground for another it is ground
                if (nonGroundPredicates.contains(neq))
                    nonGroundPredicates.remove(neq);
            }
        });
    }
    return nonGroundPredicates.isEmpty();
}
Also used : NeqPredicate(ai.grakn.graql.internal.reasoner.atom.predicate.NeqPredicate) Var(ai.grakn.graql.Var) Atom(ai.grakn.graql.internal.reasoner.atom.Atom) HashSet(java.util.HashSet)

Aggregations

Var (ai.grakn.graql.Var)1 Atom (ai.grakn.graql.internal.reasoner.atom.Atom)1 NeqPredicate (ai.grakn.graql.internal.reasoner.atom.predicate.NeqPredicate)1 HashSet (java.util.HashSet)1