Skip to content Skip to sidebar Skip to footer

Gremlinpython - Return Id And Label As String

I'm using gremlinpython 3.4.1 on Python 3.7.2, and when get vertex/edge responses it is providing for id and for the label. How would I get it to

Solution 1:

Additionally, to the project() example that was already given, you could do something like the following if you can't or don't want to specify the property names:

g.V().has('name', 'USA').limit(1000).hasLabel('Country').
  map(union(project('id','label').
              by(id).
              by(label),
            valueMap()).unfold().
      group().
        by(keys).
        by(select(values))) // select(values).unfold() if you only have single values

Solution 2:

You could try to project the results.

g.V().has('name', 'USA').limit(1000).hasLabel('Country') \
    .project('id', 'label', 'name', 'parentname', 'shortname', 'parentid') \
    .by(id) \
    .by(label) \
    .by('name') \
    .by('parentname') \
    .by('shortname') \
    .by('parentid') \
    .toList()

Solution 3:

You could replace your EnumMeta dict keys with the actual values. You would need to add an unfold() after your valueMap to use this function.

from gremlin_python.process.traversal import T

defget_query_result_without_enum_metas(query_result):
    return [replace_enum_metas(d) for d in query_result]

defreplace_enum_metas(dict):
      dict_key = (*dict,)[0]
      iftype(dict_key) isstr:
        returndicteliftype(dict_key) is T:
        return {dict_key.name: dict[dict_key]}

input: [{'vertex_property': ['Summary']}, {<T.id: 1>: '4b30f448ee2527204a050596b'}, {<T.label: 3>: 'VertexLabel'}]

output: [{'vertex_property': ['Summary']}, {'id': '4b30f448ee2527204a050596b'}, {'label': 'VertexLabel'}]

Post a Comment for "Gremlinpython - Return Id And Label As String"