gremlin

Jagged Result Array Gremlin Query

喜夏-厌秋 提交于 2019-12-01 12:24:39
问题 Please may you help me to write a query that returns each source vertex in my traversal along with its associated edges and vertices as arrays on each such source vertex? In short, I need a result set comprising an array of 3-tuples with item 1 of each tuple being the source vertex and items 2 and 3 being the associated arrays. Thanks! EDIT 1: Expanded on the graph data and added my current problem query. EDIT 2: Improved Gremlin sample graph code (apologies, didn't think anyone would

Query to check if there is a cycle in a graph with edges visited only once

无人久伴 提交于 2019-12-01 11:18:19
How to write an query runs on my graph, that outputs 'false' if there is NO path traversing through each edge only once and return to the starting point. I was using the following sample graph : g = TinkerGraph.open().traversal() g.addV().property(id, 'blue').as('b'). addV().property(id, 'orange').as('o'). addV().property(id, 'red').as('r'). addV().property(id, 'white').as('w'). addE('bridge').from('w').to('b'). addE('bridge').from('w').to('o'). addE('bridge').from('w').to('r'). addE('bridge').from('w').to('r'). addE('bridge').from('o').to('b'). addE('bridge').from('o').to('b'). addE('bridge')

Query to check if there is a cycle in a graph with edges visited only once

百般思念 提交于 2019-12-01 08:20:32
问题 How to write an query runs on my graph, that outputs 'false' if there is NO path traversing through each edge only once and return to the starting point. 回答1: I was using the following sample graph: g = TinkerGraph.open().traversal() g.addV().property(id, 'blue').as('b'). addV().property(id, 'orange').as('o'). addV().property(id, 'red').as('r'). addV().property(id, 'white').as('w'). addE('bridge').from('w').to('b'). addE('bridge').from('w').to('o'). addE('bridge').from('w').to('r'). addE(

Gremlin: What's an efficient way of finding an edge between two vertices?

女生的网名这么多〃 提交于 2019-12-01 06:01:03
问题 So obviously, a straight forward way to find an edge between two vertices is to: graph.traversal().V(outVertex).bothE(edgeLabel).filter(__.otherV().is(inVertex)) I feel that filter step will have to iterate through all edges making really slow for some applications with a lot of edges. Another way could be: traversal = graph.traversal() .V(outVertex) .bothE(edgeLabel) .as("x") .otherV() .is(outVertex) // uses index? .select("x"); I'm assuming the second approach could be much faster since it

how to escape quotes in gremlin queries

匆匆过客 提交于 2019-12-01 05:32:47
I have this query and as you firstName contains single quote Anthony O'Neil :> g.addV('person') .property('firstName', 'Anthony O'Neil') .property('lastName', 'Andersen') .property('age', 44) Any Ideas how to escape it? Escape the apostrophe using \ So your Gremlin becomes: :> g.addV('person') .property('firstName', 'Anthony O\'Neil') .property('lastName', 'Andersen') .property('age', 44) Found out the answer for encoding use this: encodeURIComponent("Anthony O'Neil").replace(/[!'()*]/g, escape) and the output is: Anthony%20O%27Neil for decoding use this: decodeURIComponent("Anthony%20O%27Neil

how to escape quotes in gremlin queries

*爱你&永不变心* 提交于 2019-12-01 03:19:11
问题 I have this query and as you firstName contains single quote Anthony O'Neil :> g.addV('person') .property('firstName', 'Anthony O'Neil') .property('lastName', 'Andersen') .property('age', 44) Any Ideas how to escape it? 回答1: Escape the apostrophe using \ So your Gremlin becomes: :> g.addV('person') .property('firstName', 'Anthony O\'Neil') .property('lastName', 'Andersen') .property('age', 44) 回答2: Found out the answer for encoding use this: encodeURIComponent("Anthony O'Neil").replace(/[!'()

Breadth First enumeration in Gremlin

别来无恙 提交于 2019-12-01 01:34:38
I'm trying to get breadth first enumeration working with Gremlin, however I'm having trouble finding a way to output all the steps observed during the enumeration. I can only print out the result of the last iteration. My question would be, given a starting node like this, how can I follow all paths (without knowing the overall depth) using Gremlin and print out everything I find along the way? study=g.v('myId') I have tried the scatter approach, looping approach (although both seem to require knowledge about the actual length of the path beforehand if I understand correctly) Many thanks! You

How to select optional graph structures with Gremlin?

天大地大妈咪最大 提交于 2019-12-01 00:57:10
I am using Gremlin to query a graph stored in TitanDB. The graph contains user vertices with properties, e.g., "description", and edges denoting relationships between users. I want to use Gremlin to obtain 1) users by properties and 2) possible relationships to other users. I can use, for example, the following query to obtain all users whose description contains the word 'developer' and the edges with label 'relationship' originating from or targeting these users: g.V('description',CONTAINS,'developer').as('user').bothE.as('relationship').select So far, so good. The problem is, however, that

How to select optional graph structures with Gremlin?

三世轮回 提交于 2019-11-30 19:32:55
问题 I am using Gremlin to query a graph stored in TitanDB. The graph contains user vertices with properties, e.g., "description", and edges denoting relationships between users. I want to use Gremlin to obtain 1) users by properties and 2) possible relationships to other users. I can use, for example, the following query to obtain all users whose description contains the word 'developer' and the edges with label 'relationship' originating from or targeting these users: g.V('description',CONTAINS,

Why do you need to fold/unfold using coalesce for a conditional insert?

左心房为你撑大大i 提交于 2019-11-30 19:13:34
I'm trying to understand how this pattern for a conditional insert works: g.V() .hasLabel('person').has('name', 'John') .fold() .coalesce( __.unfold(), g.addV('person').property('name', 'John') ).next(); What is the purpose of the fold/unfold? Why are these necessary, and why does this not work: g.V() .coalesce( __.hasLabel('person').has('name', 'John'), g.addV('person').property('name', 'John') ).next(); The fold-then-unfold pattern seems redundant to me and yet the above does not yield the same result. Consider what happens when you just do the following: gremlin> g = TinkerFactory