本文整理汇总了Java中org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource类的典型用法代码示例。如果您正苦于以下问题:Java GraphTraversalSource类的具体用法?Java GraphTraversalSource怎么用?Java GraphTraversalSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GraphTraversalSource类属于org.apache.tinkerpop.gremlin.process.traversal.dsl.graph包,在下文中一共展示了GraphTraversalSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: apply
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; //导入依赖的package包/类
@Override
@SneakyThrows
public GraphTraversal<Element, Element> apply(GraphTraversalSource g) {
GraphTraversal traversal = g.addV(element.label());
if (element.id() != null && HasFeature.Verifier.of(g)
.verify(supportsUserSuppliedIds(element))) {
traversal.property(T.id, element.id());
}
for (Field field : keyFields(element)) {
String key = propertyKey(field);
Object value = propertyValue(field, element);
if (isMissing(value)) {
throw org.apache.tinkerpop.gremlin.object.structure.Element.Exceptions.requiredKeysMissing(
element.getClass(), key);
}
traversal.property(key, value);
}
return traversal;
}
示例2: identifyRootProject
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; //导入依赖的package包/类
@Test
public void identifyRootProject() throws IOException {
InputStream bdio = new NamedGraphBuilder()
.project(p -> {})
.build();
Consumer<GraphTopology.Builder> config = b -> b.metadataLabel(TT.Metadata).rootLabel(TT.root).implicitKey(TT.implicit);
graph.io(BlackDuckIo.build().onGraphTopology(config)).readGraph(bdio);
ReadGraphContext context = new GraphContextFactoryBuilder().onGraphTopology(config).create().forBdioReadingInto(graph);
new BlackDuckIoOperations.IdentifyRootOperation(context).run();
GraphTraversalSource g = graph.traversal();
List<Vertex> roots = g.V().hasLabel(TT.Metadata).out(TT.root).toList();
assertThat(roots).hasSize(1);
assertThat(roots.get(0).label()).isEqualTo(Bdio.Class.Project.name());
}
示例3: main
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; //导入依赖的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);
}
示例4: shouldThrowExceptionOnEInDifferentPartition
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; //导入依赖的package包/类
@Test
@FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
public void shouldThrowExceptionOnEInDifferentPartition() {
final PartitionStrategy partitionStrategyAA = PartitionStrategy.build()
.partitionKey(partition).writePartition("A").addReadPartition("A").create();
final GraphTraversalSource sourceAA = create(partitionStrategyAA);
final PartitionStrategy partitionStrategyA = PartitionStrategy.build()
.partitionKey(partition).writePartition("A").create();
final GraphTraversalSource sourceA = create(partitionStrategyA);
final Vertex vA = sourceAA.addV().property("any", "a").next();
final Edge e = sourceAA.withSideEffect("vA", vA).V(vA.id()).addE("knows").to("vA").next();
assertEquals(e.id(), g.E(e.id()).id().next());
try {
sourceA.E(e.id()).next();
fail("Edge should not be in this partition");
} catch (Exception ex) {
final Exception expected = FastNoSuchElementException.instance();
assertEquals(expected.getClass(), ex.getClass());
}
}
示例5: shouldSerializeToJsonMapWithElementForKey
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; //导入依赖的package包/类
@Test
public void shouldSerializeToJsonMapWithElementForKey() throws Exception {
final TinkerGraph graph = TinkerFactory.createClassic();
final GraphTraversalSource g = graph.traversal();
final Map<Vertex, Integer> map = new HashMap<>();
map.put(g.V().has("name", "marko").next(), 1000);
final ResponseMessage response = convert(map);
assertCommon(response);
final Map<String, Integer> deserializedMap = (Map<String, Integer>) response.getResult().getData();
assertEquals(1, deserializedMap.size());
// with no embedded types the key (which is a vertex) simply serializes out to an id
// {"result":{"1":1000},"code":200,"requestId":"2d62161b-9544-4f39-af44-62ec49f9a595","type":0}
assertEquals(new Integer(1000), deserializedMap.get("1"));
}
示例6: shouldSerializeToMapWithElementForKey
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; //导入依赖的package包/类
@Test
public void shouldSerializeToMapWithElementForKey() throws Exception {
final TinkerGraph graph = TinkerFactory.createClassic();
final GraphTraversalSource g = graph.traversal();
final Map<Vertex, Integer> map = new HashMap<>();
map.put(g.V().has("name", "marko").next(), 1000);
final ResponseMessage response = convertBinary(map);
assertCommon(response);
final Map<Vertex, Integer> deserializedMap = (Map<Vertex, Integer>) response.getResult().getData();
assertEquals(1, deserializedMap.size());
final Vertex deserializedMarko = deserializedMap.keySet().iterator().next();
assertEquals(0, IteratorUtils.count(deserializedMarko.properties()));
assertEquals(1, deserializedMarko.id());
assertEquals("", deserializedMarko.label());
assertEquals(new Integer(1000), deserializedMap.values().iterator().next());
}
示例7: setUp
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; //导入依赖的package包/类
@Before
public void setUp() {
marko = Person.of("marko");
vertex = new DetachedVertex(
1, "person", new HashMap<String, Object>() {
{
put("name", Arrays.asList(new HashMap() {
{
put("value", "marko");
}
}));
}
});
g = mock(GraphTraversalSource.class);
traversal = mock(GraphTraversal.class);
when(g.V()).thenReturn(traversal);
query = new ObjectQuery(g);
}
示例8: shouldSupportFindDocuments
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; //导入依赖的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\"}"));
}
示例9: generate
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; //导入依赖的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());
}
}
示例10: benchmarkStandardTraversals
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; //导入依赖的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));
}
});
}
示例11: testPlay9
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; //导入依赖的package包/类
@Test
@Ignore
public void testPlay9() throws Exception {
Graph graph = TinkerGraph.open();
graph.io(GraphMLIo.build()).readGraph("../data/grateful-dead.xml");
GraphTraversalSource g = graph.traversal().withComputer(Computer.compute().workers(4)).withStrategies(PathRetractionStrategy.instance());
GraphTraversalSource h = graph.traversal().withComputer(Computer.compute().workers(4)).withoutStrategies(PathRetractionStrategy.class);
for (final GraphTraversalSource source : Arrays.asList(g, h)) {
System.out.println(source.V().match(
__.as("a").in("sungBy").as("b"),
__.as("a").in("sungBy").as("c"),
__.as("b").out("writtenBy").as("d"),
__.as("c").out("writtenBy").as("e"),
__.as("d").has("name", "George_Harrison"),
__.as("e").has("name", "Bob_Marley")).select("a").count().profile().next());
}
}
示例12: testPlay6
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; //导入依赖的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());
}
示例13: shouldReturnDetachedElements
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; //导入依赖的package包/类
@Test
public void shouldReturnDetachedElements() {
final Graph graph = TinkerFactory.createModern();
final GraphTraversalSource g = graph.traversal().withComputer().withStrategies(HaltedTraverserStrategy.create(new MapConfiguration(new HashMap<String, Object>() {{
put(HaltedTraverserStrategy.HALTED_TRAVERSER_FACTORY, DetachedFactory.class.getCanonicalName());
}})));
g.V().out().forEachRemaining(vertex -> assertEquals(DetachedVertex.class, vertex.getClass()));
g.V().out().properties("name").forEachRemaining(vertexProperty -> assertEquals(DetachedVertexProperty.class, vertexProperty.getClass()));
g.V().out().values("name").forEachRemaining(value -> assertEquals(String.class, value.getClass()));
g.V().out().outE().forEachRemaining(edge -> assertEquals(DetachedEdge.class, edge.getClass()));
g.V().out().outE().properties("weight").forEachRemaining(property -> assertEquals(DetachedProperty.class, property.getClass()));
g.V().out().outE().values("weight").forEachRemaining(value -> assertEquals(Double.class, value.getClass()));
g.V().out().out().forEachRemaining(vertex -> assertEquals(DetachedVertex.class, vertex.getClass()));
g.V().out().out().path().forEachRemaining(path -> assertEquals(DetachedPath.class, path.getClass()));
g.V().out().pageRank().forEachRemaining(vertex -> assertEquals(DetachedVertex.class, vertex.getClass()));
g.V().out().pageRank().out().forEachRemaining(vertex -> assertEquals(DetachedVertex.class, vertex.getClass()));
// should handle nested collections
g.V().out().fold().next().forEach(vertex -> assertEquals(DetachedVertex.class, vertex.getClass()));
}
示例14: testUpdateAttachedEntity
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; //导入依赖的package包/类
@Test(threadPoolSize = CONCURRENT_TEST_THREAD_COUNT,
invocationCount = CONCURRENT_TEST_INVOCATIONS)
public void testUpdateAttachedEntity() {
ResourceEntity resourceEntity = persistRandomResourcetoZone1AndAssert();
String resourceId = resourceEntity.getResourceIdentifier();
GraphTraversalSource g = this.graphTraversalSource;
GraphTraversal<Vertex, Vertex> traversal = g.V().has(RESOURCE_ID_KEY, resourceId);
assertThat(traversal.hasNext(), equalTo(true));
assertThat(traversal.next().property(RESOURCE_ID_KEY).value(), equalTo(resourceId));
// Update the resource.
String updateJSON = "{\'status':'test'}";
resourceEntity.setAttributesAsJson(updateJSON);
saveWithRetry(this.resourceRepository, resourceEntity, 3);
assertThat(this.resourceRepository.getEntity(TEST_ZONE_1, resourceEntity.getResourceIdentifier())
.getAttributesAsJson(), equalTo(updateJSON));
this.resourceRepository.delete(resourceEntity);
}
示例15: shouldSupportHadoopGraphOLTP
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; //导入依赖的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());
}