@Test @LoadGraphWith(MODERN) public void shouldFindInDirectedShortestPaths() throws Exception { final List<ShortestPathVertexProgram> programs = Arrays.asList( ShortestPathVertexProgram.build().edgeTraversal(__.inE()).create(graph), ShortestPathVertexProgram.build().edgeDirection(Direction.IN).create(graph)); for (final ShortestPathVertexProgram program : programs) { final ComputerResult result = graph.compute(graphProvider.getGraphComputer(graph).getClass()). program(program).submit().get(); assertTrue(result.memory().exists(ShortestPathVertexProgram.SHORTEST_PATHS)); final List<Path> shortestPaths = result.memory().get(ShortestPathVertexProgram.SHORTEST_PATHS); final List<Path> expected = Arrays.stream(ALL_SHORTEST_PATHS) .filter(p -> (p[0].equals("marko") && p.length == 1) || (p[0].equals("vadas") && Arrays.asList("marko", "vadas").contains(p[p.length - 1])) || (p[0].equals("lop") && Arrays.asList("marko", "lop", "josh", "peter").contains(p[p.length - 1])) || (p[0].equals("josh") && Arrays.asList("marko", "josh").contains(p[p.length - 1])) || (p[0].equals("ripple") && Arrays.asList("marko", "josh", "ripple").contains(p[p.length - 1])) || (p[0].equals("peter") && p.length == 1)) .map(helper::makePath).collect(Collectors.toList()); helper.checkResults(expected, shortestPaths); } }
return __.<Vertex>outE(outs).asAdmin(); else if (outLabels.isEmpty() && bothLabels.isEmpty()) // only in has labels return __.<Vertex>inE(ins).asAdmin(); else if (bothLabels.isEmpty()) // out and in both have labels return __.<Vertex, Edge>union(__.inE(ins), __.outE(outs)).asAdmin(); else if (outLabels.isEmpty() && ins.length > 0) // in and both have labels (and in is not null) return __.<Vertex, Edge>union(__.inE(ins), __.bothE(boths)).asAdmin(); else if (inLabels.isEmpty() && outs.length > 0) // out and both have labels (and out is not null) return __.<Vertex, Edge>union(__.outE(outs), __.bothE(boths)).asAdmin();
@Override public Traversal<Vertex, String> get_g_V_localXinEXknowsX_limitX2XX_outV_name() { return g.V().local(inE("knows").limit(2)).outV().values("name"); }
@Override public Traversal<Vertex, Number> get_g_VX1_2X_unionXoutE_count__inE_count__outE_weight_sumX(final Object v1Id, final Object v2Id) { return g.V(v1Id, v2Id).union(outE().count(), inE().count(), (Traversal) outE().values("weight").sum()); }
@Override public Traversal<Vertex, Number> get_g_VX1_2X_localXunionXoutE_count__inE_count__outE_weight_sumXX(final Object v1Id, final Object v2Id) { return g.V(v1Id, v2Id).local(union(outE().count(), inE().count(), (Traversal) outE().values("weight").sum())); }
@Test @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) public void g_addV_asXfirstX_repeatXaddEXnextX_toXaddVX_inVX_timesX5X_addEXnextX_toXselectXfirstXX() { final Traversal<Vertex, Edge> traversal = get_g_addV_asXfirstX_repeatXaddEXnextX_toXaddVX_inVX_timesX5X_addEXnextX_toXselectXfirstXX(); printTraversalForm(traversal); assertEquals("next", traversal.next().label()); assertFalse(traversal.hasNext()); assertEquals(6L, g.V().count().next().longValue()); assertEquals(6L, g.E().count().next().longValue()); assertEquals(Arrays.asList(2L, 2L, 2L, 2L, 2L, 2L), g.V().map(bothE().count()).toList()); assertEquals(Arrays.asList(1L, 1L, 1L, 1L, 1L, 1L), g.V().map(inE().count()).toList()); assertEquals(Arrays.asList(1L, 1L, 1L, 1L, 1L, 1L), g.V().map(outE().count()).toList()); }
@Override public Traversal<Vertex, Collection> get_g_V_storeXaX_byXoutEXcreatedX_countX_out_out_storeXaX_byXinEXcreatedX_weight_sumX_capXaX() { return g.V().store("a").by(outE("created").count()).out().out().store("a").by(inE("created").values("weight").sum()).cap("a"); } }
@Override public Traversal<Vertex, Map<Object, List<Vertex>>> get_g_V_outXcreatedX_groupXmX_byXlabelX_pageRankX1X_withXpropertyName_pageRankXX_withXedges_inEXX_withXtimes_1X_inXcreatedX_groupXmX_byXpageRankX_capXmX() { return g.V().out("created").group("m").by(T.label).pageRank(1.0).with(PageRank.propertyName, "pageRank").with(PageRank.edges, __.inE()).with(PageRank.times, 1).in("created").group("m").by("pageRank").cap("m"); } }
@Override public Traversal<Vertex, Map<Object, List<Object>>> get_g_V_hasLabelXsoftwareX_hasXname_rippleX_pageRankX1X_byXinEXcreatedXX_timesX1X_byXpriorsX_inXcreatedX_unionXboth__identityX_valueMapXname_priorsX() { return g.V().hasLabel("software").has("name", "ripple").pageRank(1.0).by(__.inE("created")).times(1).by("priors").in("created").union(__.both(), __.identity()).valueMap("name", "priors"); }
@Override public Traversal<Vertex, Map<Object, List<Vertex>>> get_g_V_outXcreatedX_groupXmX_byXlabelX_pageRankX1X_byXpageRankX_byXinEX_timesX1X_inXcreatedX_groupXmX_byXpageRankX_capXmX() { return g.V().out("created").group("m").by(T.label).pageRank(1.0).by("pageRank").by(__.inE()).times(1).in("created").group("m").by("pageRank").cap("m"); }
Map<Vertex, List<Edge>> map = ReferenceFactory.detach(g.V().hasLabel("software").group().by().by(inE().fold()).next()); for (final Map.Entry<Vertex, List<Edge>> entry : map.entrySet()) { assertTrue(entry.getKey() instanceof ReferenceVertex); map = ReferenceFactory.detach(g.V().hasLabel("software").group("m").by().by(inE().fold()).identity().cap("m").next()); for (final Map.Entry<Vertex, List<Edge>> entry : map.entrySet()) { assertTrue(entry.getKey() instanceof ReferenceVertex);
Map<Vertex, List<Edge>> map = DetachedFactory.detach(g.V().hasLabel("software").group().by().by(inE().fold()).next(), true); for (final Map.Entry<Vertex, List<Edge>> entry : map.entrySet()) { assertTrue(entry.getKey() instanceof DetachedVertex); map = DetachedFactory.detach(g.V().hasLabel("software").group("m").by().by(inE().fold()).identity().cap("m").next(), true); for (final Map.Entry<Vertex, List<Edge>> entry : map.entrySet()) { assertTrue(entry.getKey() instanceof DetachedVertex);
@Override public Traversal<Vertex, String> get_g_V_matchXa_hasXsong_name_sunshineX__a_mapX0followedBy_weight_meanX_b__a_0followedBy_c__c_filterXweight_whereXgteXbXXX_outV_dX_selectXdX_byXnameX() { return g.V().match( as("a").has("song", "name", "HERE COMES SUNSHINE"), as("a").map(inE("followedBy").values("weight").mean()).as("b"), as("a").inE("followedBy").as("c"), as("c").filter(values("weight").where(P.gte("b"))).outV().as("d")). <String>select("d").by("name"); }
@Benchmark public GraphTraversal.Admin<Vertex,Vertex> testTranslationLong() { return translator.translate(g.V().match( as("a").has("song", "name", "HERE COMES SUNSHINE"), as("a").map(inE("followedBy").values("weight").mean()).as("b"), as("a").inE("followedBy").as("c"), as("c").filter(values("weight").where(P.gte("b"))).outV().as("d")). <String>select("d").by("name").asAdmin().getBytecode()); }
@Override public Traversal<Vertex, String> get_g_V_localXinEXknowsX_limitX2XX_outV_name() { return g.V().local(inE("knows").limit(2)).outV().values("name"); }
@Override public Traversal<Vertex, Number> get_g_VX1_2X_localXunionXoutE_count__inE_count__outE_weight_sumXX(final Object v1Id, final Object v2Id) { return g.V(v1Id, v2Id).local(union(outE().count(), inE().count(), (Traversal) outE().values("weight").sum())); }
@Override public Traversal<Vertex, Collection> get_g_V_storeXaX_byXoutEXcreatedX_countX_out_out_storeXaX_byXinEXcreatedX_weight_sumX_capXaX() { return g.V().store("a").by(outE("created").count()).out().out().store("a").by(inE("created").values("weight").sum()).cap("a"); } }
@Override public Traversal<Vertex, Map<Object, List<Vertex>>> get_g_V_outXcreatedX_groupXmX_byXlabelX_pageRankX1X_byXpageRankX_byXinEX_timesX1X_inXcreatedX_groupXmX_byXpageRankX_capXmX() { return g.V().out("created").group("m").by(T.label).pageRank(1.0).by("pageRank").by(__.inE()).times(1).in("created").group("m").by("pageRank").cap("m"); }
@Override public Traversal<Vertex, Map<Object, List<Vertex>>> get_g_V_outXcreatedX_groupXmX_byXlabelX_pageRankX1X_withXpropertyName_pageRankXX_withXedges_inEXX_withXtimes_1X_inXcreatedX_groupXmX_byXpageRankX_capXmX() { return g.V().out("created").group("m").by(T.label).pageRank(1.0).with(PageRank.propertyName, "pageRank").with(PageRank.edges, __.inE()).with(PageRank.times, 1).in("created").group("m").by("pageRank").cap("m"); } }
@Override public Traversal<Vertex, String> get_g_V_matchXa_hasXsong_name_sunshineX__a_mapX0followedBy_weight_meanX_b__a_0followedBy_c__c_filterXweight_whereXgteXbXXX_outV_dX_selectXdX_byXnameX() { return g.V().match( as("a").has("song", "name", "HERE COMES SUNSHINE"), as("a").map(inE("followedBy").values("weight").mean()).as("b"), as("a").inE("followedBy").as("c"), as("c").filter(values("weight").where(P.gte("b"))).outV().as("d")). <String>select("d").by("name"); }