use of ai.grakn.graql.internal.reasoner.atom.binary.IsaAtomBase in project grakn by graknlabs.
the class ReasonerQueryImpl method getVarTypeMap.
private Map<Var, Type> getVarTypeMap(Stream<IsaAtomBase> isas) {
HashMap<Var, Type> map = new HashMap<>();
isas.map(at -> new Pair<>(at.getVarName(), at.getSchemaConcept())).filter(p -> Objects.nonNull(p.getValue())).filter(p -> p.getValue().isType()).forEach(p -> {
Var var = p.getKey();
Type newType = p.getValue().asType();
Type type = map.get(var);
if (type == null)
map.put(var, newType);
else {
boolean isSubType = type.subs().anyMatch(t -> t.equals(newType));
if (isSubType)
map.put(var, newType);
}
});
return map;
}
use of ai.grakn.graql.internal.reasoner.atom.binary.IsaAtomBase in project grakn by graknlabs.
the class ReasonerQueryImpl method getSubstitution.
/**
* @return substitution obtained from all id predicates (including internal) in the query
*/
public Answer getSubstitution() {
if (substitution == null) {
Set<Var> varNames = getVarNames();
Set<IdPredicate> predicates = getAtoms(IsaAtomBase.class).map(IsaAtomBase::getTypePredicate).filter(Objects::nonNull).filter(p -> varNames.contains(p.getVarName())).collect(Collectors.toSet());
getAtoms(IdPredicate.class).forEach(predicates::add);
HashMap<Var, Concept> answerMap = new HashMap<>();
predicates.forEach(p -> {
Concept concept = tx().getConcept(p.getPredicate());
if (concept == null)
throw GraqlQueryException.idNotFound(p.getPredicate());
answerMap.put(p.getVarName(), concept);
});
substitution = new QueryAnswer(answerMap);
}
return substitution;
}
Aggregations