Source: site.view [edit]
Function name: fiveGramsAroundBlanks
Arguments: question,answers
Description: Returns five-gram phrases around a blank, with choices filled in
Page type: webl
Render function:  
Module: sataire

Page source:

var questionList = Str_Split("|" + question + "|", "_");

var putTogether = fun(questionList, answerList)
   var s = "";
   var pos = [];
   every q in questionList do
      s = s + q;
      if (answerList != []) then
          pos = pos + [Size(Str_Split(s, " "))];
          s = s + First(answerList);
          pos = pos + [Size(Str_Split(s, " "))];
          answerList = Rest(answerList)
      end
   end;
   if (answerList != []) then
          pos = pos + [Size(Str_Split(s, " "))];
          s = s + First(answerList);
          pos = pos + [Size(Str_Split(s, " "))];
   end;
   s = Wub_ReplaceAll(s, "|", "");

   var words = Str_Split(s, " ");
   var res = [];
   while pos != [] do
        var p = First(pos);
         pos = Rest(pos);
         var p2 = First(pos);
         pos = Rest(pos);
         var len = p2 - p;
         p = p - 2;
         if p < 0 then 
             p = 0;
         end;
         len = p + len + 4;
         if (len > Size(words)) then
             len = Size(words)
         end;
         s = "";
         every word in Select(words, p, len) do
            s = s + word + " ";
         end;
         res = res + [s = Str_Trim(s)];
   end;
   res;
end;

var res = [];
every answer in answers do
     var answerList = Str_Split(answer, ";");
     res = res + [putTogether(questionList, answerList)];
end;

res;