Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

54
LINES

< > BotCompany Repo | #1009242 // ListenBot 1 [WORKS]

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Uses 3874K of libraries. Click here for Pure Java version (8719L/61K/206K).

1  
!7
2  
3  
sO listBot;
4  
concept Translation { S in, out; }
5  
static JList lCommands, lLists;
6  
p {
7  
  graphite(); //magellan();
8  
  tt(); centerConsole(700, 500);
9  
  listBot = run(#1009228); db();
10  
  if (isMainProgram()) {
11  
    swing { addToWindowSplitRight_aggressive(consoleFrame(),
12  
      jvsplit(
13  
        withMargin(withCenteredTitle("Lists", lLists = jlist())),
14  
        withMargin(withCenteredTitle("Commands", lCommands = jlist()))));
15  
    }
16  
    calcOnConceptChangesInOtherModule(listBot, 1000, f updateLists, true);
17  
    updateCommandList(); botSleep();
18  
  }
19  
}
20  
21  
synchronized answer {
22  
  translating: for (int safety = 0; safety < 10; safety++) {
23  
    // TRANSLATIONS MANAGEMENT
24  
    
25  
    if "translations" ret struct(collectOrderedMap(list(Translation), 'in, 'out));
26  
    if "add translation: * *" {
27  
      Pair<Translation, Bool> p = uniq2(Translation, in := $1);
28  
      cset(p.a, out := $2); updateCommandList();
29  
      ret p.b ? "OK, saved" : "OK, overwritten";
30  
    }
31  
    if "remove translation: *" { deleteConcepts(Translation, in := $1); updateCommandList(); ret "OK"; }
32  
    
33  
    // TRY TRANSLATIONS
34  
    
35  
    for (Translation t) if (match(t.in, s, m)) {
36  
      S translated = format(t.out, matchesToFormatArgs(m));
37  
      print("Translated: " + s + " => " + translated);
38  
      s = translated; continue translating;
39  
    }
40  
    break;
41  
  }
42  
  try answer callAnswerMethod(listBot, s); // forward verbatim
43  
}
44  
45  
svoid updateCommandList { fillListWithStrings(lCommands, knownCommands()); }
46  
svoid updateLists { fillListWithStrings(lLists, collectLists()); }
47  
48  
static L<S> knownCommands() {
49  
  ret concatLists((L<S>) callOpt(listBot, 'knownCommands), findSupportedQuestionsInFunctions('answer), collect(list(Translation), 'in));
50  
}
51  
52  
static synchronized L<S> collectLists() {
53  
  ret map((Collection) call(listBot, 'list, 'TheList), func(O x) { _get(x, 'name) + " (" + l(_get(x, 'entries)) + ")" });
54  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1009242
Snippet name: ListenBot 1 [WORKS]
Eternal ID of this version: #1009242/49
Text MD5: b6a4ae2db0fa0c8dbeeede809435513b
Transpilation MD5: f6e90f9d80842cc548ecb5a97437f3f4
Author: stefan
Category: javax / talking robots
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-07-25 17:45:14
Source code size: 1916 bytes / 54 lines
Pitched / IR pitched: No / No
Views / Downloads: 479 / 785
Version history: 48 change(s)
Referenced in: [show references]