Warning: session_start(): open(/var/lib/php/sessions/sess_h70k94ktu4b8voqjtn1dd4iuct, 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
!7
sS verbs = toLinesFullTrim([[
kow towed
made
started
want
]]);
sclass StringTree {
bool ok;
new HashMap children;
StringTree getOrAdd(S s) {
StringTree t = children.get(s);
if (t == null)
children.put(s, t = new StringTree);
ret t;
}
}
static new StringTree tree;
p {
tree = multiWordMap_lower(verbs);
callAnswerFunctionVerbose("he kow towed before them");
callAnswerFunctionVerbose("i want stuff");
botSleep();
}
static StringTree multiWordMap_lower(S items) {
new StringTree tree;
for (S s : items) {
L tok = codeTokens(nlTok4(lower(s)));
addToTree(tree, tok);
}
ret tree;
}
svoid addToTree(StringTree tree, L tok) {
if (empty(tok)) { tree.ok = true; ret; }
S s = first(tok);
StringTree t = tree.getOrAdd(s);
addToTree(t, dropFirst(tok));
}
sS answer(S s) {
L tok = codeTokens(nlTok4(lower(s)));
new L verbs;
for i over tok: {
StringTree tree = main.tree;
int j = i;
while (tree != null && j < l(tok)) {
if (tree.ok)
verbs.add(joinWithSpace(subList(tok, i, j)));
tree = tree.children.get(tok.get(j));
++j;
}
}
ret join(", ", verbs);
}