Libraryless. Click here for Pure Java version (7096L/47K).
1 | sclass AI_WhatIsBot > AttractorBot { |
2 | IDefinitions definitionsModule; |
3 | |
4 | public void run { |
5 | say("I can learn and tell you what things are"); |
6 | } |
7 | |
8 | // CONFIG |
9 | |
10 | class WhatIsAttractor > Attractor { |
11 | S term; |
12 | |
13 | public bool matches(S s) { |
14 | new Matches m; |
15 | if "what is ..." |
16 | ret true with term = $1; |
17 | false; |
18 | } |
19 | |
20 | public void run { |
21 | if (definitionsModule != null) { |
22 | Collection<S> defs = definitionsModule.getDefinitions(term); |
23 | if (nempty(defs)) { |
24 | say(term + " is " + random(defs)); |
25 | // TODO: attractors |
26 | ret; |
27 | } |
28 | } |
29 | say("I don't know. What is " + quote(term) + "?"); |
30 | lowPrioAttractor(new DefinitionAttractor(term)); |
31 | } |
32 | } |
33 | |
34 | record DefinitionAttractor(S term) extends Attractor { |
35 | S value; |
36 | |
37 | public bool matches(S s) { |
38 | new Matches m; |
39 | if "it's ...|it is...|he is...|she is..." |
40 | ret true with value = $1; |
41 | false; |
42 | } |
43 | |
44 | public void run { |
45 | say("OK. " + term + " is " + value + "."); |
46 | if (definitionsModule != null) |
47 | definitionsModule.addDefinition(term, value); |
48 | } |
49 | } |
50 | |
51 | *() { |
52 | standardAttractors(new WhatIsAttractor); |
53 | } |
54 | } |
Began life as a copy of #1022843
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1022965 |
Snippet name: | AI_WhatIsBot |
Eternal ID of this version: | #1022965/10 |
Text MD5: | fe9328894adc7f323cf6a2dca3a705ca |
Transpilation MD5: | 9fb7ddf738bf106200a6c0c9224a97a5 |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-04-16 16:56:38 |
Source code size: | 1266 bytes / 54 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 288 / 781 |
Version history: | 9 change(s) |
Referenced in: | [show references] |