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

84
LINES

< > BotCompany Repo | #1007990 // englishToLisp_multi [multiple outs, using flexMatchIC_left_multi, LIVE]

JavaX fragment (include)

sbool englishToLisp_multi_debug;
sbool englishToLisp_multi_left = true;

static new ThreadLocal<Int> englishToLisp_multi_level;

static L<Lisp> englishToLisp_multi(S s) {
  ret englishToLisp_multi(s, null);
}

static L<Lisp> englishToLisp_multi(S s, O preprocess) {
  new L<Lisp> c;
  englishToLisp_multi(listCollector(c), s, preprocess);
  ret c;
}

static void englishToLisp_multi(Collector<Lisp> out, S s, O preprocess) {
  assertNotNull("Input", s);
  /*int level = englishToLisp_multi_level.get();
  if (level >= englishToLisp_multi_maxLevel) fail("max level");
  englishToLisp_multi_level.set(level+1);
  try {*/
  s = postProcess(preprocess, s);
  
  // pattern matching all concepts against full string
  for (AIConcept c : englishToConceptLanguage_concepts()) {
    if (empty(c.name)) {
      print("Warning, empty name: " + c.globalID);
      continue;
    }
    S name = postProcess(preprocess, c.name);
    englishToLisp_multi_with(out, c.globalID, name, s);
    if (out.full()) ret;
  }
  
  // no full string match. go word by word
  /*
  L<S> tok = javaTok(s);
  if (l(tok) <= 3) ret;
  for (int i = 1; i < l(tok); i += 2) {
    S x = englishToLisp(unquote(tok.get(i)));
    if (nempty(x)) tok.set(i, conceptQuote(x));
  }
  S x = join(tok);
  if (neq(x, s)) out.add(x);
  */
}

static void englishToLisp_multi_with(Collector<Lisp> out, S id, S name, S s) {
  L<S> originalTok = javaTok(name), tok = cloneList(originalTok);
  if (l(tok) < 5) ret; // need 2 code tokens
  /*if (englishToLisp_multi_debug)
    print("xyz name " + name + " originalTok1 " + struct(originalTok));*/
  bool stars = tok.contains("*");
  if (stars)
    tok = replace(tok, "*", "**");
  /*if (englishToLisp_multi_debug)
    print("xyz name " + name + " originalTok2 " + struct(originalTok));*/
  int n = numberOfXYZVars(tok);
  if (n == 0) ret;
  tok = formatXYZ(tok, rep(n, "*"));
  L<S> toks = javaTok_cached(s);
  if (stars)
    toks = replace(cloneList(toks), "*", "**");
  for (Matches m : flexMatchIC2_left_multi(tok, toks)) {
    if (englishToLisp_multi_debug)
      print("xyz: " + n + " " + struct(tok) + " - " + struct(toks) + " => " + struct(m));
    if (n != l(m.m)) ret; // that's really wrong
    new TreeMap<Int, S> map;
    if (englishToLisp_multi_debug)
      print("xyz originalTok " + struct(originalTok));
    for (int i = 1; i < l(originalTok); i += 2) {
      S t = originalTok.get(i);
      int x = xyzVarToIndex(t);
      if (englishToLisp_multi_debug)
        print("xyz " + t + " => " + x);
      if (x != 0) {
        //S sub = english+ToConceptLanguage_multi_sub(name, s, m.m[x-1]);
        S sub = m.m[x-1];
        map.put(i, sub);
      }
    }
    if (out.add(aiUsing(lisp(id, values(map))))) ret;
  }
}

Author comment

Began life as a copy of #1007969

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: #1007990
Snippet name: englishToLisp_multi [multiple outs, using flexMatchIC_left_multi, LIVE]
Eternal ID of this version: #1007990/6
Text MD5: 8812d36eace442878fbc7131d7d03158
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-04-18 03:15:12
Source code size: 2808 bytes / 84 lines
Pitched / IR pitched: No / No
Views / Downloads: 370 / 407
Version history: 5 change(s)
Referenced in: [show references]