Gremlin-Python连接到现有的JanusGraph [英] Gremlin-Python Connecting to existing JanusGraph
问题描述
我已经使用gremlin控制台创建了一个图形
I Have created a graph using gremlin console
gremlin> ConfiguredGraphFactory.graphNames
==>MYGRAPH
gremlin> ConfiguredGraphFactory.getConfiguration('MYGRAPH')
==>storage.backend=cql
==>graph.graphname=MYGRAPH
==>storage.hostname=127.0.0.1
==>Template_Configuration=false
gremlin> g.V().properties()
==>vp[name->SFO]
==>vp[country->USA]
==>vp[name->ALD]
==>vp[country->IND]
==>vp[name->BLR]
==>vp[country->IND]
gremlin>
我想使用gremlin-python与MYGRAPH连接. 有人可以告诉我如何使用gremlin-python访问名为"MYGRAPH"的图.
I want to connect with MYGRAPH using gremlin-python. Can someone please tell me how to access graph named "MYGRAPH" using gremlin-python.
预先感谢...
推荐答案
首先,您需要为JanusGraph安装一些jar文件,以处理gremlin-python脚本:
First of all you will need to install some jar files for JanusGraph to handle gremlin-python scripts:
./bin/gremlin-server.sh -i org.apache.tinkerpop gremlin-python 3.2.9
请注意,您安装的gremlin-python版本必须与Tinuspop版本的JanusGraph兼容.您可以在JanusGraph 版本页面中找到兼容性信息.例如JanusGraph 0.2.2与Tinkerpop 3.2.9兼容.
Please note that the version of gremlin-python you install must match the Tinkerpop version JanusGraph is compatible with. You can find compatibility information on the JanusGraph releases page. For example JanusGraph 0.2.2 is compatible with Tinkerpop 3.2.9.
接下来,您需要使用ConfiguredGraphFactory启动JanusGraph服务器.您只需要使用分发中的文件conf/gremlin-server/gremlin-server-configuration.yaml
.
Next you need to start a JanusGraph server using ConfiguredGraphFactory. You just have to use the file conf/gremlin-server/gremlin-server-configuration.yaml
from the ditribution.
bin/gremlin-server.sh conf/gremlin-server/gremlin-server-configuration.yaml
此文件与传统的conf/gremlin-server/gremlin-server.yaml
在几行中有所不同
This file differs from the traditional conf/gremlin-server/gremlin-server.yaml
in those few lines
graphManager: org.janusgraph.graphdb.management.JanusGraphManager
graphs: {
ConfigurationManagementGraph: conf/janusgraph-cql-configurationgraph.properties
}
然后,我们需要在服务器的初始化脚本期间加载图MYGRAPH
.请创建一个初始化脚本scripts/init.groovy
.在这里,您可以根据需要加载任意数量的不同图形.
Then we need to load the graph MYGRAPH
during the initialization script of the server. Please create an init script scripts/init.groovy
. Here you can load as many different graphs as you want.
def globals = [:]
myGraph = ConfiguredGraphFactory.open("MYGRAPH")
globals << [myGraphTraversal : myGraph.traversal()]
确保当gremlin服务器在conf/gremlin-server/gremlin-server-configuration.yaml
Make sure this script is executed when gremlin server starts in conf/gremlin-server/gremlin-server-configuration.yaml
scriptEngines: {
gremlin-groovy: {
imports: [java.lang.Math],
staticImports: [java.lang.Math.PI],
scripts: [scripts/init.groovy]}}
最后,在您的Python项目中,安装与您的JanusGraph版本的Tinkerpop版本匹配的gremlin-python软件包.如果使用JanusGraph 0.2.2,则为3.2.9版本.
Finally in your Python project, install the gremlin-python package that matches the Tinkerpop version of your version of JanusGraph. In case of JanusGraph 0.2.2, this is version 3.2.9.
pip install gremlin-python==3.2.9
启动Python shell并开始编码:
Start a Python shell and start coding:
>>> 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()
>>> myGraphTraversal = graph.traversal().withRemote(DriverRemoteConnection('ws://localhost:8182/gremlin','myGraphTraversal'))
>>> myGraphTraversal.V().count()
这篇关于Gremlin-Python连接到现有的JanusGraph的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!