Warning: session_start(): open(/var/lib/php/sessions/sess_drafbmilptlvs96e5qkmacudgt, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
sbool englishToConceptLanguage_xyz_debug, englishToConceptLanguage_useBrackets = true;
static new ThreadLocal englishToConceptLanguage_xyz_level;
sS englishToConceptLanguage_xyz(S s, O preprocess) {
assertNotNull("Input", s);
/*int level = englishToConceptLanguage_xyz_level.get();
if (level >= englishToConceptLanguage_xyz_maxLevel) fail("max level");
englishToConceptLanguage_xyz_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);
try answer englishToConceptLanguage_xyz_with(c.globalID, name, s);
}
// no full string match. go word by word
L tok = javaTok(s);
if (l(tok) <= 3) null;
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);
ret eq(x, s) ? null : x;
}
sS englishToConceptLanguage_xyz_sub(S name, S original, S s) {
if (l(s) >= l(original)) fail("Bad sub: " + quote(name) + " " + quote(s));
S s2 = or2(englishToConceptLanguage(s), s);
if (englishToConceptLanguage_xyz_debug)
print("xyz_sub " + quote(s) + " => " + quote(s2));
if (englishToConceptLanguage_useBrackets)
ret isIdentifier(s2) || isInteger(s2) || isProperlyQuoted(s2) ? s2 : "(" + s2 + ")";
ret conceptQuote(s2);
}
sS englishToConceptLanguage_xyz_with(S id, S s) {
ret englishToConceptLanguage_xyz_with(getAIConcept(id), s);
}
sS englishToConceptLanguage_xyz_with(AIConcept c, S s) {
if (c == null) null;
ret englishToConceptLanguage_xyz_with(c.globalID, c.name, s);
}
sS englishToConceptLanguage_xyz_with(S id, S name, S s) {
new Matches m;
L tok = javaTokC(name);
//replace(tok, "*", "\\*");
if (tok.contains("*")) null;
int n = numberOfXYZVars_c(tok);
if (n == 0) null;
S pat = formatXYZ(name, rep(n, "*"));
bool yes = flexMatchIC2(pat, s, m, false);
if (englishToConceptLanguage_xyz_debug && yes)
print("xyz: " + n + " " + pat + " - " + s + " => " + (yes ? struct(m) : "-"));
if (!yes) null;
assertEquals(name, n, l(m.m));
new TreeMap map;
for (int i = 1; i <= n; i++)
map.put(tok.indexOf(xyzIndexToVar(i)),
englishToConceptLanguage_xyz_sub(name, s, m.m[i-1]));
ret aiUsing(id) + " " + join(" ", values(map));
}