1 | !include #1003413 // LooseBot v5 |
2 | |
3 | sclass DateAdapter extends WordAdapter2 { |
4 | static L<S> months = splitAtSpace("___ January February March April May June July August September October November December"); |
5 | |
6 | S lookupToken(S s) { |
7 | int i = indexOf(months, s); |
8 | if (i >= 0) pcall { |
9 | S j = lookupToken(str(i)); |
10 | print("Month found! " + s + " => " + i + " => " + j); |
11 | if (nempty(j)) |
12 | ret months.get(parseInt(j)); |
13 | } |
14 | ret super.lookupToken(s); |
15 | } |
16 | |
17 | S get(S s) { |
18 | S o = countFixer(super.get(s)); |
19 | print("count fixed: " + o); |
20 | ret o; |
21 | } |
22 | } |
23 | |
24 | static O makeBot = func { |
25 | LooseBot bot = new LooseBot(botTree, func { new DateAdapter }) { |
26 | bool isCommand(E e) { |
27 | ret !isInput(e); |
28 | } |
29 | |
30 | // see Dialog Optimizer |
31 | bool isInput(E e) { |
32 | ret e.q() |
33 | || e.state() && matchStart("result is ", e.text()); |
34 | } |
35 | }; |
36 | bot.debug = true; |
37 | ret bot; |
38 | }; |
39 | |
40 | svoid expandDialogs(L<Dialog> dialogs) { |
41 | for (Dialog d : dialogs) |
42 | for (int i = 0; i < l(d.poem); i++) { |
43 | E e = d.poem.get(i); |
44 | if (!e.state()) continue; |
45 | int idx = e.text().indexOf('='); |
46 | if (idx < 0) continue; |
47 | d.poem.set(i, E.state("get " + e.text().substring(0, idx))); |
48 | d.poem.add(i+1, E.state("result is " + e.text().substring(idx+1))); |
49 | } |
50 | } |
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1003501 |
Snippet name: | Engine / What's the date |
Eternal ID of this version: | #1003501/1 |
Text MD5: | df11783d6bb99e52dab004131b59b180 |
Author: | stefan |
Category: | javax / talking robots |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-07-10 01:03:10 |
Source code size: | 1348 bytes / 50 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 496 / 1105 |
Referenced in: | [show references] |