Warning: session_start(): open(/var/lib/php/sessions/sess_6l9bnc0gm3j6eam6ttq5n7m2j4, 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 theRiddle = [[
X is the first word in my text.
Is my text a letter or a program?
]];
sS theFacts = [[
"!" is a typical first word in a program.
"Hello" is a typical first word in a letter.
cdtwmxtqspigpyap confirms mibnjwgfxnetaxyz.
]];
sS conceptsUsed = [[
zcprevyllqdmyvcn kjuwvfidiwmbjsuc xzhtvnqwzuuzixci
mibnjwgfxnetaxyz cdtwmxtqspigpyap kdpoqkaoypqenusd
]];
static JTextArea ta;
static new L facts;
p-substance {
aiEnhancements();
L usedConcepts = findAIConcepts(conceptsUsed);
englishToConceptLanguage_concepts_global = usedConcepts;
facts = clParse(linesToCL(theFacts));
ta = showText("");
onChangeAndNow(ta, r {
fS text = getText(ta);
thread { think(text); }
});
requestFocus(ta);
}
sS firstWord(S s) {
if (empty(s)) ret "";
if (isLetterOrDigit(first(s)))
ret takeCharsWhile(s, f isLetterOrDigit);
else ret "" + first(s);
}
svoid think(S text) {
time {
S w = firstWord(text);
S riddle = formatXYZ(theRiddle, quote(w));
print(riddle);
L localFacts = concatLists(facts,
clParse(sentencesToCL(riddle)));
S answer = solveRiddle(localFacts);
S type = conceptToName(answer);
print("Answer: " + or2(type, "?"));
titleStatus_trailing(ta, empty(type) ? null : "Writing a " + type);
}
}
static L sentencesToCL(S text) {
ret listToCL(splitIntoSentences(text));
}
static L linesToCL(S text) {
ret listToCL(toLinesFullTrim(text));
}
static L listToCL(L l) {
new L out;
for (S line : l) {
S c = englishToConceptLanguage(line);
print(line + " => " + c);
out.add(c);
}
ret out;
}
// returns concept ID or null
static S solveRiddle(L facts) {
// Find the question
Lisp q = findHead(facts, "zcprevyllqdmyvcn");
if (q == null) fail("No question found");
S pivot = q.s(0);
L candidates = ll(q.s(1), q.s(2));
new Best best;
for i over candidates: {
S candidate = candidates.get(i);
new Web web;
web.newNode(pivot, candidate);
for (Lisp fact : facts)
web.relation(fact);
int score = web_countConfirms(web, facts);
if (score > 0)
best.put(candidate, score);
}
ret best.get();
}