Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

99
LINES

< > BotCompany Repo | #1002412 // Turing Include

JavaX fragment (include)

static S url = "http://bots.tinybrain.de/1002076/raw";
static S param = "q";
static int delayPerQuestionMS = 50; // time for other threads to do something

static new L<L<S>> qlist; // questions and answers

static new L<S> protocol;

static class TuringScore {
  S url;
  long score, n;
  long date;
}

static PersistentMap<S, TuringScore> scores; // key = url

p {
  scores = new PersistentMap("turing-scores.map");
  
  tests();
  
  prot("It is unix day " + unixDay() + " (timestamp " + unixTime() + "), and we are doing some Turing testing!");
  prot("Test ID: " + formatSnippetID(getProgramID()));
  prot();
  prot("Made " + n(l(qlist), "question") + ".");
  prot();
  prot("Checking " + url + "...");
  
  int score = 0;
  time {
    for (L<S> qa : qlist) try {
      S q = qa.get(0), a = qa.get(1);
      
      long t = now();
      S result = getAnswer(q);
      t = now()-t;
      result = htmldecode(result);
      S line = q + " => " + result + " [" + t + " ms]";
      boolean ok = turingMatch(a, result);
      if (ok) {
        ++score;
        prot("OK     " + line);
      } else
        prot("NOT OK expected: " + a + " - " + line);
    } catch (Throwable e) {
      prot(exceptionToUser(e));
    }
    
    sleep(delayPerQuestionMS);
  }
  
  prot("");
  prot("Time elapsed: " + lastTiming() + " ms");
  prot("");
  prot(format("Score for *: * / *", url, score, l(qlist)));
  
  new TuringScore ts;
  ts.date = now();
  ts.url = url;
  ts.score = score;
  ts.n = l(qlist);
  
  logStructure(getProgramFile("turing-tests.log"), ts);
  scores.put(url, ts);
  
  saveTextFile(getProgramFile("protocol-" + urlencode(url)), fromLines(protocol));
}

static void add(S q, boolean yes) {
  qlist.add(litlist(q, yes ? "yes" : "no"));
}

static void add(S q, long number) {
  qlist.add(litlist(q, str(number)));
}

static void add(S q, S s) {
  qlist.add(litlist(q, s));
}

static void prot(S s) {
  print(s);
  protocol.add(s);
}

static void prot() { prot(""); }

static S getAnswer(S q) {
  O mainBot = getMainBot();
  if (mainBot != null) {
    // give us a dialog ID!
    
    callOpt(getOpt(mainBot, "dialogID"), "set", "turing-" + getProgramID());
    
    ret (S) call(mainBot, "answer", q);
  } else
    ret loadPage(url + "?" + makePostData(param, q));
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1002412
Snippet name: Turing Include
Eternal ID of this version: #1002412/2
Text MD5: 870ba7574b3c18cc7a842ddbacf9af6b
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-06-23 14:43:58
Source code size: 2373 bytes / 99 lines
Pitched / IR pitched: No / No
Views / Downloads: 664 / 1592
Version history: 1 change(s)
Referenced in: [show references]