【问题标题】:Gremlin Python Gizmo how to query in graph dbGremlin Python Gizmo 如何在图形数据库中查询
【发布时间】:2017-09-10 17:26:26
【问题描述】:

我使用 gremlin-python 推送数据。现在我想对它运行特定的查询。我正在为此使用 Gizmo。

我基本上是想达到每个节点的中心度。我该怎么做?

目前我查询返回的结果与:

g.V().group().
......1> by(id).
......2> by(union(__(), outE('mentions').count()).fold())

我是如何做到这一点的:

def query(self, q):
    from gizmo import Mapper, Request
    from gremlinpy import Gremlin

    req = Request('localhost', 8182)
    gremlin = Gremlin('g')

    mapper = Mapper(request=req, gremlin=gremlin)
    # s = mapper.gremlin.V().inE('mentions').count().toList()
    # res = mapper.query(gremlin=s)

    # print(res.get_data()[0])
    print("Something")

    res = mapper.query(script=q)

    # print(res.get_data()[0])
    print("Something")
    print(res.data)

    print(res.first(), res.data)
    # exit(0)
    return res.first()

我想要的是显示在 res 变量中获取的数据。

但每次我得到错误时:

AttributeError: 'coroutine' object has no attribute 'data'
AttributeError: 'coroutine' object has no attribute 'get_data'

或者我尝试过的任何类似的东西。

如何获取从协程对象中获取的结果?

注意:我传递给函数 query() 的示例查询是 g.V().count()

还有其他更好的方法可以在 gremlin shell 中从 python 运行任何通用查询并获取结果吗?

图形数据库: JanusGraph

后端: Cassandra

索引后端: Elasticsearch

【问题讨论】:

    标签: python graph gremlin janusgraph


    【解决方案1】:

    你提到了可能与多个项目相关的小发明,但我认为你的意思是这个:

    https://github.com/emehrkay/gizmo

    根据文档,该项目适用于 TinkerPop 2.x 和 Rexster。我不相信它适用于 JanusGraph 所基于的 TinkerPop 3.x 和 Gremlin Server。如果您需要 TinkerPop 3.x 的某种 Python OGM,您可以考虑:

    https://github.com/davebshow/goblin

    【讨论】:

    • 谢谢,Goblin 似乎在我们的问题用例中工作。 :-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-29
    • 1970-01-01
    • 1970-01-01
    • 2021-12-17
    • 2021-08-13
    • 2016-10-05
    • 1970-01-01
    相关资源
    最近更新 更多