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

79
LINES

< > BotCompany Repo | #1007966 // englishToConceptLanguage_multi [multiple outs, dev.]

JavaX fragment (include)

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

Author comment

Began life as a copy of #1007960

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: #1007966
Snippet name: englishToConceptLanguage_multi [multiple outs, dev.]
Eternal ID of this version: #1007966/11
Text MD5: 265fd0cf4516495c0073115d8c0a028c
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-17 22:10:52
Source code size: 2877 bytes / 79 lines
Pitched / IR pitched: No / No
Views / Downloads: 574 / 543
Version history: 10 change(s)
Referenced in: [show references]