本文整理了Java中org.apache.tinkerpop.gremlin.structure.Graph.traversal()
方法的一些代码示例,展示了Graph.traversal()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Graph.traversal()
方法的具体详情如下:
包路径:org.apache.tinkerpop.gremlin.structure.Graph
类名称:Graph
方法名:traversal
[英]Generate a reusable GraphTraversalSource instance. The GraphTraversalSource provides methods for creating org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal instances.
[中]生成可重用的GraphTraversalSource实例。GraphTraversalSource提供了创建组织的方法。阿帕奇。小炉匠。小精灵。过程穿越。dsl。图表GraphTraversal实例。
代码示例来源:origin: JanusGraph/janusgraph
@Override
public GraphTraversalSource traversal(final Graph graph) {
return graph.traversal();
}
代码示例来源:origin: JanusGraph/janusgraph
@Override
public GraphTraversalSource traversal(final Graph graph, final TraversalStrategy... strategies) {
return graph.traversal().withStrategies(strategies);
}
代码示例来源:origin: JanusGraph/janusgraph
private void updateTraversalSource(String graphName, Graph graph, GremlinExecutor gremlinExecutor,
JanusGraphManager graphManager){
gremlinExecutor.getScriptEngineManager().put(graphName, graph);
String traversalName = graphName + "_traversal";
TraversalSource traversalSource = graph.traversal();
gremlinExecutor.getScriptEngineManager().put(traversalName, traversalSource);
graphManager.putTraversalSource(traversalName, traversalSource);
}
代码示例来源:origin: apache/tinkerpop
/**
* Create a {@link GraphTraversalSource} from a {@link Graph} instance. The default implementation does not
* use {@link GraphComputer} so providers should override as necessary if their implementation is testing
* something that requires a different engine type, like {@link GraphComputer}.
*/
public default GraphTraversalSource traversal(final Graph graph) {
return graph.traversal();
}
代码示例来源:origin: thinkaurelius/titan
@Test
public void testReadWideVertexWithManyProperties() {
int numProps = 1 << 16;
long numV = 1;
mgmt.makePropertyKey("p").cardinality(Cardinality.LIST).dataType(Integer.class).make();
mgmt.commit();
finishSchema();
for (int j = 0; j < numV; j++) {
Vertex v = graph.addVertex();
for (int i = 0; i < numProps; i++) {
v.property("p", i);
}
}
graph.tx().commit();
assertEquals(numV, (long) graph.traversal().V().count().next());
Map<String, Object> propertiesOnVertex = graph.traversal().V().valueMap().next();
List<?> valuesOnP = (List)propertiesOnVertex.values().iterator().next();
assertEquals(numProps, valuesOnP.size());
Graph g = GraphFactory.open("target/test-classes/cassandra-read.properties");
GraphTraversalSource t = g.traversal(GraphTraversalSource.computer(SparkGraphComputer.class));
assertEquals(numV, (long) t.V().count().next());
propertiesOnVertex = t.V().valueMap().next();
valuesOnP = (List)propertiesOnVertex.values().iterator().next();
assertEquals(numProps, valuesOnP.size());
}
代码示例来源:origin: apache/tinkerpop
/**
* Converts SPARQL to a Gremlin traversal.
*
* @param graph the {@link Graph} instance to execute the traversal from
* @param sparqlQuery the query to compile to Gremlin
*/
public static GraphTraversal<Vertex, ?> compile(final Graph graph, final String sparqlQuery) {
return compile(graph.traversal(), sparqlQuery);
}
代码示例来源:origin: thinkaurelius/titan
@Test
public void testReadGraphOfTheGods() {
GraphOfTheGodsFactory.load(graph, null, true);
assertEquals(12L, (long) graph.traversal().V().count().next());
Graph g = GraphFactory.open("target/test-classes/cassandra-read.properties");
GraphTraversalSource t = g.traversal(GraphTraversalSource.computer(SparkGraphComputer.class));
assertEquals(12L, (long) t.V().count().next());
}
代码示例来源:origin: apache/tinkerpop
@Setup(Level.Invocation)
public void prepare() {
graph = TinkerGraph.open();
g = graph.traversal();
}
}
代码示例来源:origin: apache/tinkerpop
@Test(expected = IllegalArgumentException.class)
public void shouldNotAllowBytecodeEvalWithInvalidBinding() throws Exception {
final GremlinScriptEngine scriptEngine = manager.getEngineByName(ENGINE_TO_TEST);
final Graph graph = EmptyGraph.instance();
final GraphTraversalSource g = graph.traversal();
// purposefully use "x" to match the name of the traversal source binding for "x" below and
// thus tests the alias added for "x"
final GraphTraversal t = getTraversalWithLambda(g);
final Bindings bindings = new SimpleBindings();
bindings.put("z", g);
bindings.put("x", "invalid-binding-for-x-given-x-should-be-traversal-source");
scriptEngine.eval(t.asAdmin().getBytecode(), bindings, "x");
}
代码示例来源:origin: apache/tinkerpop
@Test(expected = IllegalArgumentException.class)
public void shouldNotAllowBytecodeEvalWithAliasInBindings() throws Exception {
final GremlinScriptEngine scriptEngine = manager.getEngineByName(ENGINE_TO_TEST);
final Graph graph = EmptyGraph.instance();
final GraphTraversalSource g = graph.traversal();
// purposefully use "x" to match the name of the traversal source binding for "x" below and
// thus tests the alias added for "x"
final GraphTraversal t = getTraversalWithLambda(g);
final Bindings bindings = new SimpleBindings();
bindings.put("x", g);
bindings.put(GremlinScriptEngine.HIDDEN_G, g);
scriptEngine.eval(t.asAdmin().getBytecode(), bindings, "x");
}
代码示例来源:origin: apache/tinkerpop
@Test(expected = IllegalArgumentException.class)
public void shouldNotAllowBytecodeEvalWithMissingBinding() throws Exception {
final GremlinScriptEngine scriptEngine = manager.getEngineByName(ENGINE_TO_TEST);
final Graph graph = EmptyGraph.instance();
final GraphTraversalSource g = graph.traversal();
// purposefully use "x" to match the name of the traversal source binding for "x" below and
// thus tests the alias added for "x"
final GraphTraversal t = getTraversalWithLambda(g);
final Bindings bindings = new SimpleBindings();
bindings.put("z", g);
scriptEngine.eval(t.asAdmin().getBytecode(), bindings, "x");
}
代码示例来源:origin: apache/tinkerpop
@Test(expected = IllegalArgumentException.class)
public void shouldNotAllowBytecodeEvalWithAliasAsTraversalSource() throws Exception {
final GremlinScriptEngine scriptEngine = manager.getEngineByName(ENGINE_TO_TEST);
final Graph graph = EmptyGraph.instance();
final GraphTraversalSource g = graph.traversal();
// purposefully use "x" to match the name of the traversal source binding for "x" below and
// thus tests the alias added for "x"
final GraphTraversal t = getTraversalWithLambda(g);
final Bindings bindings = new SimpleBindings();
bindings.put("x", g);
scriptEngine.eval(t.asAdmin().getBytecode(), bindings, GremlinScriptEngine.HIDDEN_G);
}
代码示例来源:origin: apache/tinkerpop
@Test
public void shouldEvalBytecode() throws Exception {
final GremlinScriptEngine scriptEngine = manager.getEngineByName(ENGINE_TO_TEST);
final Graph graph = EmptyGraph.instance();
final GraphTraversalSource g = graph.traversal();
// purposefully use "x" to match the name of the traversal source binding for "x" below and
// thus tests the alias added for "x"
final GraphTraversal t = getTraversalWithLambda(g);
final Bindings bindings = new SimpleBindings();
bindings.put("x", g);
final Traversal evald = scriptEngine.eval(t.asAdmin().getBytecode(), bindings, "x");
assertTraversals(t, evald);
assertThat(manager.getBindings().containsKey(GremlinScriptEngine.HIDDEN_G), is(false));
}
代码示例来源:origin: apache/tinkerpop
@Test
@LoadGraphWith(MODERN)
public void shouldExecutePageRankWithEnergyConservation() throws Exception {
final ComputerResult result = graph.compute(graphProvider.getGraphComputer(graph).getClass()).program(PageRankVertexProgram.build().create(graph)).submit().get();
final double sum = result.graph().traversal().V().values(PageRankVertexProgram.PAGE_RANK).sum().next().doubleValue();
assertEquals(1.0d, sum, 0.01d);
}
}
代码示例来源:origin: apache/tinkerpop
@Test
@FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
public void shouldGenerateDefaultIdOnGraphAddVWithGeneratedDefaultId() throws Exception {
final ElementIdStrategy strategy = ElementIdStrategy.build().create();
final GraphTraversalSource sg = create(strategy);
final Vertex v = sg.addV().property("name", "stephen").next();
assertEquals("stephen", v.value("name"));
final Traversal t1 = graph.traversal().V(v);
t1.asAdmin().applyStrategies();
logger.info(t1.toString());
final Traversal t2 = sg.V(v);
t2.asAdmin().applyStrategies();
logger.info(t2.toString());
assertNotNull(UUID.fromString(sg.V(v).id().next().toString()));
}
代码示例来源:origin: apache/tinkerpop
@Test
@LoadGraphWith(MODERN)
public void shouldSupportMultipleScopes() throws ExecutionException, InterruptedException {
final ComputerResult result = graphProvider.getGraphComputer(graph).program(new MultiScopeVertexProgram()).submit().get();
assertEquals(result.graph().traversal().V().has("name", "josh").next().property(MultiScopeVertexProgram.MEMORY_KEY).value(), 0L);
assertEquals(result.graph().traversal().V().has("name", "lop").next().property(MultiScopeVertexProgram.MEMORY_KEY).value(), 1L);
assertEquals(result.graph().traversal().V().has("name", "ripple").next().property(MultiScopeVertexProgram.MEMORY_KEY).value(), 1L);
assertEquals(result.graph().traversal().V().has("name", "marko").next().property(MultiScopeVertexProgram.MEMORY_KEY).value(), 2L);
}
代码示例来源:origin: apache/tinkerpop
private GraphTraversal<Vertex, Vertex> runMPTest(final Direction direction) throws Exception {
final VertexProgramR svp = VertexProgramR.build().direction(direction).create();
final ComputerResult result = graphProvider.getGraphComputer(graph).program(svp).vertices(__.hasLabel(VertexProgramR.VERTEX_LABEL)).submit().get();
return result.graph().traversal().V().hasLabel(VertexProgramR.VERTEX_LABEL);
}
代码示例来源:origin: apache/tinkerpop
@Test
@LoadGraphWith(MODERN)
public void shouldSupportMultipleScopesWithEdgeFunction() throws ExecutionException, InterruptedException {
final ComputerResult result = graphProvider.getGraphComputer(graph).program(new MultiScopeVertexWithEdgeFunctionProgram()).submit().get();
assertEquals(result.graph().traversal().V().has("name", "josh").next().property(MultiScopeVertexProgram.MEMORY_KEY).value(), 0L);
assertEquals(result.graph().traversal().V().has("name", "lop").next().property(MultiScopeVertexProgram.MEMORY_KEY).value(), 4L);
assertEquals(result.graph().traversal().V().has("name", "ripple").next().property(MultiScopeVertexProgram.MEMORY_KEY).value(), 10L);
assertEquals(result.graph().traversal().V().has("name", "marko").next().property(MultiScopeVertexProgram.MEMORY_KEY).value(), 20L);
}
代码示例来源:origin: apache/tinkerpop
@Test
@LoadGraphWith(MODERN)
@IgnoreEngine(TraversalEngine.Type.COMPUTER) // we can't modify the graph in computer mode
public void shouldProperlyHandleMetaProperties() throws Exception {
graph.traversal().V().has("name", "marko").properties("name").property("alias", "okram").iterate();
final BulkLoaderVertexProgram blvp = BulkLoaderVertexProgram.build()
.userSuppliedIds(true)
.writeGraph(getWriteGraphConfiguration()).create(graph);
graphProvider.getGraphComputer(graph).workers(1).program(blvp).submit().get();
assertGraphEquality(graph, getWriteGraph());
}
代码示例来源:origin: JanusGraph/janusgraph
private void testOr(final Graph aGraph) {
final GraphTraversalSource g = aGraph.traversal();
final Vertex hiro = g.addV().property("name", "Hiro").property("age", 2).property("length", 90).next();
final Vertex totoro = g.addV().property("name", "Totoro").property("age", 1).next();
内容来源于网络,如有侵权,请联系作者删除!