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

158
LINES

< > BotCompany Repo | #1002462 // Dynamic Turing Questions Bot

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (1987L/12K/42K).

!752

!include #1002461 // Source

static class TuringQuestion {
  S id;
  S question;
  S answer;
  Source source;
  int level; // difficulty level, 1 or higher (0 means 1)
}

// validate or invalidate a question
static class Val {
  S id; // turing question id
  boolean value;
  Source source;
  
  *() {}
  *(S *id, boolean *value, Source *source) {}
}

static new L<TuringQuestion> questions;
static long nextID = 1;
static new L<Val> vals;

p {
  load("questions");
  load("nextID");
  load("vals");
}

synchronized answer {
  if (match("list turing questions", s) || match("list tq", s)) {
    S url = "bots.tinybrain.de/1002408?id=" + parseSnippetID("#1002463");
    ret n(l(questions), "question") + ", results here: " + url + "\n" + simpleList();
  }
    
  if (match("full list turing questions", s) || match("full list tq", s))
    ret n(l(questions), "question") + "\n" + structureLines(questions);
  if (match("count turing questions", s) || match("count tq", s))
    ret str(l(questions));
    
  if "show tq * full" {
    S id = "tq" + m.unq(0);
    ret structure(findQuestion(id));
  }
  
  if (match("*", s, m)) {
    S x = m.unq(0);
    if (x.startsWith("tq"))
      ret structure(findQuestion(x));
  }
  
  // add last dialog as turing question
  if "add tq" {
    O dialog = last(getDialog());
    if (dialog == null) ret "No dialog to add";
    
    new TuringQuestion tq;
    tq.question = getString(dialog, "question");
    tq.answer = removeAtName(getString(dialog, "answer"));
    tq.source = new Source(s);
    ret addTQ(tq);
  }
    
  // add last question as turing question with custom answer
  if "add tq *" {
    O dialog = last(getDialog());
    if (dialog == null) ret "No dialog to add";
    
    new TuringQuestion tq;
    tq.question = getString(dialog, "question");
    tq.answer = m.unq(0);
    tq.source = new Source(s);
    ret addTQ(tq);
  }
    
  if (match("add tq * *", s, m) || match("add turing question * *", s, m)) {
    new TuringQuestion tq;
    tq.question = m.unq(0);
    tq.answer = m.unq(1);
    tq.source = new Source(s);
    ret addTQ(tq);
  }
  
  if (match("add tq level * * *", s, m) || match("add turing question level * * *", s, m)) {
    new TuringQuestion tq;
    tq.level = m.psi(0);
    tq.question = m.unq(1);
    tq.answer = m.unq(2);
    tq.source = new Source(s);
    ret addTQ(tq);
  }
  
  if (match("run tq", s) || match("run turing questions", s))
    ret askSelf(format("run turing test *", "#1002463"));
    
  if "run tq *" {
    S id = "tq" + m.unq(0);
    TuringQuestion tq = findQuestion(id);
    if (tq == null) ret "TQ not found";
    ret checkTQ(tq) ? id + " solved" : id +" not solved";
  }
    
  if "show tq *" {
    S id = "tq" + m.unq(0);
    TuringQuestion tq = findQuestion(id);
    if (tq == null) ret "TQ not found";
    ret tq.question + " => " + tq.answer;
  }
  
  if "invalidate tq *" {
    S id = "tq" + m.unq(0);
    TuringQuestion tq = findQuestion(id);
    if (tq == null) ret "TQ not found";
    vals.add(new Val(id, false, new Source(s)));
    save("vals");
    ret "OK, your input is recorded.";
  }
}

static synchronized TuringQuestion findQuestion(S id) {
  ret findByField(questions, "id", id);
}

static synchronized L<TuringQuestion> getLiveList() {
  ret cloneList(questions);
}

static synchronized S simpleList() {
  Map valsByID = indexByField(vals, "id");
  new L<S> l;
  for (TuringQuestion tq : questions) {
    boolean inv = valsByID.containsKey(tq.id);
    l.add(tq.question + " => " + tq.answer + (inv ? " (invalidated)" : ""));
  }
  ret fromLines(l);
}

static S html() {
  ret h3("Turing Questions")
    + sourceCodeToHTML(simpleList());
}

static S addTQ(TuringQuestion tq) {
  tq.id = "tq" + nextID++;
  save("nextID");
  questions.add(tq);
  save("questions");
  boolean solved = checkTQ(tq);
  ret "OK, added as question " + tq.id + ". "
    + (solved ? "Also, solved." : "Not solved yet.");
}

static boolean checkTQ(TuringQuestion tq) {
  ret turingMatch(tq.answer, askSelf(tq.question));
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1002462
Snippet name: Dynamic Turing Questions Bot
Eternal ID of this version: #1002462/1
Text MD5: e3e6e6c451a46919522e96e1e986b711
Transpilation MD5: a8f465feecabe48e5821c498605143fb
Author: stefan
Category: eleu
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-02-03 00:05:14
Source code size: 4175 bytes / 158 lines
Pitched / IR pitched: No / No
Views / Downloads: 658 / 1589
Referenced in: #1002463 - Turing Tests: Dynamic Questions (added by #1002462)
#3000179 - Answer for stefanreich
#3000180 - Answer for stefanreich
#3000181 - Answer for stefanreich
#3000182 - Answer for stefanreich
#3000184 - Answer for stefanreich
#3000185 - Answer for stefanreich
#3000190 - Answer for stefanreich(>> t 20 questions)
#3000195 - Answer for stefanreich (>> y)
#3000196 - Answer for stefanreich (>> y)
#3000197 - Answer for stefanreich (>> program data sizes)
#3000198 - Answer for stefanreich (>> program data sizes)
#3000199 - Answer for stefanreich (>> program data sizes)
#3000200 - Answer for stefanreich (>> program data sizes)
#3000201 - Answer for stefanreich (>> list all files)
#3000202 - Answer for stefanreich (>> T conversion bot)
#3000203 - Answer for stefanreich (>> timing hello bot)
#3000208 - Answer for bgrgndz (>> list sub bots)
#3000209 - Answer for bgrgndz (>> list sub bots)
#3000238 - Answer for stefanreich (>> t power bot)
#3000369 - Answer for Stefan (>> list sub bots)
#3000376 - Answer for stefanreich (>> list sub bots)
#3000377 - Answer for stefanreich (>> timing eleu?)
#3000380 - Answer for stefanreich (>> list sub bots)
#3000381 - Answer for speedforce (>> list sub bots)
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)