gremlin

Recursively query simpler tree-like structures with Gremlin

ぃ、小莉子 提交于 2019-12-02 11:53:11
Consider the following data: g.addV('RootTopic').property('name', 'A').as('A') .addV('RootTopic').property('name', 'M').as('M') .addV('Topic').property('name', 'A1').as('A1') .addV('Topic').property('name', 'A2').as('A2') .addV('Topic').property('name', 'B1').as('B1') .addV('Topic').property('name', 'B2').as('B2') .addV('Topic').property('name', 'N1').as('N1') .addV('Topic').property('name', 'N2').as('N2') .addV('Topic').property('name', 'O1').as('O1') .addE('refines').from('A').to('A1') .addE('refines').from('A').to('A2') .addE('refines').from('A1').to('B1') .addE('refines').from('A1').to('B2

gremlin syntax to calculate Jaccard similarity metric

允我心安 提交于 2019-12-02 11:48:50
I'm interested in calculating the Jaccard similarity metric for all pairs of vertices in a graph that are not directly connected. The Jaccard metric is defined as the norm of the intersection of the neighbors of the two vertices divided by the norm of the union of the same sets. where So far I have been able to get all pairs of nodes not directly connected (only interested in this case for link prediction, if a direct link already exists then I do not need to calculate the Jaccard metric) such that for a pair (x, y) where x not equals y: g.V().as('v1').V().where(neq('v1')).as('v2').filter(__

Gremlin: adding edges between nodes having the same property

烂漫一生 提交于 2019-12-02 10:12:43
问题 I am very new to Gremlin. I am trying to build a graph on DSE graph using Gremlin. I am able to create the vertices: a = graph.addVertex(label, 'label1', 'key', 1) b = graph.addVertex(label, 'label1', 'key', 2) c = graph.addVertex(label, 'label2', 'key', 1) d = graph.addVertex(label, 'label2', 'key', 2) Now i am looking to automatically add edges between two nodes with differents label where the property 'key' matches (i.e create and edge between a and c, and between b and c). I am stuggling

Gremlin: adding edges between nodes having the same property

徘徊边缘 提交于 2019-12-02 05:03:52
I am very new to Gremlin. I am trying to build a graph on DSE graph using Gremlin. I am able to create the vertices: a = graph.addVertex(label, 'label1', 'key', 1) b = graph.addVertex(label, 'label1', 'key', 2) c = graph.addVertex(label, 'label2', 'key', 1) d = graph.addVertex(label, 'label2', 'key', 2) Now i am looking to automatically add edges between two nodes with differents label where the property 'key' matches (i.e create and edge between a and c, and between b and c). I am stuggling to do that. I tried to do the following g.V().hasLabel("label1").sideEffect{g.V().("label2").has("key"

How to collect all vertex and edge properties along path, with Gremlin

会有一股神秘感。 提交于 2019-12-02 02:10:43
问题 Here's a really simple query: g.V('customerId').out().path() The JSON output of this is { "requestId":"96b26c1d-d032-2004-d36e-c700bd6db2a2", "status":{ "message":"", "code":200, "attributes":{ "@type":"g:Map", "@value":[ ] } }, "result":{ "data":{ "@type":"g:List", "@value":[ { "@type":"g:Path", "@value":{ "labels":{ "@type":"g:List", "@value":[ { "@type":"g:Set", "@value":[ ] }, { "@type":"g:Set", "@value":[ ] } ] }, "objects":{ "@type":"g:List", "@value":[ { "@type":"g:Vertex", "@value":{

How to print out Gremlin pipe / traversal results

感情迁移 提交于 2019-12-02 02:01:11
问题 I have the code below in a file named traversal.groovy (which I call from the command line with gremlin -e traversal.groovy ): // Begin traversal.groovy // g = TinkerGraphFactory.createTinkerGraph() v = g.v(1) println v.outE.inV.name // End traversal.groovy // As you can see, it's very basic; but the output is not what I'm looking for. The output is [StartPipe, OutEdgesPipe, InVertexPipe, PropertyPipe(name)] When I run the same code in the gremlin command line, I get what I'm looking for...

Tinkerpop/gremlin merge vertices (and edges)

∥☆過路亽.° 提交于 2019-12-01 23:52:47
Is there an easy way to replace or merge vertices and keep/merge existing edges? Or just manually copy all properties from the vertex and recreate existing edges and all (meta-)properties and then drop the superfluous vertex? Alright, as mentioned in the comments above, you're going to do the matching in OLTP. That means you'll likely have a concrete entry point. Let's make up a simple sample graph: g = TinkerGraph.open().traversal() // Stackoverflow data g.addV("user").property("login", "user3508638").as("a"). addV("user").property("login", "dkuppitz").property("age", 35).as("b"). addV(

Gremlin date filter approach

柔情痞子 提交于 2019-12-01 22:26:04
Is there anyway to query on date in titan/gremlin? e.g. find all results in the last X days Any help would be much appreciated. The best approach is to simply store the date as a Long value and to possibly index upon such a field in an edge such that you could take advantage of limit() , interval , etc. See this Titan wiki page on the topic: https://github.com/thinkaurelius/titan/wiki/Vertex-Centric-Indices It maps to your specific request with a Twitter example where it indexes on time . You could find results based on time by simply calculating milliseconds for "X days" back and then finding

How to remove an edge and add a new edge between two vertices?

≯℡__Kan透↙ 提交于 2019-12-01 18:43:14
问题 I'm trying to drop an edge and add a new edge between two vertices. How do I do that in Tinkerpop3? def user = g.V().has("userId", 'iamuser42').has("tenantId", 'testtenant').hasLabel('User'); user.outE("is_invited_to_join").where(otherV().has("groupId", 'test123')).drop(); def group = g.V().has("groupId", 'test123').has("tenantId", 'testtenant').hasLabel('Group').next(); user.addEdge("is_member_of", group); This is the error I get on gremlin shell: No signature of method: org.apache.tinkerpop

Why does Gremlin JavaScript use “from_” mapping instead of “from”?

Deadly 提交于 2019-12-01 13:42:00
I struggled with this for hours before finding out that you have to use from_ instead of from when using gremlin javascript. After digging through the source code I finally found out that the code is using from_ instead of from (see code ). Since I'm a newbie this comes off as strange because its counterpart to is still to (and not to_ , see code here ) I googled everywhere but couldn't find the reason why this works this way, and feel uneasy about using the underscore version since most of the times underscores denote private methods that users should not really trust. Also, is there an