Gremlin Python返回空图

Gremlin Python返回空图,第1张

概述我开始玩gremlin- python包装器来与我的gremlin服务器进行交互. 我做了以下步骤: ./bin/gremlin.sh 一旦Gremlin控制台打开,我使用以下命令加载配置: graph = JanusGraphFactory.open('conf/gremlin-server/janusgraph-cassandra-es.properties')g = graph.trave 我开始玩gremlin- python包装器来与我的gremlin服务器进行交互.

我做了以下步骤:

./bin/gremlin.sh

一旦Gremlin控制台打开,我使用以下命令加载配置:

graph = JanusGraphFactory.open('conf/gremlin-server/janusgraph-cassandra-es.propertIEs')g = graph.traversal()saturn = g.V().has('name','saturn')

gremlin shell中的上面一组代码工作得很好,我可以看到列出的脊椎,但是当我尝试在python中做同样的事情时,我得到一个空图.以下是我的python代码:

graph = Graph()g = graph.traversal().withRemote(DriverRemoteConnection('ws://localhost:8182/gremlin','g'))print(g)

返回
graphtraversalsource [图表[空]]

为什么我得到空图?据我所知,它无法连接到相同的Graph源.有什么我想念的吗?

请注意:

JanusGraphFactory.open('conf/gremlin-server/janusgraph-cassandra-es.propertIEs')

提供的配置文件名是用于启动gremlin服务器的文件名.

任何帮助都非常感谢.

谢谢

解决方法 你看到graph [empty]的原因是因为那是Python图形对象的实际字符串表示 – 请参阅 code here.图表实际上可能包含数据,所以如果它像graph [remote]或者更好的话会更好图[]代替.我打开了一个 issue来解决这个问题.

开箱即用,JanusGraph未配置Python.您可以在Apache TinkerPop docs中找到有关如何执行此 *** 作的文档.首先安装gremlin-python.假设您正在使用使用TinkerPop 3.2.3的JanusGraph 0.1.1,这是命令:

bin/gremlin-server.sh -i org.apache.tinkerpop gremlin-python 3.2.3

接下来修改conf / gremlin-server / gremlin-server.yaml以添加gremlin-python脚本引擎:

scriptEngines: {  gremlin-groovy: {    imports: [java.lang.Math],staticimports: [java.lang.Math.PI],scripts: [scripts/empty-sample.groovy]},gremlin-jython: {},gremlin-python: {}}

要使用Gremlin Python,您需要浏览Gremlin Server,因此启动JanusGraph pre-packaged distribution:

bin/janusgraph.sh start

从Gremlin控制台:

gremlin> graph = JanusGraphFactory.open('conf/janusgraph-cassandra-es.propertIEs')==>standardjanusgraph[cassandrathrift:[127.0.0.1]]gremlin> GraphOfTheGodsFactory.load(graph)==>nullgremlin> g = graph.traversal()==>graphtraversalsource[standardjanusgraph[cassandrathrift:[127.0.0.1]],standard]gremlin> g.V().count()14:51:58 WARN  org.janusgraph.graphdb.transaction.StandardJanusGraphTx  - query requires iterating over all vertices [()]. For better performance,use indexes==>12

安装Gremlin-Python驱动程序,再次匹配TinkerPop版本:

pip install gremlinpython==3.2.3

从Python 3 shell:

>>> 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','g'))>>> print(graph)graph[empty]>>> print(g)graphtraversalsource[graph[empty]]>>> g.V().count().next()12>>> g.addV('god').property('name','mars').property('age',3500).next()v[4280]>>> g.V().count().next()13

请记住,当您在Python shell中工作时,图形遍历不会自动迭代,因此您需要确保使用iterate()或next()或toList()迭代遍历.

总结

以上是内存溢出为你收集整理的Gremlin Python返回空图全部内容,希望文章能够帮你解决Gremlin Python返回空图所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1195037.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存