Hello! I’m trying to create a query that returns the n-hop ego net for a node, where the input parameters are the starting node and the number of hops. However, I get an error when I try to use the input parameter to set the number of hops in the pattern. For example, if the pattern is:
X:x -(F>*..3)- Y:y
, I would like to set the length with a parameter:
INT num_hops = 3;
X:x -(F>*..num_hops)- Y:y
However, this produces an error.
To be specific, here is my query:
USE GRAPH RoadMap
SET syntax_version="v2"
CREATE QUERY n_hop_neighborhood(VERTEX<Coordinate> start_node, INT num_hops)
{
start = {start_node};
SetAccum<VERTEX> @@vertex_set;
SetAccum<EDGE> @@edge_set;
dummy = SELECT c2
FROM start:c1 -(Road>*..num_hops)- Coordinate:c2
ACCUM
@@vertex_set += c2,
@@vertex_set += c1;
my_nodes = SELECT c
FROM Coordinate:c
WHERE c in @@vertex_set;
dummy = SELECT c2
FROM Coordinate:c1 -(Road>:r)- Coordinate:c2
WHERE c1 in @@vertex_set and c2 in @@vertex_set
ACCUM
@@edge_set += r;
print my_nodes, @@edge_set;
}
It produces the following error message:
line 15:28 no viable alternative at input 'from start:c1 -(Road>*..num_hops'
line 15:49 mismatched input ':' expecting {INTERSECT, MINUS, UNION, '%', '&', '+', '-', '*', '/', '.', ';', '>', '|', '<<'}
line 17:22 no viable alternative at input 'c2,'
Parsing encountered 3 syntax error(s)
If I change the line FROM start:c1 -(Road>*..num_hops)- Coordinate:c2
to e.g. FROM start:c1 -(Road>*..3)- Coordinate:c2
, it all works.
Any help would be much appreciated!