Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert string command of Gremlin to executable

Tags:

I have created a long Gremlin chained command as a string. What is the best way to execute it in NodeJS or Python?

g.addV("person").
  property(id, 1).
  property("name", "marko").
  property("age", 29).as("1").
  addV("person").
  property(id, 2).
  property("name", "vadas").
  property("age", 27).as("2").
  addV("software").
  property(id, 3).
  property("name", "lop").
  property("lang", "java").as("3").
  addV("person").
  property(id, 4).
  property("name", "josh").
  property("age", 32).as("4").
  addV("software").
  property(id, 5).
  property("name", "ripple").
  property("lang", "java").as("5").
  addV("person").
  property(id, 6).
  property("name", "peter").
  property("age", 35).as("6").
  addE("created").from("1").to("3").
  property(id, 9).
  property("weight", 0.4).
  addE("knows").from("1").to("2").
  property(id, 7).
  property("weight", 0.5).
  addE("knows").from("1").to("4").
  property(id, 8).
  property("weight", 1.0).
  addE("created").from("3").to("4").
  property(id, 11).
  property("weight", 0.4).
  addE("created").from("3").to("6").
  property(id, 12).
  property("weight", 0.2).
  addE("created").from("4").to("5").
  property(id, 10).
  property("weight", 1.0)

The command given above was executed on the Gremlin console and was successful, but I need to know how to achieve this in program of node or Python using TinkerPop drive.

like image 843
Hammad Ali Khan Avatar asked Oct 18 '18 05:10

Hammad Ali Khan


2 Answers

Start with Gremlin Language Variants (GLV) and then head over to Gremlin-python.

The docs should be good enough for you to solve this yourself.

http://tinkerpop.apache.org/docs/current/tutorials/gremlin-language-variants/#using-python-and-gremlin-server

like image 137
The-Big-K Avatar answered Nov 15 '22 04:11

The-Big-K


from gremlin_python.driver import client

client = client.Client('ws://localhost:8182/gremlin', 'g')

client.submit("your query")
like image 38
Ranjit Soni Avatar answered Nov 15 '22 06:11

Ranjit Soni