本文整理汇总了Java中org.apache.tinkerpop.gremlin.structure.Graph.traversal方法的典型用法代码示例。如果您正苦于以下问题:Java Graph.traversal方法的具体用法?Java Graph.traversal怎么用?Java Graph.traversal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.tinkerpop.gremlin.structure.Graph
的用法示例。
在下文中一共展示了Graph.traversal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.tinkerpop.gremlin.structure.Graph; //导入方法依赖的package包/类
public static void main(String[] args) {
// Create a new TinkerGraph and load some test data. The Graph instance is typically named "graph" as a
// variable name. You will see this pattern consistently in TinkerPop documentation, the mailing list, etc.
Graph graph = TinkerGraph.open();
loadData(graph);
// Create a GraphTraversalSource instance that is used to query the data in the Graph instance. This variable
// is typically denoted as "g". In TinkerPop documentation you can always count on references to "g" as
// being a object of this type.
GraphTraversalSource g = graph.traversal();
Vertex fromNode = findByName(g, "marko");
Vertex toNode = findByName(g, "peter");
List list = calculateShortestPathBetween(g, fromNode, toNode);
System.out.println(list.toString());
System.exit(0);
}
示例2: shouldSupportFindDocuments
import org.apache.tinkerpop.gremlin.structure.Graph; //导入方法依赖的package包/类
@Test
public void shouldSupportFindDocuments() throws Exception {
final Graph graph = TinkerFactory.createModern();
final GraphTraversalSource g = graph.traversal(GraphTraversalSource.class);
final MongoDBTraversalSource db = graph.traversal(MongoDBTraversalSource.class);
// test find(name,marko)
assertEquals(
parser.parse("{\"~label\":\"person\",\"created\":{\"~label\":\"software\",\"~id\":3,\"name\":\"lop\",\"lang\":\"java\"}," +
"\"~id\":1,\"name\":\"marko\",\"age\":29,\"knows\":[{\"~label\":\"person\",\"~id\":2,\"name\":\"vadas\",\"age\":27}," +
"{\"~label\":\"person\",\"created\":{\"~label\":\"software\",\"~id\":5,\"name\":\"ripple\",\"lang\":\"java\"}," +
"\"~id\":4,\"name\":\"josh\",\"age\":32},{\"~label\":\"person\",\"created\":{\"~label\":\"software\",\"~id\":3,\"name\":\"lop\",\"lang\":\"java\"}," +
"\"~id\":4,\"name\":\"josh\",\"age\":32}]}"),
parser.parse(db.find("{ \"name\": \"marko\" }").next().toString()));
compareQueryTraversalSegment(g.V().has("age", P.gt(30)), db.find("{\"age\" : {\"$gt\" : 30}}"));
compareQueryTraversalSegment(g.V().has("name", "vadas").has("age", 27), db.find("{\"age\" : 27, \"name\":\"vadas\"}"));
}
示例3: generate
import org.apache.tinkerpop.gremlin.structure.Graph; //导入方法依赖的package包/类
private static void generate(final Graph graph) {
final int size = 100;
final List<Object> ids = new ArrayList<>();
final Vertex v = graph.addVertex("sin", 0.0f, "cos", 1.0f, "ii", 0f);
ids.add(v.id());
final GraphTraversalSource g = graph.traversal();
final Random rand = new Random();
for (int ii = 1; ii < size; ii++) {
final Vertex t = graph.addVertex("ii", ii, "sin", Math.sin(ii / 5.0f), "cos", Math.cos(ii / 5.0f));
final Vertex u = g.V(ids.get(rand.nextInt(ids.size()))).next();
t.addEdge("linked", u);
ids.add(u.id());
ids.add(v.id());
}
}
示例4: benchmarkStandardTraversals
import org.apache.tinkerpop.gremlin.structure.Graph; //导入方法依赖的package包/类
@Test
@Ignore
public void benchmarkStandardTraversals() throws Exception {
Graph graph = TinkerGraph.open();
GraphTraversalSource g = graph.traversal();
graph.io(GraphMLIo.build()).readGraph("data/grateful-dead.xml");
final List<Supplier<Traversal>> traversals = Arrays.asList(
() -> g.V().outE().inV().outE().inV().outE().inV(),
() -> g.V().out().out().out(),
() -> g.V().out().out().out().path(),
() -> g.V().repeat(out()).times(2),
() -> g.V().repeat(out()).times(3),
() -> g.V().local(out().out().values("name").fold()),
() -> g.V().out().local(out().out().values("name").fold()),
() -> g.V().out().map(v -> g.V(v.get()).out().out().values("name").toList())
);
traversals.forEach(traversal -> {
logger.info("\nTESTING: {}", traversal.get());
for (int i = 0; i < 7; i++) {
final long t = System.currentTimeMillis();
traversal.get().iterate();
System.out.print(" " + (System.currentTimeMillis() - t));
}
});
}
示例5: testPlay6
import org.apache.tinkerpop.gremlin.structure.Graph; //导入方法依赖的package包/类
@Test
@Ignore
public void testPlay6() throws Exception {
final Graph graph = TinkerGraph.open();
final GraphTraversalSource g = graph.traversal();
for (int i = 0; i < 1000; i++) {
graph.addVertex(T.label, "person", T.id, i);
}
graph.vertices().forEachRemaining(a -> {
graph.vertices().forEachRemaining(b -> {
if (a != b) {
a.addEdge("knows", b);
}
});
});
graph.vertices(50).next().addEdge("uncle", graph.vertices(70).next());
logger.info(TimeUtil.clockWithResult(500, () -> g.V().match(as("a").out("knows").as("b"), as("a").out("uncle").as("b")).toList()).toString());
}
示例6: shouldSupportHadoopGraphOLTP
import org.apache.tinkerpop.gremlin.structure.Graph; //导入方法依赖的package包/类
@Test
public void shouldSupportHadoopGraphOLTP() {
final Configuration configuration = new BaseConfiguration();
configuration.setProperty("spark.master", "local[4]");
configuration.setProperty("spark.serializer", GryoSerializer.class.getCanonicalName());
configuration.setProperty(Graph.GRAPH, HadoopGraph.class.getName());
configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_READER, ExampleInputRDD.class.getCanonicalName());
configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_WRITER, GryoOutputFormat.class.getCanonicalName());
configuration.setProperty(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION, TestHelper.makeTestDataDirectory(this.getClass(), "shouldSupportHadoopGraphOLTP"));
configuration.setProperty(Constants.GREMLIN_HADOOP_JARS_IN_DISTRIBUTED_CACHE, false);
////////
Graph graph = GraphFactory.open(configuration);
GraphTraversalSource g = graph.traversal(); // OLTP;
assertEquals("person", g.V().has("age", 29).next().label());
assertEquals(Long.valueOf(4), g.V().count().next());
assertEquals(Long.valueOf(0), g.E().count().next());
assertEquals(Long.valueOf(2), g.V().has("age", P.gt(30)).count().next());
}
示例7: shouldSupportInsertDocuments
import org.apache.tinkerpop.gremlin.structure.Graph; //导入方法依赖的package包/类
@Test
public void shouldSupportInsertDocuments() throws Exception {
final Graph graph = TinkerFactory.createModern();
final GraphTraversalSource g = graph.traversal(GraphTraversalSource.class);
final MongoDBTraversalSource db = graph.traversal(MongoDBTraversalSource.class);
System.out.println(db.insertOne("{\"name\" : \"stephen\", \"~label\":\"person\", \"hobbies\":[\"art\",\"emails\",\"lame stuff\"], " +
"\"created\" : {\"name\":\"Gremlin DSL\"}," +
"\"likes\" : [{\"name\":\"Bob\", \"~label\":\"android\"},{\"name\":\"marko\",\"~id\":1}]}").toList());
System.out.println(g.E().project("a", "b", "c").by(outV().values("name")).by(T.label).by(inV().values("name")).toList());
System.out.println("##########");
System.out.println(db.find("{\"name\" : \"stephen\"}").next());
}
示例8: testPlay8
import org.apache.tinkerpop.gremlin.structure.Graph; //导入方法依赖的package包/类
@Test
@Ignore
public void testPlay8() throws Exception {
Graph graph = TinkerFactory.createModern();
GraphTraversalSource g = graph.traversal();
System.out.println(g.withSack(1).inject(1).repeat(__.sack((BiFunction)sum).by(__.constant(1))).times(10).emit().math("sin _").by(sack()).toList());
}
示例9: testPlayDK
import org.apache.tinkerpop.gremlin.structure.Graph; //导入方法依赖的package包/类
@Test
@Ignore
public void testPlayDK() throws Exception {
Graph graph = TinkerGraph.open();
GraphTraversalSource g = graph.traversal();
graph.io(GraphMLIo.build()).readGraph("/projects/apache/tinkerpop/data/grateful-dead.xml");
System.out.println(g.V().filter(outE("sungBy").count().is(0)).explain());
System.out.println(g.V().filter(outE("sungBy").count().is(lt(1))).explain());
System.out.println(g.V().filter(outE("sungBy").count().is(1)).explain());
}
示例10: traversal
import org.apache.tinkerpop.gremlin.structure.Graph; //导入方法依赖的package包/类
@Override
public GraphTraversalSource traversal(final Graph graph) {
if ((Boolean) graph.configuration().getProperty("skipTest"))
return graph.traversal();
//throw new VerificationException("This test current does not work with Gremlin-Python", EmptyTraversal.instance());
else {
final GraphTraversalSource g = graph.traversal();
return g.withStrategies(new TranslationStrategy(g, new GryoTranslator<>(JavaTranslator.of(g))));
}
}
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:11,代码来源:TinkerGraphGryoTranslatorProvider.java
示例11: traversal
import org.apache.tinkerpop.gremlin.structure.Graph; //导入方法依赖的package包/类
@Override
public GraphTraversalSource traversal(final Graph graph) {
if ((Boolean) graph.configuration().getProperty("skipTest"))
return graph.traversal();
//throw new VerificationException("This test current does not work with Gremlin-Python", EmptyTraversal.instance());
else {
final GraphTraversalSource g = graph.traversal();
return g.withStrategies(new TranslationStrategy(g, new GraphSONTranslator<>(JavaTranslator.of(g))));
}
}
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:11,代码来源:TinkerGraphGraphSONTranslatorProvider.java
示例12: DataStore
import org.apache.tinkerpop.gremlin.structure.Graph; //导入方法依赖的package包/类
DataStore(final Graph graph,
final boolean readOnly,
final Function<String, GraphIndex> indexFactory,
final SailChangedHelper sailChangedHelper) {
this.graph = graph;
this.traversal = graph.traversal();
this.readOnly = readOnly;
this.sailChangedHelper = sailChangedHelper;
valueIndex = indexFactory.apply(Schema.VertexProperties.VALUE);
valueIndex.initialize();
}
示例13: setup
import org.apache.tinkerpop.gremlin.structure.Graph; //导入方法依赖的package包/类
@BeforeClass
public void setup() throws Exception {
this.subjectRepository = new GraphSubjectRepository();
Graph graph = TitanFactory.build().set("storage.backend", "inmemory").open();
GraphConfig.createSchemaElements(graph);
this.graphTraversalSource = graph.traversal();
this.subjectRepository.setGraphTraversal(this.graphTraversalSource);
}
示例14: traversal
import org.apache.tinkerpop.gremlin.structure.Graph; //导入方法依赖的package包/类
@Override
public GraphTraversalSource traversal(final Graph graph) {
return RANDOM.nextBoolean() ?
RANDOM.nextBoolean() ?
graph.traversal(GraphTraversalSource.build().engine(ComputerTraversalEngine.build().computer(SparkGraphComputer.class).workers(RANDOM.nextInt(3) + 1))) :
graph.traversal().withComputer(Computer.compute(SparkGraphComputer.class).workers(RANDOM.nextInt(3) + 1)) :
RANDOM.nextBoolean() ?
graph.traversal(GraphTraversalSource.computer(SparkGraphComputer.class)) :
graph.traversal().withComputer();
}
示例15: dump
import org.apache.tinkerpop.gremlin.structure.Graph; //导入方法依赖的package包/类
/**
* Helper to a graph to standard output.
*/
// TODO Make this more configurable?
public static void dump(Graph graph) {
GraphTraversalSource g = graph.traversal();
PrintStream out = System.out;
// TODO This isn't the greatest output, but somewhat useful for small graphs..
g.V()
.order().by(id().map(Objects::toString))
.valueMap(true)
.forEachRemaining(valueMap -> {
// TODO Why was this needed?
TreeMap<String, Object> sortedValueMap = new TreeMap<>();
for (Map.Entry<?, ?> e : ((Map<?, ?>) valueMap).entrySet()) {
sortedValueMap.put(e.getKey().toString(), e.getValue());
}
out.println("{");
sortedValueMap.forEach((k, v) -> out.format(" %s = %s%n", k, v));
out.println("}");
out.println();
});
g.E().forEachRemaining(e -> {
out.format("[%s] %s --%s--> %s%n", e.id(), e.outVertex().id(), e.label(), e.inVertex().id());
});
}