Query path of words – must contain several words in between first and last word

Next step in developing our “path” query to capture specific phrases:

We can already return a set of vertices (words) where we define the first and last word and a max distance between.

Now we need to add to the criteria: The words between first and last must also include some additional words. For example:

  1. We can pass in the string “exclusive,permanent,Right,Way” and use the split function to parse this into a list.

  2. “exclusive” will be the starting word and “Way” will be the ending word and we have a max distance of 10.

  3. For this example the words in between must contain “permanent” and “Right”.

Two example of what this could return:
[exclusive,
permanent,
and,
perpetual,
Right,
of,
Way]

and

[exclusive,
and,
permanent,
easement,
for,
the,
Right,
of,
Way]

Ultimately, we’ll want to pass in a flag to determine if the words in-between must be in the order from the list, or if they can be in any random order. For now lets do what is simplest.

I took the previous query and modified it according to the description above where it’s fully functional except for using the logic where the vertices returned must contain the words between the first and last (“permanent” and “Right” in this example). What’s the text way to implement this next logic?

Just tying to think about how to do this, since we have a list of words - @@words and assuming there’s a way to do this for each separate path (set of words) we could do this (in pseudo code):

ListAccum @@crit;

@@crit += “permanent”;

@@crit += “Right”

IF !@@words.contains(@@crit) THEN

//Remove this set because doesn’t meet our criteria.

Thank you.

CREATE QUERY aFindPathContainingMulitCriteria(STRING criteria, INT maxDist) FOR GRAPH MyGraph {
  /* Test criteria:  exclusive,permanent,Right,Way */
 ListAccum<string>  @@criteriaWords;
 SetAccum<edge> @@edgeSet;
 SetAccum<vertex> @@vSet;
 ListAccum<STRING> @@words;
 
 STRING startWord;
 STRING endWord;
 INT wordCount;
 
 @@criteriaWords += string_split(criteria,",");
 startWord = @@criteriaWords.get(0);
 endWord = @@criteriaWords.get(@@criteriaWords.size()-1); 
 
 
 // Need to implement logic so the sets returned contain "permanent" and "Right".
 
 Start (ANY) = {word.*};
 
 Start = select s from Start:s where s.Text == startWord;
 
 while Start.size() > 0 limit 20 do
   Start = select t from Start:s-(nextword:e)-word:t
           accum @@edgeSet += e,
                  @@vSet += t,
                 @@words += t.Text
           having t.Text != endWord;
 end;
 
 vSet = @@vSet;
 print @@vSet,@@edgeSet, vSet;
 print @@words;
}