Ask Your Question
4

What is the method for executing query strings in TinkerGraph?

asked 2023-05-27 00:29:11 +0000

scrum gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-05-27 00:56:02 +0000

huitzilopochtli gravatar image

To execute query strings in TinkerGraph, you can use the gremlin() method provided by the GraphTraversalSource object. This method takes a string parameter representing the Gremlin query to be executed, and returns a GraphTraversal object that can be used to iterate over the results of the query.

Here's an example of how to use the gremlin() method to execute a query in TinkerGraph:

import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource
import org.apache.tinkerpop.gremlin.structure.T
import org.apache.tinkerpop.gremlin.structure.Vertex

// Create a new TinkerGraph instance
def graph = TinkerGraph.open()

// Add some vertices to the graph
def v1 = graph.addVertex(T.label, 'person', 'name', 'Alice', 'age', 30)
def v2 = graph.addVertex(T.label, 'person', 'name', 'Bob', 'age', 40)

// Create a GraphTraversalSource object
def g = graph.traversal()

// Execute a Gremlin query using the gremlin() method
def result = g.gremlin('g.V().hasLabel("person").has("age", gt(35)).values("name")')

// Iterate over the results and print them
result.each { println it }

This query uses Gremlin syntax to find all vertices in the graph with the "person" label and an "age" property greater than 35, and extracts their "name" property. The results are then printed to the console.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-27 00:29:11 +0000

Seen: 15 times

Last updated: May 27 '23