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

50
LINES

< > BotCompany Repo | #1003501 // Engine / What's the date

JavaX fragment (include)

!include #1003413 // LooseBot v5

sclass DateAdapter extends WordAdapter2 {
  static L<S> months = splitAtSpace("___ January February March April May June July August September October November December");

  S lookupToken(S s) {
    int i = indexOf(months, s);
    if (i >= 0) pcall {
      S j = lookupToken(str(i));
      print("Month found! " + s + " => " + i + " => " + j);
      if (nempty(j))
        ret months.get(parseInt(j));
    }
    ret super.lookupToken(s);
  }
  
  S get(S s) {
    S o = countFixer(super.get(s));
    print("count fixed: " + o);
    ret o;
  }
}

static O makeBot = func {
  LooseBot bot = new LooseBot(botTree, func { new DateAdapter }) {
    bool isCommand(E e) {
      ret !isInput(e);
    }
    
    // see Dialog Optimizer
    bool isInput(E e) {
      ret e.q()
        || e.state() && matchStart("result is ", e.text());
      }
    };
  bot.debug = true;
  ret bot;
};

svoid expandDialogs(L<Dialog> dialogs) {
  for (Dialog d : dialogs)
    for (int i = 0; i < l(d.poem); i++) {
      E e = d.poem.get(i);
      if (!e.state()) continue;
      int idx = e.text().indexOf('=');
      if (idx < 0) continue;
      d.poem.set(i, E.state("get " + e.text().substring(0, idx)));
      d.poem.add(i+1, E.state("result is " + e.text().substring(idx+1)));
    }
}

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: 425 / 1029
Referenced in: [show references]