use of ai.grakn.graql.Var in project grakn by graknlabs.
the class JsonPrinter method build.
@Override
public final Json build(Map<?, ?> map) {
Json json = Json.object();
map.forEach((Object key, Object value) -> {
if (key instanceof Var)
key = ((Var) key).getValue();
String keyString = key == null ? "" : key.toString();
json.set(keyString, build(value));
});
return json;
}
use of ai.grakn.graql.Var in project grakn by graknlabs.
the class QueryAnswer method unify.
@Override
public Answer unify(Unifier unifier) {
if (unifier.isEmpty())
return this;
Map<Var, Concept> unified = new HashMap<>();
for (Map.Entry<Var, Concept> e : this.entrySet()) {
Var var = e.getKey();
Concept con = e.getValue();
Collection<Var> uvars = unifier.get(var);
if (uvars.isEmpty() && !unifier.values().contains(var)) {
Concept put = unified.put(var, con);
if (put != null && !put.equals(con))
return new QueryAnswer();
} else {
for (Var uv : uvars) {
Concept put = unified.put(uv, con);
if (put != null && !put.equals(con))
return new QueryAnswer();
}
}
}
return new QueryAnswer(unified, this.getExplanation());
}
use of ai.grakn.graql.Var in project grakn by graknlabs.
the class HasAttributeProperty method mapToAtom.
@Override
public Atomic mapToAtom(VarPatternAdmin var, Set<VarPatternAdmin> vars, ReasonerQuery parent) {
// NB: HasAttributeProperty always has (type) label specified
Var varName = var.var().asUserDefined();
Var relationVariable = relationship().var();
Var attributeVariable = attribute().var().asUserDefined();
Set<ValuePredicate> predicates = getValuePredicates(attributeVariable, attribute(), vars, parent);
IsaProperty isaProp = attribute().getProperties(IsaProperty.class).findFirst().orElse(null);
VarPatternAdmin typeVar = isaProp != null ? isaProp.type() : null;
IdPredicate predicate = typeVar != null ? getIdPredicate(attributeVariable, typeVar, vars, parent) : null;
ConceptId predicateId = predicate != null ? predicate.getPredicate() : null;
// add resource atom
VarPatternAdmin resVar = relationVariable.isUserDefinedName() ? varName.has(type(), attributeVariable, relationVariable).admin() : varName.has(type(), attributeVariable).admin();
return ResourceAtom.create(resVar, attributeVariable, relationVariable, predicateId, predicates, parent);
}
use of ai.grakn.graql.Var in project grakn by graknlabs.
the class PlaysProperty method mapToAtom.
@Override
public Atomic mapToAtom(VarPatternAdmin var, Set<VarPatternAdmin> vars, ReasonerQuery parent) {
Var varName = var.var().asUserDefined();
VarPatternAdmin typeVar = this.role();
Var typeVariable = typeVar.var().asUserDefined();
IdPredicate predicate = getIdPredicate(typeVariable, typeVar, vars, parent);
ConceptId predicateId = predicate == null ? null : predicate.getPredicate();
return PlaysAtom.create(varName, typeVariable, predicateId, parent);
}
use of ai.grakn.graql.Var in project grakn by graknlabs.
the class Fragment method vars.
/**
* Get all variables in the fragment including the start and end (if present)
*/
public final Set<Var> vars() {
if (vars == null) {
ImmutableSet.Builder<Var> builder = ImmutableSet.<Var>builder().add(start());
Var end = end();
if (end != null)
builder.add(end);
builder.addAll(otherVars());
vars = builder.build();
}
return vars;
}
Aggregations