sbool englishToConceptLanguage_multi_debug;
static new ThreadLocal<Int> englishToConceptLanguage_multi_level;
static L<S> englishToConceptLanguage_multi(S s, O preprocess) {
new L<S> c;
englishToConceptLanguage_multi(listCollector(c), s, preprocess);
ret c;
}
static void englishToConceptLanguage_multi(Collector<S> out, S s, O preprocess) {
assertNotNull("Input", s);
/*int level = englishToConceptLanguage_multi_level.get();
if (level >= englishToConceptLanguage_multi_maxLevel) fail("max level");
englishToConceptLanguage_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);
englishToConceptLanguage_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 = englishToConceptLanguage(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 englishToConceptLanguage_multi_with(Collector<S> 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 (englishToConceptLanguage_multi_debug)
print("xyz name " + name + " originalTok1 " + struct(originalTok));*/
bool stars = tok.contains("*");
if (stars)
tok = replace(tok, "*", "**");
/*if (englishToConceptLanguage_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 = flexMatchIC2(tok, toks, m, false);
if (englishToConceptLanguage_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 (englishToConceptLanguage_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 (englishToConceptLanguage_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];
if (l_javaTokC(sub) > 1) sub = "(" + sub + ")";
map.put(i, sub);
}
}
out.add(aiUsing(id) + " " + join(" ", values(map)));
}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: | 1113 / 994 |
| Version history: | 10 change(s) |
| Referenced in: | #1006654 - Standard functions list 2 (LIVE, continuation of #761) #1007969 - englishToLisp_multi [multiple outs, old] |