I have some miniature Gremlin directed graphs, in which each vertex has two properties "type" and "text". The values for "text" property are just English text while the "type" property can a have a value selected from this set :
NP, PP, VP, ADVP, ADJP, SBAR, PRT, INTJ, O
All edges in those graphs have same label : "next".
I want to be able to select the graphs which have following patterns of nodes:
1) [text=","] --> type="VP" --> type="ADVP" --> type="NP"
2) type="NP" --> [text="," Upto 3 nodes with any text and type text=","] --> type="VP" --> [text=":" OR "that"]
The pattern element in brackets means that it is optional.
So, for first pattern, I need to select the graphs which have a node with text "," optionally, followed by a node with type "VP", followed by "ADVP", followed "NP".
For second pattern, I need to select the graphs which have a node type "NP", followed by an optional sequence of nodes starting with a node with text "," then upto 3 nodes with any text and type and then a node with text ",". This optional sequence is then followed by a node of type "VP" and finally a node with text ":" or "that".
Two sample graphs that would match with first pattern are :
Following are sample graphs that would match with second pattern:
I understand basic Gremlin traversals but I am not sure about how to handle optional elements of the pattern above.
Is there any way to write queries for such patterns in Gremlin? If not, can you suggest a non-Gremlin based approach to create such graphs and querying them ?