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

51
LINES

< > BotCompany Repo | #1020792 // Question Detection Trainer [OK]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Libraryless. Click here for Pure Java version (9834L/69K).

!7

module QuestionDetectionTrainer > DynPrintLogAndEnabled {
  transient Set<Thread> extraThreads = weakSet();
  
  start {
    thread { mainLoop(); }
  }
  
  void mainLoop enter {
    while true {
    	S x = input();
    	if (!enabled) continue;
    	if (match_vbar("stop listening|stop training", x)) {
    	  say("OK");
    	  setField(enabled := false);
    	  interruptThreads(extraThreads);
    	} else if (probablyAQuestion(x))
    	  say("I don't know");
    	else if (probablyNotAQuestion(x)) {
    	  sayNothing();
        extraThreads.add(thread {
          S y = input();
          if (match("That was a question", y)) {
            saveIsQuestion(y, "yes");
            say("Oh, sorry. Stored.");
          }
        });
      } else {
    	  say("Is that a question?");
    	  S y = input();
    	  if (dm_isYes(y)) { y = "yes"; say("OK, stored"); }
    	  else if (dm_isNo(y)) { y = "no"; say("OK, stored"); }
    	  else y = "(?) " + y;
    	  saveIsQuestion(x, y);
    	}
    }
  }
  
  bool probablyAQuestion(S s) { ret false; }
  bool probablyNotAQuestion(S s) { ret false; }
  
  void saveIsQuestion(S text, S isQuestion) {
    dm_requireAndCallModule("#1020788/IsQuestionExamples", 'addEntry, text, isQuestion);
  }
  
  void sayNothing() {}
  
  S input() { ret print("> ", dm_waitForTopInput()); }
  void say(S s) { dm_say(s); }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 8 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

-
Snippet ID: #1020792
Snippet name: Question Detection Trainer [OK]
Eternal ID of this version: #1020792/19
Text MD5: e33d60d679680807c0b4ac4005a3b5c1
Transpilation MD5: ce8f52e4913d7f7e96039c670bec0a11
Author: stefan
Category: javax / stefan's os
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-01-03 23:41:05
Source code size: 1405 bytes / 51 lines
Pitched / IR pitched: No / No
Views / Downloads: 356 / 2364
Version history: 18 change(s)
Referenced in: