User defined rules or subgraphs

I have data in a full graph, and can run analysis on subgraphs/subsets of the graph to check it for rule consistency. The nodes in the graph have different types and are connected to other nodes via named connections as in the picture. enter image description here

A rule is something like "find me all nodes of type A that is connected to a node of type B via a named connection called 1" or "find me all nodes of type A that is connected to type B using a connection named 1, then to a node of type C using a connection named 2, then to a node of type D using a connection named 3". Or relevant to the picture "find all MA connected to NEG_R using a connection named PHR , then to a type ABS_R using a connection named 4, then to a type Pcs7AnIn using a connection called 1".

I would appreciate a suggestion for a UI for defining these rules. A variation of this Search options for a tag hierarchy view is my current best idea.