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

99
LINES

< > BotCompany Repo | #1002412 // Turing Include

JavaX fragment (include)

1  
2  
static S url = "http://bots.tinybrain.de/1002076/raw";
3  
static S param = "q";
4  
static int delayPerQuestionMS = 50; // time for other threads to do something
5  
6  
static new L<L<S>> qlist; // questions and answers
7  
8  
static new L<S> protocol;
9  
10  
static class TuringScore {
11  
  S url;
12  
  long score, n;
13  
  long date;
14  
}
15  
16  
static PersistentMap<S, TuringScore> scores; // key = url
17  
18  
p {
19  
  scores = new PersistentMap("turing-scores.map");
20  
  
21  
  tests();
22  
  
23  
  prot("It is unix day " + unixDay() + " (timestamp " + unixTime() + "), and we are doing some Turing testing!");
24  
  prot("Test ID: " + formatSnippetID(getProgramID()));
25  
  prot();
26  
  prot("Made " + n(l(qlist), "question") + ".");
27  
  prot();
28  
  prot("Checking " + url + "...");
29  
  
30  
  int score = 0;
31  
  time {
32  
    for (L<S> qa : qlist) try {
33  
      S q = qa.get(0), a = qa.get(1);
34  
      
35  
      long t = now();
36  
      S result = getAnswer(q);
37  
      t = now()-t;
38  
      result = htmldecode(result);
39  
      S line = q + " => " + result + " [" + t + " ms]";
40  
      boolean ok = turingMatch(a, result);
41  
      if (ok) {
42  
        ++score;
43  
        prot("OK     " + line);
44  
      } else
45  
        prot("NOT OK expected: " + a + " - " + line);
46  
    } catch (Throwable e) {
47  
      prot(exceptionToUser(e));
48  
    }
49  
    
50  
    sleep(delayPerQuestionMS);
51  
  }
52  
  
53  
  prot("");
54  
  prot("Time elapsed: " + lastTiming() + " ms");
55  
  prot("");
56  
  prot(format("Score for *: * / *", url, score, l(qlist)));
57  
  
58  
  new TuringScore ts;
59  
  ts.date = now();
60  
  ts.url = url;
61  
  ts.score = score;
62  
  ts.n = l(qlist);
63  
  
64  
  logStructure(getProgramFile("turing-tests.log"), ts);
65  
  scores.put(url, ts);
66  
  
67  
  saveTextFile(getProgramFile("protocol-" + urlencode(url)), fromLines(protocol));
68  
}
69  
70  
static void add(S q, boolean yes) {
71  
  qlist.add(litlist(q, yes ? "yes" : "no"));
72  
}
73  
74  
static void add(S q, long number) {
75  
  qlist.add(litlist(q, str(number)));
76  
}
77  
78  
static void add(S q, S s) {
79  
  qlist.add(litlist(q, s));
80  
}
81  
82  
static void prot(S s) {
83  
  print(s);
84  
  protocol.add(s);
85  
}
86  
87  
static void prot() { prot(""); }
88  
89  
static S getAnswer(S q) {
90  
  O mainBot = getMainBot();
91  
  if (mainBot != null) {
92  
    // give us a dialog ID!
93  
    
94  
    callOpt(getOpt(mainBot, "dialogID"), "set", "turing-" + getProgramID());
95  
    
96  
    ret (S) call(mainBot, "answer", q);
97  
  } else
98  
    ret loadPage(url + "?" + makePostData(param, q));
99  
}

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: 667 / 1597
Version history: 1 change(s)
Referenced in: [show references]