Break result into a collection of subsets

For the query listed at the bottom of this post the variable that I’m most interested in returning is:

ListAccum @@words;

However, @@words is the combined total of all paths (phrases) and I need to return a collection of phrases such as:

{

construction,

shall,

be,

sixty,

(60),

feet,

wide

},

{

during,

any,

period,

of,

construction,

to,

a,

width,

of,

100,

feet

}

Rather than one long list of words. Also, the words must be listed in the correct order and currently they’re being resorted.

Do I need to return the json for the entire vertex instead of just each word’s text?

Thank you.

CREATE QUERY aFindPathContainingMulitCriteria(STRING criteria, INT maxDist) FOR GRAPH MyGraph {
  /* 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); 
 
 
 
 
 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;
}

Hi George,

Since all edges are traversed in parallel, the order of words from one sentence may overlap another.

To fix this, you can - instead of storing the words in @@words - store the vertices.

Since you said the vertices are all given numbers, which basically act as an index, you can move the list into a HeapAccum and order them by the primary id values. Then they’ll be in order. From here, you can move them back into a ListAccum, which will preserve the order in which the items were inserted.

Please check out our documentation on accumulators, and everything else, here: https://docs.tigergraph.com/dev/gsql-ref/querying/accumulators

Thanks,

Kevin

Thank you Kevin,

This answers the question on preserving the order. The other part of the problem is breaking the data into subset where each subset is a phrase. This result will be passed back to a client application expecting a list of phrases in one form or another. Passing back json for the vertices is an acceptable option, but they need to be grouped by phrase. the screenshot below shows the phrases I’m talking about.

I will work on your response above first and will come back to this.

I assume your subset question here is the same as the one here : https://groups.google.com/a/opengsql.org/forum/#!topic/gsql-users/_OSPYX-L2vQ

Yes and thank you for the detailed responses. it will take some time to go through these.