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

87
LINES

< > BotCompany Repo | #1007969 // englishToLisp_multi [multiple outs, old]

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) {
  new Matches m;
  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), "*", "**");
  bool yes = englishToLisp_multi_left
    ? flexMatchIC2_left(tok, toks, m, false)
    : flexMatchIC2(tok, toks, m, false);
  if (englishToLisp_multi_debug && yes)
    print("xyz: " + n + " " + struct(tok) + " - " + struct(toks) + " => " + (yes ? struct(m) : "-"));
  if (!yes) ret;
  if (n != l(m.m)) ret;
  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);
    }
  }
  out.add(aiUsing(lisp(id, values(map))));
}

Author comment

Began life as a copy of #1007966

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: #1007969
Snippet name: englishToLisp_multi [multiple outs, old]
Eternal ID of this version: #1007969/9
Text MD5: 7cc6c07989e5e5ea84e29a69a8a8bd5c
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:23
Source code size: 2861 bytes / 87 lines
Pitched / IR pitched: No / No
Views / Downloads: 491 / 484
Version history: 8 change(s)
Referenced in: [show references]