Search in sources :

Example 6 with IdPredicate

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

the class RelatesProperty method mapToAtom.

@Override
public Atomic mapToAtom(VarPatternAdmin var, Set<VarPatternAdmin> vars, ReasonerQuery parent) {
    Var varName = var.var().asUserDefined();
    VarPatternAdmin roleVar = this.role();
    Var roleVariable = roleVar.var().asUserDefined();
    IdPredicate predicate = getIdPredicate(roleVariable, roleVar, vars, parent);
    ConceptId predicateId = predicate != null ? predicate.getPredicate() : null;
    return RelatesAtom.create(varName, roleVariable, predicateId, parent);
}
Also used : IdPredicate(ai.grakn.graql.internal.reasoner.atom.predicate.IdPredicate) ReasonerUtils.getIdPredicate(ai.grakn.graql.internal.reasoner.utils.ReasonerUtils.getIdPredicate) VarPatternAdmin(ai.grakn.graql.admin.VarPatternAdmin) Var(ai.grakn.graql.Var) ConceptId(ai.grakn.concept.ConceptId)

Example 7 with IdPredicate

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

the class Binary method hasEquivalentPredicatesWith.

boolean hasEquivalentPredicatesWith(Binary atom) {
    // check if there is a substitution for varName
    IdPredicate thisVarPredicate = this.getIdPredicate(getVarName());
    IdPredicate varPredicate = atom.getIdPredicate(atom.getVarName());
    IdPredicate thisTypePredicate = this.getTypePredicate();
    IdPredicate typePredicate = atom.getTypePredicate();
    return ((thisVarPredicate == null && varPredicate == null || thisVarPredicate != null && thisVarPredicate.isAlphaEquivalent(varPredicate))) && (thisTypePredicate == null && typePredicate == null || thisTypePredicate != null && thisTypePredicate.isAlphaEquivalent(typePredicate));
}
Also used : IdPredicate(ai.grakn.graql.internal.reasoner.atom.predicate.IdPredicate)

Example 8 with IdPredicate

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

the class Binary method predicateBindingsAreEquivalent.

boolean predicateBindingsAreEquivalent(Binary atom) {
    // check if there is a substitution for varName
    IdPredicate thisVarPredicate = this.getIdPredicate(getVarName());
    IdPredicate varPredicate = atom.getIdPredicate(atom.getVarName());
    IdPredicate thisTypePredicate = this.getTypePredicate();
    IdPredicate typePredicate = atom.getTypePredicate();
    return (thisVarPredicate == null) == (varPredicate == null) && (thisTypePredicate == null) == (typePredicate == null);
}
Also used : IdPredicate(ai.grakn.graql.internal.reasoner.atom.predicate.IdPredicate)

Example 9 with IdPredicate

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

the class IsaAtomBase method getTypedPair.

Pair<VarPattern, IdPredicate> getTypedPair(SchemaConcept type) {
    ConceptId typeId = type.getId();
    Var typeVariable = getPredicateVariable().getValue().isEmpty() ? Graql.var().asUserDefined() : getPredicateVariable();
    IdPredicate newPredicate = IdPredicate.create(typeVariable.id(typeId).admin(), getParentQuery());
    return new Pair<>(getPattern(), newPredicate);
}
Also used : IdPredicate(ai.grakn.graql.internal.reasoner.atom.predicate.IdPredicate) Var(ai.grakn.graql.Var) ConceptId(ai.grakn.concept.ConceptId) Pair(ai.grakn.graql.internal.reasoner.utils.Pair)

Example 10 with IdPredicate

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

the class RelationshipAtom method getRoleVarMap.

/**
 * @return map containing roleType - (rolePlayer var - rolePlayer type) pairs
 */
@Memoized
public Multimap<Role, Var> getRoleVarMap() {
    ImmutableMultimap.Builder<Role, Var> builder = ImmutableMultimap.builder();
    GraknTx graph = getParentQuery().tx();
    getRelationPlayers().forEach(c -> {
        Var varName = c.getRolePlayer().var();
        VarPatternAdmin rolePattern = c.getRole().orElse(null);
        if (rolePattern != null) {
            // try directly
            Label typeLabel = rolePattern.getTypeLabel().orElse(null);
            Role role = typeLabel != null ? graph.getRole(typeLabel.getValue()) : null;
            // try indirectly
            if (role == null && rolePattern.var().isUserDefinedName()) {
                IdPredicate rolePredicate = getIdPredicate(rolePattern.var());
                if (rolePredicate != null) {
                    Role r = graph.getConcept(rolePredicate.getPredicate());
                    if (r == null)
                        throw GraqlQueryException.idNotFound(rolePredicate.getPredicate());
                    role = r;
                }
            }
            if (role != null)
                builder.put(role, varName);
        }
    });
    return builder.build();
}
Also used : Role(ai.grakn.concept.Role) GraknTx(ai.grakn.GraknTx) IdPredicate(ai.grakn.graql.internal.reasoner.atom.predicate.IdPredicate) VarPatternAdmin(ai.grakn.graql.admin.VarPatternAdmin) Var(ai.grakn.graql.Var) Label(ai.grakn.concept.Label) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) Memoized(com.google.auto.value.extension.memoized.Memoized)

Aggregations

IdPredicate (ai.grakn.graql.internal.reasoner.atom.predicate.IdPredicate)16 ConceptId (ai.grakn.concept.ConceptId)11 Var (ai.grakn.graql.Var)11 VarPatternAdmin (ai.grakn.graql.admin.VarPatternAdmin)9 ReasonerUtils.getIdPredicate (ai.grakn.graql.internal.reasoner.utils.ReasonerUtils.getIdPredicate)5 Atomic (ai.grakn.graql.admin.Atomic)4 GraknTx (ai.grakn.GraknTx)3 Concept (ai.grakn.concept.Concept)3 Label (ai.grakn.concept.Label)3 Role (ai.grakn.concept.Role)3 GraqlQueryException (ai.grakn.exception.GraqlQueryException)3 ReasonerQuery (ai.grakn.graql.admin.ReasonerQuery)3 Atom (ai.grakn.graql.internal.reasoner.atom.Atom)3 Pair (ai.grakn.graql.internal.reasoner.utils.Pair)3 Sets (com.google.common.collect.Sets)3 Set (java.util.Set)3 Stream (java.util.stream.Stream)3 Nullable (javax.annotation.Nullable)3 Relationship (ai.grakn.concept.Relationship)2 SchemaConcept (ai.grakn.concept.SchemaConcept)2