简体   繁体   English

根据顶点属性在Tinkerpop3中创建边?

[英]Creating edges in Tinkerpop3 based on vertex properties?

I'm working to migrate information from another database to a Tinkerpop database, using TinkerPop3 Java. 我正在使用TinkerPop3 Java将信息从另一个数据库迁移到Tinkerpop数据库。 I have a large number of ids stored in a single vertex, which I need to transform into an edge between two vertices. 我在单个顶点中存储了大量ID,我需要将其转换为两个顶点之间的边。

Let's say I run the following code to create the Modern toy graph, and add a property "friend" of josh, with the corresponding name of his friend "marko". 假设我运行以下代码来创建Modern玩具图,并添加josh的属性“ friend”,以及其朋友“ marko”的相应名称。

graph = TinkerFactory.createModern()
g = graph.traversal()
g.V().has("name","josh").property("friend","marko")

What I want is a query that will programmatically find all vertices with the property "friend", find the corresponding vertex whose name matches, and create an edge labeled "friends" between them. 我想要的是一个查询,该查询将以编程方式找到具有“ friend”属性的所有顶点,找到名称匹配的相应顶点,并在它们之间创建一个标记为“ friends”的边。 Ideally this would be a single query, as I have to scan a large number of vertices. 理想情况下,这将是一个查询,因为我必须扫描大量的顶点。

The following query will find the vertices that have friends and the names of those friends, but I don't know how to find the vertex with the matching name without breaking the search into multiple queries. 以下查询将查找具有朋友的顶点以及这些朋友的名字,但是我不知道如何在不将搜索分为多个查询的情况下找到具有匹配名称的顶点。

g.V().has("friend").as("a").values("friend").as("b").select("a","b")

Thanks!! 谢谢!!

I found the following worked: 我发现以下工作:

g.V().has("friend").as("x").
V().has("name").where(eq("x")).by("name").by("friend").
as("y").
addE("friends").from("x").to("y")

inspired from the answer found here: https://groups.google.com/forum/#!msg/gremlin-users/l-Xtknn3Loo/0SljkNFiDQAJ;context-place=forum/gremlin-users 从此处找到的答案中得到启发: https : //groups.google.com/forum/#!msg/gremlin-users/l-Xtknn3Loo/0SljkNFiDQAJ;context-place=forum/gremlin-users

Explanation: The query is finding a series of nodes with friends, labelling them "x". 说明:该查询正在查找一系列带有朋友的节点,并将其标记为“ x”。 Then it looks at all nodes with names, and labels them as "y" if they match - that is, if their name matches the friend property of "x". 然后,它将查看所​​有具有名称的节点,如果它们匹配则将它们标记为“ y”-也就是说,如果它们的名称与“ x”的好友属性匹配。 (That's what the two .by() statements are doing). (这就是两个.by()语句所做的事情)。 Then it creates an edge between them. 然后在它们之间创建一条边缘。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM