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).

!7

sO listBot;
concept Translation { S in, out; }
static JList lCommands, lLists;
p {
  graphite(); //magellan();
  tt(); centerConsole(700, 500);
  listBot = run(#1009228); db();
  if (isMainProgram()) {
    swing { addToWindowSplitRight_aggressive(consoleFrame(),
      jvsplit(
        withMargin(withCenteredTitle("Lists", lLists = jlist())),
        withMargin(withCenteredTitle("Commands", lCommands = jlist()))));
    }
    calcOnConceptChangesInOtherModule(listBot, 1000, f updateLists, true);
    updateCommandList(); botSleep();
  }
}

synchronized answer {
  translating: for (int safety = 0; safety < 10; safety++) {
    // TRANSLATIONS MANAGEMENT
    
    if "translations" ret struct(collectOrderedMap(list(Translation), 'in, 'out));
    if "add translation: * *" {
      Pair<Translation, Bool> p = uniq2(Translation, in := $1);
      cset(p.a, out := $2); updateCommandList();
      ret p.b ? "OK, saved" : "OK, overwritten";
    }
    if "remove translation: *" { deleteConcepts(Translation, in := $1); updateCommandList(); ret "OK"; }
    
    // TRY TRANSLATIONS
    
    for (Translation t) if (match(t.in, s, m)) {
      S translated = format(t.out, matchesToFormatArgs(m));
      print("Translated: " + s + " => " + translated);
      s = translated; continue translating;
    }
    break;
  }
  try answer callAnswerMethod(listBot, s); // forward verbatim
}

svoid updateCommandList { fillListWithStrings(lCommands, knownCommands()); }
svoid updateLists { fillListWithStrings(lLists, collectLists()); }

static L<S> knownCommands() {
  ret concatLists((L<S>) callOpt(listBot, 'knownCommands), findSupportedQuestionsInFunctions('answer), collect(list(Translation), 'in));
}

static synchronized L<S> collectLists() {
  ret map((Collection) call(listBot, 'list, 'TheList), func(O x) { _get(x, 'name) + " (" + l(_get(x, 'entries)) + ")" });
}

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: 550 / 871
Version history: 48 change(s)
Referenced in: [show references]