sbool englishToLisp_multi_debug; sbool englishToLisp_multi_left = true; static new ThreadLocal englishToLisp_multi_level; static L englishToLisp_multi(S s) { ret englishToLisp_multi(s, null); } static L englishToLisp_multi(S s, O preprocess) { new L c; englishToLisp_multi(listCollector(c), s, preprocess); ret c; } static void englishToLisp_multi(Collector 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 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 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 (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 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 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)))); }