@Override public UnaryOperator<VarPattern> visitPropResource(GraqlParser.PropResourceContext ctx) { return var -> var.has(visitVariable(ctx.variable())); }
@Override public UnaryOperator<VarPattern> visitPropHas(GraqlParser.PropHasContext ctx) { Label type = visitLabel(ctx.label()); VarPattern relation = Optional.ofNullable(ctx.relation).map(this::getVariable).orElseGet(Graql::var); VarPattern resource = Optional.ofNullable(ctx.resource).map(this::getVariable).orElseGet(Graql::var); if (ctx.predicate() != null) { resource = resource.val(visitPredicate(ctx.predicate())); } VarPattern finalResource = resource; return var -> var.has(type, finalResource, relation); }
/** * Add the resources of an entity * @param var var representing the entity * @param thing thing containing resource information * @return var pattern with resources */ private static VarPattern hasResources(VarPattern var, Thing thing){ for(Attribute attribute : thing.attributes().collect(Collectors.toSet())){ var = var.has(attribute.type().label(), var().val(attribute.value())); } return var; }