简体   繁体   中英

Gremlin Python Gizmo how to query in graph db

I've pushed data using gremlin-python. Now I want to run spcific queries on it. I'm using gizmo for that.

I basically want to achieve the degree of centrality for each node. How do I do that?

Currently I've query to return the same as :

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

How I'm achieving that is:

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()

What I want is to display the data fetched inside res variable.

But each time I get errors as :

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

or anything similar which I try.

How do I fetch the results fetched from coroutine object?

NOTE : The sample query I'm passing to function query() is gV().count()

Is there any other better way to run any generic queries from python in gremlin shell and fetch results?

Graph DB: JanusGraph

Backend: Cassandra

Indexing Backend: Elasticsearch

You mention gizmo which could relate to multiple projects, but I think you mean this one:

https://github.com/emehrkay/gizmo

According to the documentation, this project is meant for TinkerPop 2.x and Rexster. I don't believe it works with TinkerPop 3.x and Gremlin Server which is what JanusGraph is based on. If you need a Python OGM of some sort for TinkerPop 3.x you might consider:

https://github.com/davebshow/goblin

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM