Libraryless. Click here for Pure Java version (9834L/69K).
1 | !7 |
2 | |
3 | module QuestionDetectionTrainer > DynPrintLogAndEnabled { |
4 | transient Set<Thread> extraThreads = weakSet(); |
5 | |
6 | start { |
7 | thread { mainLoop(); } |
8 | } |
9 | |
10 | void mainLoop enter { |
11 | while true { |
12 | S x = input(); |
13 | if (!enabled) continue; |
14 | if (match_vbar("stop listening|stop training", x)) { |
15 | say("OK"); |
16 | setField(enabled := false); |
17 | interruptThreads(extraThreads); |
18 | } else if (probablyAQuestion(x)) |
19 | say("I don't know"); |
20 | else if (probablyNotAQuestion(x)) { |
21 | sayNothing(); |
22 | extraThreads.add(thread { |
23 | S y = input(); |
24 | if (match("That was a question", y)) { |
25 | saveIsQuestion(y, "yes"); |
26 | say("Oh, sorry. Stored."); |
27 | } |
28 | }); |
29 | } else { |
30 | say("Is that a question?"); |
31 | S y = input(); |
32 | if (dm_isYes(y)) { y = "yes"; say("OK, stored"); } |
33 | else if (dm_isNo(y)) { y = "no"; say("OK, stored"); } |
34 | else y = "(?) " + y; |
35 | saveIsQuestion(x, y); |
36 | } |
37 | } |
38 | } |
39 | |
40 | bool probablyAQuestion(S s) { ret false; } |
41 | bool probablyNotAQuestion(S s) { ret false; } |
42 | |
43 | void saveIsQuestion(S text, S isQuestion) { |
44 | dm_requireAndCallModule("#1020788/IsQuestionExamples", 'addEntry, text, isQuestion); |
45 | } |
46 | |
47 | void sayNothing() {} |
48 | |
49 | S input() { ret print("> ", dm_waitForTopInput()); } |
50 | void say(S s) { dm_say(s); } |
51 | } |
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: | 357 / 2365 |
Version history: | 18 change(s) |
Referenced in: | [show references] |