sbool englishToConceptLanguage_multi_debug; static new ThreadLocal englishToConceptLanguage_multi_level; static L englishToConceptLanguage_multi(S s, O preprocess) { new L c; englishToConceptLanguage_multi(listCollector(c), s, preprocess); ret c; } static void englishToConceptLanguage_multi(Collector 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 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 out, S id, S name, S s) { new Matches m; L 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 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 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))); }