private static GraphTraversal<?, ?> transform(final E_LogicalAnd expression) { return __.and( transform(expression.getArg1()), transform(expression.getArg2())); }
@Override public Traversal<Vertex, Map<String, Object>> get_g_V_matchXa_knows_b__andXa_created_c__b_created_c__andXb_created_count_d__a_knows_count_dXXX() { return g.V().match( as("a").out("knows").as("b"), and( as("a").out("created").as("c"), as("b").out("created").as("c"), and( as("b").out("created").count().as("d"), as("a").out("knows").count().as("d") ) )); }
@Override public Traversal<Vertex, Map<String, Object>> get_g_V_asXaX_outXcreatedX_asXbX_whereXandXasXbX_in__notXasXaX_outXcreatedX_hasXname_rippleXXX_selectXa_bX() { return g.V().as("a").out("created").as("b").where(and(as("b").in(), not(as("a").out("created").has("name", "ripple")))).select("a", "b"); }
@Override public Traversal<Vertex, Map<String, Object>> get_g_V_matchXwhereXandXa_created_b__b_0created_count_isXeqX3XXXX__a_both_b__whereXb_inXX() { return g.V().match( where(and( as("a").out("created").as("b"), as("b").in("created").count().is(eq(3)))), as("a").both().as("b"), where(as("b").in())); }
@Override public Traversal<Vertex, Map<String, Object>> get_g_V_asXaX_out_asXbX_whereXandXasXaX_outXknowsX_asXbX__orXasXbX_outXcreatedX_hasXname_rippleX__asXbX_inXknowsX_count_isXnotXeqX0XXXXX_selectXa_bX() { return g.V().as("a").out().as("b").where(and(as("a").out("knows").as("b"), or(as("b").out("created").has("name", "ripple"), as("b").in("knows").count().is(not(eq(0)))))).select("a", "b"); }
assertCount(2, g.V().or(__.has("name", "Totoro"),__.has("age", 2))); assertCount(2, g.V().or(__.has("name", "Totoro").has("age", 1),__.has("age", 2))); assertCount(2, g.V().or(__.and(__.has("name", "Totoro"), __.has("age", 1)),__.has("age", 2)));
private SubgraphStrategy(final Builder builder) { this.vertexCriterion = null == builder.vertexCriterion ? null : builder.vertexCriterion.asAdmin().clone(); this.checkAdjacentVertices = builder.checkAdjacentVertices; // if there is no vertex predicate there is no need to test either side of the edge - also this option can // be simply configured in the builder to not be used if (null == this.vertexCriterion || !checkAdjacentVertices) { this.edgeCriterion = null == builder.edgeCriterion ? null : builder.edgeCriterion.asAdmin().clone(); } else { final Traversal.Admin<Edge, ?> vertexPredicate; vertexPredicate = __.<Edge>and( __.inV().filter(this.vertexCriterion), __.outV().filter(this.vertexCriterion)).asAdmin(); // if there is a vertex predicate then there is an implied edge filter on vertices even if there is no // edge predicate provided by the user. this.edgeCriterion = null == builder.edgeCriterion ? vertexPredicate : builder.edgeCriterion.asAdmin().clone().addStep(new TraversalFilterStep<>(builder.edgeCriterion.asAdmin(), vertexPredicate)); } this.vertexPropertyCriterion = null == builder.vertexPropertyCriterion ? null : builder.vertexPropertyCriterion.asAdmin().clone(); if (null != this.vertexCriterion) TraversalHelper.applyTraversalRecursively(t -> t.getStartStep().addLabel(MARKER), this.vertexCriterion); if (null != this.edgeCriterion) TraversalHelper.applyTraversalRecursively(t -> t.getStartStep().addLabel(MARKER), this.edgeCriterion); if (null != this.vertexPropertyCriterion) TraversalHelper.applyTraversalRecursively(t -> t.getStartStep().addLabel(MARKER), this.vertexPropertyCriterion); }
public static GraphTraversal<?, ?> transform(final E_LogicalAnd expression) { return __.and( transform(expression.getArg1()), transform(expression.getArg2())); }
/** * BGP ?x p value * generate appropriate Tinkerpop filter to match value = dt */ GraphTraversal<? extends Element, Edge> getVertexPredicate(P p, DatatypeValue dt){ if (dt.isLiteral()){ if (dt.getLang() != null && !dt.getLang().isEmpty()) { return __.and(__.has(KIND, LITERAL), __.has(VERTEX_VALUE, dt.stringValue()), __.has(LANG, dt.getLang())); } else if (dt.getDatatypeURI() != null) { return __.and(__.has(KIND, LITERAL), __.has(VERTEX_VALUE, dt.stringValue()), __.has(TYPE, dt.getDatatypeURI())); } else { return __.and(__.has(KIND, LITERAL), __.has(VERTEX_VALUE, dt.stringValue())); } } return __.and(__.has(KIND, (dt.isBlank()) ? BNODE : IRI), __.has(VERTEX_VALUE, dt.stringValue())); }
@Override public Traversal<Vertex, Map<String, Object>> get_g_V_matchXa_knows_b__andXa_created_c__b_created_c__andXb_created_count_d__a_knows_count_dXXX() { return g.V().match( as("a").out("knows").as("b"), and( as("a").out("created").as("c"), as("b").out("created").as("c"), and( as("b").out("created").count().as("d"), as("a").out("knows").count().as("d") ) )); }
GraphTraversal<? extends Element, ? extends Element> translate(Expr exp, int node){ if (isDebug()){ System.out.println("SP2T: " + exp); } switch (exp.oper()){ case ExprType.AND: return __.and(translate(exp.getExp(0), node), translate(exp.getExp(1), node)); case ExprType.OR: return __.or(translate(exp.getExp(0), node), translate(exp.getExp(1), node)); case ExprType.NOT: return __.not(translate(exp.getExp(0), node)); default: return filter(exp, node); } }
@Override public Traversal<Vertex, Map<String, Object>> get_g_V_asXaX_outXcreatedX_asXbX_whereXandXasXbX_in__notXasXaX_outXcreatedX_hasXname_rippleXXX_selectXa_bX() { return g.V().as("a").out("created").as("b").where(and(as("b").in(), not(as("a").out("created").has("name", "ripple")))).select("a", "b"); }
@Override public Traversal<Vertex, Map<String, Object>> get_g_V_matchXwhereXandXa_created_b__b_0created_count_isXeqX3XXXX__a_both_b__whereXb_inXX() { return g.V().match( where(and( as("a").out("created").as("b"), as("b").in("created").count().is(eq(3)))), as("a").both().as("b"), where(as("b").in())); }
@Override public Traversal<Vertex, Map<String, Object>> get_g_V_asXaX_out_asXbX_whereXandXasXaX_outXknowsX_asXbX__orXasXbX_outXcreatedX_hasXname_rippleX__asXbX_inXknowsX_count_isXnotXeqX0XXXXX_selectXa_bX() { return g.V().as("a").out().as("b").where(and(as("a").out("knows").as("b"), or(as("b").out("created").has("name", "ripple"), as("b").in("knows").count().is(not(eq(0)))))).select("a", "b"); }
private SubgraphStrategy(final Builder builder) { this.vertexCriterion = null == builder.vertexCriterion ? null : builder.vertexCriterion.asAdmin().clone(); this.checkAdjacentVertices = builder.checkAdjacentVertices; // if there is no vertex predicate there is no need to test either side of the edge - also this option can // be simply configured in the builder to not be used if (null == this.vertexCriterion || !checkAdjacentVertices) { this.edgeCriterion = null == builder.edgeCriterion ? null : builder.edgeCriterion.asAdmin().clone(); } else { final Traversal.Admin<Edge, ?> vertexPredicate; vertexPredicate = __.<Edge>and( __.inV().filter(this.vertexCriterion), __.outV().filter(this.vertexCriterion)).asAdmin(); // if there is a vertex predicate then there is an implied edge filter on vertices even if there is no // edge predicate provided by the user. this.edgeCriterion = null == builder.edgeCriterion ? vertexPredicate : builder.edgeCriterion.asAdmin().clone().addStep(new TraversalFilterStep<>(builder.edgeCriterion.asAdmin(), vertexPredicate)); } this.vertexPropertyCriterion = null == builder.vertexPropertyCriterion ? null : builder.vertexPropertyCriterion.asAdmin().clone(); if (null != this.vertexCriterion) TraversalHelper.applyTraversalRecursively(t -> t.getStartStep().addLabel(MARKER), this.vertexCriterion); if (null != this.edgeCriterion) TraversalHelper.applyTraversalRecursively(t -> t.getStartStep().addLabel(MARKER), this.edgeCriterion); if (null != this.vertexPropertyCriterion) TraversalHelper.applyTraversalRecursively(t -> t.getStartStep().addLabel(MARKER), this.vertexPropertyCriterion); }