Neo4j Chypre convention in to gremlin query

We are trying to convert the Neo4j chypre query into a Gremlin query, but we are stuck on some extract methods in the chypre query that need to be converted into the Gremlin query. The chypre query follows:
MATCH (from: `Person` {title: "John"}), (to: `Location` {title: "New York City"})
MATCH p = (from)-[rel*..5]->(to)
RETURN extract(x IN nodes(p) | x.title) as title,
extract(i IN relationships(p)| type(i)) as relation,
extract(j IN nodes(p) | j.nt) as node,
length(p) as len,
extract(x IN nodes(p) | x) as node_data,
extract (i in nodes(p)| id(i)) as id,
extract(i IN relationships(p)| id(i)) as rel_id,
extract(rel IN relationships(p) | id(startNode(rel))) as start,
extract(rel IN relationships(p) | id(endNode(rel))) as end
MATCH (from: `Person` {title: "John"}), (to: `Location` {title: "New York City"})
MATCH p = (from)-[rel*..5]->(to)
RETURN extract(x IN nodes(p) | x.title) as title,
extract(i IN relationships(p)| type(i)) as relation,
extract(j IN nodes(p) | j.nt) as node,
length(p) as len,
extract(x IN nodes(p) | x) as node_data,
extract (i in nodes(p)| id(i)) as id,
extract(i IN relationships(p)| id(i)) as rel_id,
extract(rel IN relationships(p) | id(startNode(rel))) as start,
extract(rel IN relationships(p) | id(endNode(rel))) as end
Output of the above query as follow:
[
{
"title": ["John", "new york city"], // 'title' is property of the vertices
"relation": ["WORKIGN_AT"], // Edge label between nodes
"node": ["Person", "Location"], // List of labels
"len": 1, // Node hop between two node label
"node_data": [ // List of node property data
{
"Employee_Status": "Active",
"FT_or_PT": "Full Time",
"title": "john"
},
{
"Office_Type": "Headquarters",
"Mailing_Code": 10022,
"ISO_Alpha_Two_Country_Code": "US",
"City": "New York",
"title": "New York City",
"Display": "New York City",
"Name": "New York City"
}
],
"id": [5432,5125], // List of node id in the hopes
"rel_id": [17409], // list of edge id in the hopes
"start": [5432], // id of from nodes in the hopes
"end": [5125] // id of to nodes in the l
}
]
[
{
"title": ["John", "new york city"], // 'title' is property of the vertices
"relation": ["WORKIGN_AT"], // Edge label between nodes
"node": ["Person", "Location"], // List of labels
"len": 1, // Node hop between two node label
"node_data": [ // List of node property data
{
"Employee_Status": "Active",
"FT_or_PT": "Full Time",
"title": "john"
},
{
"Office_Type": "Headquarters",
"Mailing_Code": 10022,
"ISO_Alpha_Two_Country_Code": "US",
"City": "New York",
"title": "New York City",
"Display": "New York City",
"Name": "New York City"
}
],
"id": [5432,5125], // List of node id in the hopes
"rel_id": [17409], // list of edge id in the hopes
"start": [5432], // id of from nodes in the hopes
"end": [5125] // id of to nodes in the l
}
]
I'm looking for a Gremlin query that can effectively replace the extract method for Neo4j and produce the same output. Your insights would be greatly appreciated.
2 Replies
rg2609
rg2609OP2mo ago
@janusgraph, passionately looking for a solution
Kennh
Kennh2mo ago
I'm not familiar with query languages other than Gremlin, but I can give a shot at coming up with an answer for this tomorrow if no one else has suggested anything by then.
effectively replace the extract method for Neo4j and produce the same output
Could you clarify what you meant by this? Did you need the output to be in the exact same output (with the same formatting)? Or just output that contains the same data but it's ok for it to be organized differently? Did you need it back in a JSON compatible format? Also, there's some duplicated data in the results, which tends to make the Gremlin query quite long since you'll need to add steps just for formatting.

Did you find this page helpful?