我现在正在尝试学习如何使用Python中的Bulbflow连接到Neo4j服务器并在其上运行Cypher查询.我不明白的是连接到neo4j服务器的两种可能性之间的区别:
1)图表
from bulbs.neo4jserver import Graph
g = Graph()
Run Code Online (Sandbox Code Playgroud)
from bulbs.neo4jserver import Neo4jClient
client = Neo4jClient()
Run Code Online (Sandbox Code Playgroud)
有谁能请解释这里的概念差异?哪种方式更好的选择我是否想要执行(相当多)Cypher查询服务器并最终并行执行?
PS:我没有足够的声誉为这个问题创建一个标签"bulbflow":)
所以,我在mac-osx上使用python3.2和灯泡,使用rexster和orientdb.细节:
orientdb - 从他们的页面下载标准
〜/工作区/ orientdb社区-1.7-RC1
运行服务器, ./bin/server.sh
database - orientdb database~/databases/orientdb/dev-db-01
rexster - 来自github git clone的标准结账git://github.com/tinkerpop/rexster.wiki.git~/ workspace /
配置/ rexster.xml:
...
<graph>
<graph-enabled>true</graph-enabled>
<graph-name>dev-db-01</graph-name>
<graph-type>orientgraph</graph-type>
<graph-location>local:*<path to...>*/databases/orientdb/dev-db-01</graph-location>
<properties>
<username>admin</username>
<password>admin</password>
</properties>
<extensions>
<allows>
<allow>tp:gremlin</allow>
</allows>
</extensions>
</graph>
...
Run Code Online (Sandbox Code Playgroud)
Python代码:
from bulbs.rexster import Graph
from bulbs.config import Config
config = Config("http://localhost:8182/dev-db-01/", username="admin", password="admin")
g = Graph(config)
Run Code Online (Sandbox Code Playgroud)
问题:
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/opt/local/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/bulbs/rexster/graph.py", li ne 56, in __init__
super(Graph, self).__init__(config) File "/opt/local/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/bulbs/base/graph.py", line …
Run Code Online (Sandbox Code Playgroud) 我需要一些帮助来确认我的选择...并了解你是否可以给我一些信息.我的存储数据库是TitanDb和Cassandra.我有一个非常大的图表.我的目标是在后面的图上使用Mllib.
我的第一个想法是:使用Titan和GraphX,但我没有找到任何东西或正在开发中...... TinkerPop还没准备好.所以我看看Giraph.TinkerPop,Titan可以与TinkerPop的Rexster通信.
我的问题是:使用Giraph有什么好处?Gremlin似乎也在思考并分发.
非常感谢你解释我.我想我并不真正理解Gremlin和Giraph(或GraphX)之间的区别.
祝你今天愉快.
在我的系统中,我要求节点上的边数必须存储为顶点的内部属性以及特定传出边上的顶点中心索引.这自然要求我在所有数据加载完毕后计算节点上的边数.我这样做如下:
long edgeCount = graph.getGraph().traversal().V(vertexId).bothE().count().next();
Run Code Online (Sandbox Code Playgroud)
但是,当我将测试扩展到某些节点是"超级"节点时,我在上面的行中得到以下异常:
Caused by: com.netflix.astyanax.connectionpool.exceptions.TransportException: TransportException: [host=127.0.0.1(127.0.0.1):9160, latency=4792(4792), attempts=1]org.apache.thrift.transport.TTransportException: Frame size (70936735) larger than max length (62914560)!
at com.netflix.astyanax.thrift.ThriftConverter.ToConnectionPoolException(ThriftConverter.java:197) ~[astyanax-thrift-3.8.0.jar!/:3.8.0]
at com.netflix.astyanax.thrift.AbstractOperationImpl.execute(AbstractOperationImpl.java:65) ~[astyanax-thrift-3.8.0.jar!/:3.8.0]
at com.netflix.astyanax.thrift.AbstractOperationImpl.execute(AbstractOperationImpl.java:28) ~[astyanax-thrift-3.8.0.jar!/:3.8.0]
at com.netflix.astyanax.thrift.ThriftSyncConnectionFactoryImpl$ThriftConnection.execute(ThriftSyncConnectionFactoryImpl.java:153) ~[astyanax-thrift-3.8.0.jar!/:3.8.0]
at com.netflix.astyanax.connectionpool.impl.AbstractExecuteWithFailoverImpl.tryOperation(AbstractExecuteWithFailoverImpl.java:119) ~[astyanax-core-3.8.0.jar!/:3.8.0]
at com.netflix.astyanax.connectionpool.impl.AbstractHostPartitionConnectionPool.executeWithFailover(AbstractHostPartitionConnectionPool.java:352) ~[astyanax-core-3.8.0.jar!/:3.8.0]
at com.netflix.astyanax.thrift.ThriftColumnFamilyQueryImpl$4.execute(ThriftColumnFamilyQueryImpl.java:538) ~[astyanax-thrift-3.8.0.jar!/:3.8.0]
at com.thinkaurelius.titan.diskstorage.cassandra.astyanax.AstyanaxKeyColumnValueStore.getNamesSlice(AstyanaxKeyColumnValueStore.java:112) ~[titan-cassandra-1.0.0.jar!/:na]
Run Code Online (Sandbox Code Playgroud)
解决这个问题的最佳方法是什么?我应该简单地增加帧大小还是有更好的方法来计算节点上的边数?
如何遍历图形并增加顶点属性的值?通过某个固定数量或通过其边缘属性的数量.
例如.如下图:
gremlin> graph = TinkerGraph.open()
==>tinkergraph[vertices:0 edges:0]
gremlin> g = graph.traversal()
==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
gremlin> a = g.addV('name','a','amount', 100).next()
==>v[0]
gremlin> b = g.addV('name','b','amount', 200).next()
==>v[3]
gremlin> c = g.addV('name','c','amount', 300).next()
==>v[6]
gremlin> a.addEdge('fill', b, 'bonus', 20)
==>e[9][0-drain->3]
gremlin> b.addEdge('fill', c, 'bonus', 40)
==>e[10][3-drain->6]
gremlin>
Run Code Online (Sandbox Code Playgroud)
所以
1)我如何增加每个顶点10
?
最后我想要:
gremlin> g.V().valueMap()
==>[amount:[110],name:[a]]
==>[amount:[210.0],name:[b]]
==>[amount:[310.00],name:[c]]
Run Code Online (Sandbox Code Playgroud)
鉴于声明:
g.V(a).property('amount', X)
Run Code Online (Sandbox Code Playgroud)
我想我正在尝试做类似的事情:
g.V(a).property('amount', g.V(a).values('amount').next()+10)
Run Code Online (Sandbox Code Playgroud)
...但是对于我图中的所有顶点.它看起来像Tinkerpop2 loop()
并且it.object
可能有所帮助,但似乎不在Tinkerpop3中
编辑:好的,我离我更近了,但不是那里:
gremlin> g.V().as('x').property('amount', select('x').by('amount')+10)
No signature of method: org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal.plus() is applicable for argument …
Run Code Online (Sandbox Code Playgroud) 我使用gremlin-console(janusgraph)远程连接到gremlin服务器,但是当我创建一个变量并访问它时,它不起作用.我的最终目标是使用gremlin-console创建索引...
gremlin> :remote connect tinkerpop.server conf/remote.yaml
==>Configured localhost/127.0.0.1:8182
gremlin> :remote console
==>All scripts will now be sent to Gremlin Server -
[localhost/127.0.0.1:8182] - type ':remote console' to return to local mode
gremlin> a = "b"
==>b
gremlin> a
No such property: a for class: Script3
Type ':help' or ':h' for help.
Run Code Online (Sandbox Code Playgroud) 从我看过的文章中,Neo4j实现了apache tinkerpop,这使我认为我可以使用gremlin python,而不是连接到gremlin服务器,我可以将python代码指向neo4j服务器,并将其视为gremlin服务器。
但是,我在网上找不到任何信息来显示如何执行此操作,因此我认为我可能误解了一些信息。
谢谢
亚历克斯
我正在添加这样的顶点:
g.addV("foobar").property("id", 1).property(...etc...
如何使用 uuid 而不是整数 id 设置属性?
刚开始使用 Tinkerpop 和 Janusgraph,我正试图根据文档弄清楚这一点。
但首先我需要一种将数据导入 Janusgraph 的方法。
可能存在用于此的脚本。但除此之外,它是否可能用python编写,打开一个csv文件,获取变量X的每一行,并将其添加为顶点/边/等。……?还是我完全误解了 Janusgraph/Tinkerpop?
提前感谢您的任何帮助。
编辑:
假设我有几个文件,每个文件包含几百万行,代表人,还有几个变量,代表不同的指标。第一个示例可能如下所示:
metric_1 metric_2 metric_3 ..
person_1 a e i
person_2 b f j
person_3 c g k
person_4 d h l
..
Run Code Online (Sandbox Code Playgroud)
我是否应该将其转换为具有首先仅由值 [a,..., l] 组成的节点的文件。(以及后来可能更精细的属性集)
然后 [a,..., l] 被索引了吗?
在“现代”图形这里似乎有一个索引(号码1,...,12对所有的节点和边,独立于它们的重叠标签/类别的),例如应在每次测量单独索引,然后连接至一个给定的person_x他们属于哪个?
为这些可能直截了当的问题道歉,但我对此很陌生。
上下文:
我确实有一个大约有 2000 个顶点和 6000 条边的图,随着时间的推移,这可能会增长到 10000 个顶点和 100000 条边。目前我正在使用以下遍历查询更新新顶点:
向上插入顶点和边
queryVertex = "g.V().has(label, name, foo).fold().coalesce(
unfold(), addV(label).property(name, foo).property(model, 2)
).property(model, 2)"
Run Code Online (Sandbox Code Playgroud)
这里的目的是寻找名为 foo 的顶点,如果找到则更新其model
属性,否则创建一个新顶点并设置该model
属性。这发出两次:一次是针对源顶点,一次是针对目标顶点。
创建两个相关顶点后,将发出另一个查询以创建它们之间的边:
queryEdge = "g.V('id_of_source_vertex').coalesce(
outE(edge_label).filter(inV().hasId('id_of_target_vertex')),
addE(edge_label).to(V('id_of_target_vertex'))
).property(model, 2)"
Run Code Online (Sandbox Code Playgroud)
在这里,如果两个顶点之间存在model
边,则更新边上的属性,否则会在它们之间创建边。
执行此操作的伪代码如下:
for each edge in the list of new edges:
//upsert source and target vertices:
execute queryVertex for edge.source
execute queryVertex for edge.target
// upsert edge:
execute queryEdge
Run Code Online (Sandbox Code Playgroud)
这行得通,但效率极低;例如,对于上述图形大小,它需要几分钟才能完成,并且通过一些应用内并发,它只将时间减少了几分钟。当然,对于如此小的图尺寸,必须有一种更有效的方法来做到这一点。
问题
* 如何使这些 upsert 更快?
tinkerpop ×10
gremlin ×7
python ×4
tinkerpop3 ×3
titan ×3
bulbs ×2
graph ×2
janusgraph ×2
neo4j ×2
cypher ×1
giraph ×1
orientdb ×1
rexster ×1
spark-graphx ×1