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)

1  
sbool englishToLisp_multi_debug;
2  
sbool englishToLisp_multi_left = true;
3  
4  
static new ThreadLocal<Int> englishToLisp_multi_level;
5  
6  
static L<Lisp> englishToLisp_multi(S s) {
7  
  ret englishToLisp_multi(s, null);
8  
}
9  
10  
static L<Lisp> englishToLisp_multi(S s, O preprocess) {
11  
  new L<Lisp> c;
12  
  englishToLisp_multi(listCollector(c), s, preprocess);
13  
  ret c;
14  
}
15  
16  
static void englishToLisp_multi(Collector<Lisp> out, S s, O preprocess) {
17  
  assertNotNull("Input", s);
18  
  /*int level = englishToLisp_multi_level.get();
19  
  if (level >= englishToLisp_multi_maxLevel) fail("max level");
20  
  englishToLisp_multi_level.set(level+1);
21  
  try {*/
22  
  s = postProcess(preprocess, s);
23  
  
24  
  // pattern matching all concepts against full string
25  
  for (AIConcept c : englishToConceptLanguage_concepts()) {
26  
    if (empty(c.name)) {
27  
      print("Warning, empty name: " + c.globalID);
28  
      continue;
29  
    }
30  
    S name = postProcess(preprocess, c.name);
31  
    englishToLisp_multi_with(out, c.globalID, name, s);
32  
    if (out.full()) ret;
33  
  }
34  
  
35  
  // no full string match. go word by word
36  
  /*
37  
  L<S> tok = javaTok(s);
38  
  if (l(tok) <= 3) ret;
39  
  for (int i = 1; i < l(tok); i += 2) {
40  
    S x = englishToLisp(unquote(tok.get(i)));
41  
    if (nempty(x)) tok.set(i, conceptQuote(x));
42  
  }
43  
  S x = join(tok);
44  
  if (neq(x, s)) out.add(x);
45  
  */
46  
}
47  
48  
static void englishToLisp_multi_with(Collector<Lisp> out, S id, S name, S s) {
49  
  L<S> originalTok = javaTok(name), tok = cloneList(originalTok);
50  
  if (l(tok) < 5) ret; // need 2 code tokens
51  
  /*if (englishToLisp_multi_debug)
52  
    print("xyz name " + name + " originalTok1 " + struct(originalTok));*/
53  
  bool stars = tok.contains("*");
54  
  if (stars)
55  
    tok = replace(tok, "*", "**");
56  
  /*if (englishToLisp_multi_debug)
57  
    print("xyz name " + name + " originalTok2 " + struct(originalTok));*/
58  
  int n = numberOfXYZVars(tok);
59  
  if (n == 0) ret;
60  
  tok = formatXYZ(tok, rep(n, "*"));
61  
  L<S> toks = javaTok_cached(s);
62  
  if (stars)
63  
    toks = replace(cloneList(toks), "*", "**");
64  
  for (Matches m : flexMatchIC2_left_multi(tok, toks)) {
65  
    if (englishToLisp_multi_debug)
66  
      print("xyz: " + n + " " + struct(tok) + " - " + struct(toks) + " => " + struct(m));
67  
    if (n != l(m.m)) ret; // that's really wrong
68  
    new TreeMap<Int, S> map;
69  
    if (englishToLisp_multi_debug)
70  
      print("xyz originalTok " + struct(originalTok));
71  
    for (int i = 1; i < l(originalTok); i += 2) {
72  
      S t = originalTok.get(i);
73  
      int x = xyzVarToIndex(t);
74  
      if (englishToLisp_multi_debug)
75  
        print("xyz " + t + " => " + x);
76  
      if (x != 0) {
77  
        //S sub = english+ToConceptLanguage_multi_sub(name, s, m.m[x-1]);
78  
        S sub = m.m[x-1];
79  
        map.put(i, sub);
80  
      }
81  
    }
82  
    if (out.add(aiUsing(lisp(id, values(map))))) ret;
83  
  }
84  
}

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: 378 / 415
Version history: 5 change(s)
Referenced in: [show references]