use of ai.grakn.graql.Var in project grakn by graknlabs.
the class QueryVisitor method visitGetQuery.
@Override
public GetQuery visitGetQuery(GraqlParser.GetQueryContext ctx) {
Set<Var> vars = ctx.VARIABLE().stream().map(this::getVariable).collect(toSet());
Match match = visitMatchPart(ctx.matchPart());
if (vars.isEmpty()) {
return match.get();
} else {
return match.get(vars);
}
}
use of ai.grakn.graql.Var in project grakn by graknlabs.
the class QueryVisitor method visitMatchOrderBy.
@Override
public Match visitMatchOrderBy(GraqlParser.MatchOrderByContext ctx) {
Match match = visitMatchPart(ctx.matchPart());
// decide which ordering method to use
Var var = getVariable(ctx.VARIABLE());
if (ctx.order() != null) {
return match.orderBy(var, visitOrder(ctx.order()));
} else {
return match.orderBy(var);
}
}
use of ai.grakn.graql.Var in project grakn by graknlabs.
the class VarPatternImpl method toString.
@Override
public final String toString() {
Collection<VarPatternAdmin> innerVars = innerVarPatterns();
innerVars.remove(this);
getProperties(HasAttributeProperty.class).map(HasAttributeProperty::attribute).flatMap(r -> r.innerVarPatterns().stream()).forEach(innerVars::remove);
if (innerVars.stream().anyMatch(VarPatternImpl::invalidInnerVariable)) {
LOG.warn("printing a query with inner variables, which is not supported in native Graql");
}
StringBuilder builder = new StringBuilder();
String name = var().isUserDefinedName() ? var().toString() : "";
builder.append(name);
if (var().isUserDefinedName() && !properties().isEmpty()) {
// Add a space after the var name
builder.append(" ");
}
boolean first = true;
for (VarProperty property : properties()) {
if (!first) {
builder.append(" ");
}
first = false;
property.buildString(builder);
}
return builder.toString();
}
use of ai.grakn.graql.Var in project grakn by graknlabs.
the class ResourceAtom method materialise.
@Override
public Stream<Answer> materialise() {
Answer substitution = getParentQuery().getSubstitution();
AttributeType type = getSchemaConcept().asAttributeType();
Concept owner = substitution.get(getVarName());
Var resourceVariable = getPredicateVariable();
// if the attribute already exists, only attach a new link to the owner, otherwise create a new attribute
if (substitution.containsVar(resourceVariable)) {
Attribute attribute = substitution.get(resourceVariable).asAttribute();
attachAttribute(owner, attribute);
return Stream.of(substitution);
} else {
Attribute attribute = AttributeTypeImpl.from(type).putAttributeInferred(Iterables.getOnlyElement(getMultiPredicate()).getPredicate().equalsValue().get());
attachAttribute(owner, attribute);
return Stream.of(substitution.merge(new QueryAnswer(ImmutableMap.of(resourceVariable, attribute))));
}
}
use of ai.grakn.graql.Var in project grakn by graknlabs.
the class ValuePredicate method getVarNames.
@Override
public Set<Var> getVarNames() {
Set<Var> vars = super.getVarNames();
VarPatternAdmin innerVar = getPredicate().getInnerVar().orElse(null);
if (innerVar != null && innerVar.var().isUserDefinedName())
vars.add(innerVar.var());
return vars;
}
Aggregations