我正在撰写一份脚本,使用gremlin-python库在gremlin-server上创建一个图表。我找不到关于该库的任何好的文档。
以下是我正在尝试的代码结构:
这段代码只给我2个顶点和1条边。
我的一些尝试:
- 当我尝试不使用
一些额外的信息:
- 我正在以graphson格式存储图形。 - 我正在使用Python3.6。
以下是我正在尝试的代码结构:
from gremlin_python import statics
from gremlin_python.structure.graph import Graph
from gremlin_python.process.graph_traversal import __
from gremlin_python.process.strategies import *
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
graph = Graph()
g = graph.traversal().withRemote(DriverRemoteConnection('ws://localhost:8182/gremlin','try1'))
# Drop all vertices in the graph to create a new one
g.V().drop().iterate()
a = g.addV('person').property('name', 'Tushar').property('pronoun', 'me')
b = g.addV('person').property('name', 'Avi').property('pronoun','you')
e1 = a.addE('knows').to(b).property('relation','self')
c = g.addV('subject').property('name','maths')
e2 = a.addE('studies').to(c)
e3 = b.addE('studies').to(c)
e3.next()
v = g.V().toList()
e = g.E().toList()
print(v)
print(e)
这段代码只给我2个顶点和1条边。
我的一些尝试:
- 当我尝试不使用
.next()
的代码时,没有数据提交到图形中。
- 当我给e1
一个.next()
时,创建了2个不同的顶点和1个不同的边。
- 当我在e2
和e1
上添加.next()
时,会抛出一个错误,说StopIteration
。
- 当我在e3
和e1
上添加.next()
时,我得到了4个顶点和2条边。
我的图应该有3个顶点和3个节点。我真正想要的是将脚本所做的更改提交到图形中。一些额外的信息:
- 我正在以graphson格式存储图形。 - 我正在使用Python3.6。
:remote
,那么你需要使用 "session" 标志:https://tinkerpop.apache.org/docs/current/reference/#console-sessions 如果你在谈论应用程序中的 Gremlin 代码,则需要使用支持事务的图形会话提交脚本——请参阅此处所使用的编程语言的 "Submitting Scripts" 部分:https://tinkerpop.apache.org/docs/current/reference - stephen mallette