private static GraphTraversal<?, ?> transform(final E_LogicalOr expression) { return __.or( transform(expression.getArg1()), transform(expression.getArg2())); }
@Test @LoadGraphWith(MODERN) public void shouldFilterComplexVertexCriterion() throws Exception { checkResults(Arrays.asList("vadas", "josh"), g.withStrategies(SubgraphStrategy.build().vertices(__.<Vertex>in("knows").has("name", "marko")).create()). V().values("name")); checkResults(Arrays.asList("vadas", "josh", "lop"), g.withStrategies(SubgraphStrategy.build().vertices(__.<Vertex>in().has("name", "marko")).create()). V().values("name")); checkResults(Arrays.asList("vadas", "josh"), g.withStrategies(SubgraphStrategy.build().vertices(__.<Vertex>in("knows").where(out("created").has("name", "lop"))).create()). V().values("name")); checkResults(Arrays.asList("vadas", "josh", "lop"), g.withStrategies(SubgraphStrategy.build().vertices(__.<Vertex>in().where(has("name", "marko").out("created").has("name", "lop"))).create()). V().values("name")); checkResults(Arrays.asList("marko", "vadas", "josh", "lop"), g.withStrategies(SubgraphStrategy.build().vertices(__.or(both().has("name", "marko"), has("name", "marko"))).create()). V().where(bothE().count().is(P.neq(0))).values("name")); }
@Test(expected = NoSuchElementException.class) @LoadGraphWith(MODERN) public void shouldGetExcludedEdge() throws Exception { final Traversal<Edge, ?> edgeCriterion = __.or( has("weight", 1.0d).hasLabel("knows"), // 8 has("weight", 0.4d).hasLabel("created").outV().has("name", "marko"), // 9 has("weight", 1.0d).hasLabel("created") // 10 ); final GraphTraversalSource sg = g.withStrategies(SubgraphStrategy.build().edges(edgeCriterion).create()); sg.E(sg.E(convertToEdgeId("marko", "knows", "vadas")).next()).next(); }
@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"); }
@Override public Traversal<Vertex, Map<String, Object>> get_g_V_asXaX_out_asXbX_matchXa_out_count_c__orXa_knows_b__b_in_count_c__and__c_isXgtX2XXXX() { return g.V().as("a").out().as("b"). match( as("a").out().count().as("c"), or( as("a").out("knows").as("b"), as("b").in().count().as("c").and().as("c").is(P.gt(2)) ) ); }
final Traversal<Edge, ?> edgeCriterion = __.or( has("weight", 0.4d).hasLabel("created"), // 11 has("weight", 1.0d).hasLabel("created") // 10
@Override public Traversal<Vertex, Map<String, Object>> get_g_V_matchXa_whereXa_neqXcXX__a_created_b__orXa_knows_vadas__a_0knows_and_a_hasXlabel_personXX__b_0created_c__b_0created_count_isXgtX1XXX_selectXa_b_cX_byXidX() { return g.V().match( where("a", P.neq("c")), as("a").out("created").as("b"), or( as("a").out("knows").has("name", "vadas"), as("a").in("knows").and().as("a").has(T.label, "person") ), as("b").in("created").as("c"), as("b").in("created").count().is(P.gt(1))) .select("a", "b", "c").by(T.id); }
final Traversal<Edge, ?> edgeCriterion = __.or( has("weight", 0.4d).hasLabel("created"), // 11 has("weight", 1.0d).hasLabel("created") // 10
@Test @LoadGraphWith(MODERN) public void shouldFilterEdgeCriterion() throws Exception { final Traversal<Edge, ?> edgeCriterion = __.or( has("weight", 1.0d).hasLabel("knows"), // 8 has("weight", 0.4d).hasLabel("created").outV().has("name", "marko"), // 9
public static GraphTraversal<?, ?> transform(final E_LogicalOr expression) { return __.or( transform(expression.getArg1()), transform(expression.getArg2())); }
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); } }
@Test @LoadGraphWith(MODERN) public void shouldFilterComplexVertexCriterion() throws Exception { checkResults(Arrays.asList("vadas", "josh"), g.withStrategies(SubgraphStrategy.build().vertices(__.<Vertex>in("knows").has("name", "marko")).create()). V().values("name")); checkResults(Arrays.asList("vadas", "josh", "lop"), g.withStrategies(SubgraphStrategy.build().vertices(__.<Vertex>in().has("name", "marko")).create()). V().values("name")); checkResults(Arrays.asList("vadas", "josh"), g.withStrategies(SubgraphStrategy.build().vertices(__.<Vertex>in("knows").where(out("created").has("name", "lop"))).create()). V().values("name")); checkResults(Arrays.asList("vadas", "josh", "lop"), g.withStrategies(SubgraphStrategy.build().vertices(__.<Vertex>in().where(has("name", "marko").out("created").has("name", "lop"))).create()). V().values("name")); checkResults(Arrays.asList("marko", "vadas", "josh", "lop"), g.withStrategies(SubgraphStrategy.build().vertices(__.or(both().has("name", "marko"), has("name", "marko"))).create()). V().where(bothE().count().is(P.neq(0))).values("name")); }
@Test(expected = NoSuchElementException.class) @LoadGraphWith(MODERN) public void shouldGetExcludedEdge() throws Exception { final Traversal<Edge, ?> edgeCriterion = __.or( has("weight", 1.0d).hasLabel("knows"), // 8 has("weight", 0.4d).hasLabel("created").outV().has("name", "marko"), // 9 has("weight", 1.0d).hasLabel("created") // 10 ); final GraphTraversalSource sg = g.withStrategies(SubgraphStrategy.build().edges(edgeCriterion).create()); sg.E(sg.E(convertToEdgeId("marko", "knows", "vadas")).next()).next(); }
@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"); }
@Override public Traversal<Vertex, Map<String, Object>> get_g_V_asXaX_out_asXbX_matchXa_out_count_c__orXa_knows_b__b_in_count_c__and__c_isXgtX2XXXX() { return g.V().as("a").out().as("b"). match( as("a").out().count().as("c"), or( as("a").out("knows").as("b"), as("b").in().count().as("c").and().as("c").is(P.gt(2)) ) ); }
@SuppressWarnings("unchecked") protected void updateDirectoryFileSystemTypes() { GraphTraversalSource g = traversal(); g.V().out(Bdio.ObjectProperty.parent.name()) .or(hasNot(Bdio.DataProperty.fileSystemType.name()), // TODO We should be checking for other types as well has(Bdio.DataProperty.fileSystemType.name(), Bdio.FileSystemType.REGULAR.toString())) .coalesce( or(has(Bdio.DataProperty.byteCount.name()), has(Bdio.DataProperty.contentType.name())) .property(Bdio.DataProperty.fileSystemType.name(), Bdio.FileSystemType.DIRECTORY_ARCHIVE.toString()), property(Bdio.DataProperty.fileSystemType.name(), Bdio.FileSystemType.DIRECTORY.toString())) .iterate(); }
final Traversal<Edge, ?> edgeCriterion = __.or( has("weight", 0.4d).hasLabel("created"), // 11 has("weight", 1.0d).hasLabel("created") // 10
final Traversal<Edge, ?> edgeCriterion = __.or( has("weight", 0.4d).hasLabel("created"), // 11 has("weight", 1.0d).hasLabel("created") // 10
@Override public Traversal<Vertex, Map<String, Object>> get_g_V_matchXa_whereXa_neqXcXX__a_created_b__orXa_knows_vadas__a_0knows_and_a_hasXlabel_personXX__b_0created_c__b_0created_count_isXgtX1XXX_selectXa_b_cX_byXidX() { return g.V().match( where("a", P.neq("c")), as("a").out("created").as("b"), or( as("a").out("knows").has("name", "vadas"), as("a").in("knows").and().as("a").has(T.label, "person") ), as("b").in("created").as("c"), as("b").in("created").count().is(P.gt(1))) .select("a", "b", "c").by(T.id); }
@Test @LoadGraphWith(MODERN) public void shouldFilterEdgeCriterion() throws Exception { final Traversal<Edge, ?> edgeCriterion = __.or( has("weight", 1.0d).hasLabel("knows"), // 8 has("weight", 0.4d).hasLabel("created").outV().has("name", "marko"), // 9