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);
}
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));
}
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);
}
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);
}
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();
}
Aggregations