Uses 911K of libraries. Click here for Pure Java version (14869L/82K).
1 | !7 |
2 | |
3 | concept Entry { |
4 | S keyword, code; |
5 | bool enabled = true; |
6 | |
7 | sS _fieldOrder = "keyword code enabled"; |
8 | } |
9 | |
10 | set flag DynModule. |
11 | |
12 | cmodule KeywordToCode > DynCRUD<Entry> { |
13 | afterVisualize { |
14 | tablePopupMenuItemThreaded(table(), "Run", r { runEntry(selected(), "") }); |
15 | } |
16 | |
17 | start { |
18 | db(); |
19 | dm_onTopInput(voidfunc(fS s) { |
20 | thread { |
21 | //print("KtC got: " + s); |
22 | for (Entry e : list(Entry)) |
23 | if (e.enabled && matchMethod(e.keyword, s)) |
24 | runEntry(e, s); |
25 | } |
26 | }); |
27 | } |
28 | |
29 | void runEntry(Entry e, S input) enter { |
30 | if (e == null) ret; |
31 | print("KtC running #" + e.id); |
32 | S code = trim(e.code); |
33 | bool say = startsWith(code, "="); |
34 | if (say) code = substring(code, 1); |
35 | try { |
36 | temp tempSetTL(evalJava_prep_args, "fS s"); |
37 | O result = dm_evalJava_withModule(code, input); |
38 | if (say) dm_say(strOrNull(result)); |
39 | } catch print _e { |
40 | if (say) dm_say("Internal error, Sir"); |
41 | } |
42 | } |
43 | |
44 | // API |
45 | |
46 | bool matchMethod(S pat, S s) { |
47 | ret matchX_vbar(pat, s); |
48 | } |
49 | |
50 | bool isVoiceCommand(S s) { |
51 | for (Entry e : list(Entry)) |
52 | if (e.enabled && matchMethod(e.keyword, s)) |
53 | true; |
54 | false; |
55 | } |
56 | } |
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1018993 |
Snippet name: | Voice Commands [formerly: "Keyword To Code"] |
Eternal ID of this version: | #1018993/41 |
Text MD5: | c1dc583a653cb240439ec3e14db66f90 |
Transpilation MD5: | 757edcbd5374d5766788d5bbe72f7404 |
Author: | stefan |
Category: | javax / a.i. / gui |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-01-18 22:56:30 |
Source code size: | 1245 bytes / 56 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 600 / 12146 |
Version history: | 40 change(s) |
Referenced in: | [show references] |