Source: site.view [edit]
Function name: readingTest
Arguments:
Description:
Page type: webl
Render function:  
Module: sataire

Page source:

// Oct 5, 2010:  3 correct 10 wrong 11 omitted  (yahoo search, full query string

// Oct 5, 2010: 7 correct 5 wrong 12 omitted (bing search, 5-grams

var test = WubCall("satQuestions", []);

var ChooseBest = fun(listOfQuestionLists)
   var bestScore = 0;
   var best = 0;
   var i = 1;
   every ql in listOfQuestionLists do
       var score = 0;
       every q in ql do
           score = score + WubCall("bingWebCount", [q, true]) ? 0;
           if score > bestScore then
              bestScore = score;
              best = i
           end;
           // best = best + [ [. q=q, score=score .] ];
        end;
        i = i + 1
   end;
   return best
end;

var IsFillInQuestion = fun(content)
   Str_IndexOf("_", content) >= 0
end;

var res = [];
var done = false;
every q in test do

   var g = q.group ? "";
   var c = q.content ? "content";
   var choices = q.choices ? "choices";

   if (g == "reading") then
      if IsFillInQuestion(c)  and !done then
         var qs = WubCall("fiveGramsAroundBlanks", [c, choices]);
         var best = ChooseBest(qs);
          done = false;
         res = res + [ [. id=q.id, answer=best.] ]
      end
   end;
end;

res;