!7 module QuestionDetectionTrainer > DynPrintLogAndEnabled { transient Set 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); } }