问题
Sample data: TinkerPop Modern
Required Data format:
{'relation': '['created']', 'id': [10224, 10220], 'title': ['Marko', 'lop']}
{'relation': '['knows', 'created']', 'id': [10224, 10226, 10222], 'title': ['Marko', 'Josh', 'ripple']}
{'relation': '['knows', 'created']', 'id': [10225, 10224, 10220], 'title': ['Vadas', 'Marko', 'lop']}
{'relation': '['knows', 'knows', 'knows', 'created']', 'id': [10225, 10224, 10226, 10222], 'title': ['Vadas', 'Marko', 'Josh', 'ripple']}
{'relation': '['created']', 'id': [10226, 10220], 'title': ['Josh', 'lop']}
{'relation': '['created']', 'id': [10226, 10222], 'title': ['Josh', 'ripple']}
{'relation': '['created']', 'id': [10227, 10220], 'title': ['Peter', 'lop']}
{'relation': '['created', 'knows', 'created']', 'id': [10227, 10220, 10226, 10222], 'title': ['Peter', 'lop', 'Josh', 'ripple']}
Query:
g.V().hasLabel("Person").as("from")
.repeat(both().as("to").dedup("from", "to"))
.emit(hasLabel("Software"))
.hasLabel("Software")
.project("title", "relation", "id")
.by(path().by("name"))
.by(constant("r"))
.by(path().by(id()))
Problem:
I cannot find a way to get the Edges that were traversed to get the result Vertex. any way out? I tried bothE().bothV() but that is not limited to the traversals
回答1:
First you have to traverse the edges by using bothE().otherV()
instead of just both()
. However, this will also change the path and thus you'll have to adjust a few more things in your query:
g.V().hasLabel("person").as("from","v").
repeat(bothE().as("e").otherV().as("v").dedup("from", "v")).
emit(hasLabel("software")).
hasLabel("software").
project("title", "relation", "id").
by(select(all, "v").unfold().values("name").fold()).
by(select(all, "e").unfold().label().fold()).
by(select(all, "v").unfold().id().fold())
回答2:
PipeFunction "enablePath()" should do this for You. See documentation.
来源:https://stackoverflow.com/questions/49510446/gremlin-get-edges-that-were-traversed