use of ai.grakn.graql.Var in project grakn by graknlabs.
the class TemplateVisitor method visitVarLiteral.
@Override
public String visitVarLiteral(GraqlTemplateParser.VarLiteralContext ctx) {
Var var = var(ctx.getText().substring(1));
if (!scope.hasSeen(var)) {
scope.markAsSeen(var);
iteration.compute(var, (k, v) -> v == null ? 0 : v + 1);
}
return ctx.getText() + iteration.get(var);
}
use of ai.grakn.graql.Var in project grakn by graknlabs.
the class AttributeIndexFragmentSet method optimise.
private static void optimise(Collection<EquivalentFragmentSet> fragmentSets, ValueFragmentSet valueSet, IsaFragmentSet isaSet, Label label) {
// Remove fragment sets we are going to replace
fragmentSets.remove(valueSet);
fragmentSets.remove(isaSet);
// Add a new fragment set to replace the old ones
Var attribute = valueSet.var();
Optional<Object> maybeValue = valueSet.predicate().equalsValue();
assert maybeValue.isPresent() : "This is filtered to only ones with equalValues in equalValueFragments method";
Object value = maybeValue.get();
AttributeIndexFragmentSet indexFragmentSet = AttributeIndexFragmentSet.of(attribute, label, value);
fragmentSets.add(indexFragmentSet);
}
use of ai.grakn.graql.Var in project grakn by graknlabs.
the class GraqlTraversal method getGraphTraversal.
/**
* Get the {@code GraphTraversal} that this {@code GraqlTraversal} represents.
*/
// Because 'union' accepts an array, we can't use generics
@SuppressWarnings("unchecked")
public GraphTraversal<Vertex, Map<String, Element>> getGraphTraversal(EmbeddedGraknTx<?> tx, Set<Var> vars) {
if (fragments().size() == 1) {
// If there are no disjunctions, we don't need to union them and get a performance boost
ImmutableList<Fragment> list = Iterables.getOnlyElement(fragments());
return getConjunctionTraversal(tx, tx.getTinkerTraversal().V(), vars, list);
} else {
Traversal[] traversals = fragments().stream().map(list -> getConjunctionTraversal(tx, __.V(), vars, list)).toArray(Traversal[]::new);
// This is a sneaky trick - we want to do a union but tinkerpop requires all traversals to start from
// somewhere, so we start from a single arbitrary vertex.
GraphTraversal traversal = tx.getTinkerTraversal().V().limit(1).union(traversals);
return selectVars(traversal, vars);
}
}
use of ai.grakn.graql.Var in project grakn by graknlabs.
the class Fragments method traverseSchemaConceptFromEdge.
static <S> GraphTraversal<S, Vertex> traverseSchemaConceptFromEdge(GraphTraversal<S, Edge> traversal, Schema.EdgeProperty edgeProperty) {
// Access label ID from edge
Var labelId = Graql.var();
traversal.values(edgeProperty.name()).as(labelId.name());
// Look up schema concept using ID
return traversal.V().has(LABEL_ID.name(), __.where(P.eq(labelId.name())));
}
use of ai.grakn.graql.Var in project grakn by graknlabs.
the class ConjunctionQuery method equivalentFragmentSetsOfVar.
private static Stream<EquivalentFragmentSet> equivalentFragmentSetsOfVar(VarPatternAdmin var) {
Collection<EquivalentFragmentSet> traversals = new HashSet<>();
Var start = var.var();
var.getProperties().forEach(property -> {
VarPropertyInternal propertyInternal = (VarPropertyInternal) property;
Collection<EquivalentFragmentSet> newTraversals = propertyInternal.match(start);
traversals.addAll(newTraversals);
});
if (!traversals.isEmpty()) {
return traversals.stream();
} else {
// If this variable has no properties, only confirm that it is not internal and nothing else.
return Stream.of(EquivalentFragmentSets.notInternalFragmentSet(null, start));
}
}
Aggregations