- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在 python 中使用 gremlin。我导入了以下内容:
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
from gremlin_python.structure.graph import Graph
from gremlin_python import statics
from gremlin_python.process.graph_traversal import __
from gremlin_python.process.strategies import *
from gremlin_python.process.traversal import *
import asyncio
statics.load_statics(globals())
当我运行这个时:
graph = TinkerGraph.open()
graph.io(graphml()).readGraph('air-routes.graphml')
我收到以下错误:
NameError: name 'TinkerGraph' is not defined
如何解决这个问题?
最佳答案
Python 中没有 TinkerGraph。在 gremlin-python 中,您只能获得对服务器上远程图的引用,这可能是 TinkerGraph 或其他东西。如果您想以这种方式加载数据,则必须通过 Client
实例以脚本形式发出该命令:
client = Client('ws://localhost:45940/gremlin', 'g')
client.submit("graph.io(graphml()).readGraph('air-routes.graphml');[]").all().result()
其中该脚本中的“graph”是服务器上已存在的Graph
实例(并且可能为空)。如果您使用 Gremlin Server,您可能会考虑将其作为 Gremlin Server startup 的一部分单独加载,然后仅使用 gremlin-python 来查询该数据。在本例中这可能是最好的,因为数据只会在服务器启动时出现。
请注意,在 3.4.0 中,我们引入了 io()
步骤,该步骤将直接成为 gremlin-python 的一部分,此时您可以直接执行以下操作:
g.io('air-routes.xml').read()
在 native python 中,它会正常工作(同样,Graph
实例必须远程定义),尽管该文件必须可由服务器读取。
这是我在 Python shell 中提交脚本的工作示例,首先出现 Tornado 错误,然后没有:
$ env/bin/python
Python 3.4.3 (default, Nov 28 2017, 16:41:13)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from gremlin_python.driver.client import Client
>>> client = Client('ws://localhost:8182/gremlin', 'g')
>>> client.submit("g.V()").all().result()
Traceback (most recent call last):
File "/home/smallette/git/apache/incubator-tinkerpop/gremlin-python/target/python3/gremlin_python/driver/client.py", line 51, in __init__
from gremlin_python.driver.tornado.transport import (
File "/home/smallette/git/apache/incubator-tinkerpop/gremlin-python/target/python3/gremlin_python/driver/tornado/transport.py", line 19, in <module>
from tornado import ioloop, websocket
ImportError: No module named 'tornado'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/smallette/git/apache/incubator-tinkerpop/gremlin-python/target/python3/gremlin_python/driver/driver_remote_connection.py", line 45, in __init__
password=password)
File "/home/smallette/git/apache/incubator-tinkerpop/gremlin-python/target/python3/gremlin_python/driver/client.py", line 54, in __init__
raise Exception("Please install Tornado or pass"
Exception: Please install Tornado or passcustom transport factory
>>> exit
Use exit() or Ctrl-D (i.e. EOF) to exit
>>> exit()
$ env/bin/pip install tornado
Collecting tornado
Collecting backports-abc>=0.4 (from tornado)
Using cached https://files.pythonhosted.org/packages/7d/56/6f3ac1b816d0cd8994e83d0c4e55bc64567532f7dc543378bd87f81cebc7/backports_abc-0.5-py2.py3-none-any.whl
Installing collected packages: backports-abc, tornado
Successfully installed backports-abc-0.5 tornado-5.1.1
smallette@ubuntu:~/git/apache/incubator-tinkerpop/gremlin-python/target/python3$ env/bin/python
Python 3.4.3 (default, Nov 28 2017, 16:41:13)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from gremlin_python import statics
>>> client = Client('ws://localhost:8182/gremlin', 'g')
>>> client.submit("g.V()").all().result()
[v[0]]
关于python - 如何将tinkergraph上传到python/gremlin?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53708193/
我想知道是否可以使用 TinkerPop 3 为内存中 TinkerGraph 定义内存中模式约束。因此,如果不允许某些操作,它将抛出异常,就像 DSE Graph 和 Titan 正在做的那样。现在
我一直在 Java 环境中使用 Apache Tinkerpop 3.3,但在打印我所做的查询的输出时遇到了问题。例如,当我使用以下代码时: GraphTraversalSource g = tg.t
我已经为修补图运行了 gremlin 服务器 session 。 gremlin.graph=org.apache.tinkerpop.gremlin.tinkergraph.structure.Ti
在 gremlin 控制台中,我们可以轻松创建一个内存中的 TinkerGraph 来使用(或加载示例图之一): gremlin> graph = TinkerGraph.open() gremlin
使用 JanusGraph 和 Gremlin,我有一个似乎失败的图形导出要求。从 Gremlin 控制台,我可以导出我的小图: g.io('sample.json').write().iterate
是否可以针对 gremlin-server 的本地实例使用 Tinkergraph-Gremlin?换句话说,以下源代码中缺少什么以使其查询 localhost:8182 gremlin-server
我无法通过执行 g.V(3640).valueMap(true).unfold() 选择特定的顶点。在 g.V() 命令的括号之间包含 ID 的任何命令似乎都不起作用。 这是我做的: 我是图形数据库的
我是一名优秀的程序员,十分优秀!