!7 concept Is { S a, b, mod; } module IsBot > DynAttractorBot { transient SimpleCRUD crud; // word -> language transient SS linkWords = reversePseudoMultiMapAsCIMap(litmap( "english" := litciset("is", "are", "am"), "german" := litciset("ist", "sind", "bin", "bist", "seid"))); PairS splitIt(S s) { LS tok = wordTok(s); int i = -1; if (l(tok) == 2*2+1) // two words i = 3; else { L determiners = indicesOfAny(tok, combinedMechSetsCI("Determiners", "German | Determiners"), 3); if (l(determiners) == 1) i = last(determiners); } ret i < 0 ? null : pair(joinSubList(tok, 1, i-1), joinSubList(tok, i, l(tok)-1)); } void storeAnswer(PairS p, S mod, S huh) { if (p == null) emitAnswer(huh); else { Collection mods = lookup(p.a, p.b); if (containsIC(mods, mod)) emitAnswer("I know"); else { uniqCI_sync Is(a := p.a, b := p.b, +mod); emitAnswer("Stored: " + p.a + " " + modToLinkPhrase(mod) + " " + p.b); } } } S modToLinkPhrase(S mod) { if (eqic(mod, 'yes)) ret "is"; if (eqic(mod, 'no)) ret "is not"; ret "is " + mod; } // returns mods Collection lookup(S a, S b) { ret collect mod(findConceptsWhereCI(Is, +a, +b)); } AttractorBot makeBot() { ret testBot(new SingleAttractorBot { PairS lastPair; // persistent void process(S s) { new Matches m; temp ai_setLanguages("english", "german"); s = ai_userSpaceToObjective(s); print("Got objective space input: " + s); if (matchX_any(mL("Is Bot | Yes Phrases"), s)) storeAnswer(lastPair, 'yes, "Yes what?"); if (matchX_any(mL("Is Bot | No Phrases"), s)) storeAnswer(lastPair, 'no, "No what?"); LS tok = wordTok(s); S linkWord = second(tok); S language = linkWords.get(linkWord); if (language == null) ret; bool g = eq(language, 'german); ai_setLanguages(language); // tautological case S s2 = joinSubList(tok, 3); if (matchDoubleRest("", s2)) ret with emitAnswer(g ? "Ja, natürlich" : "yes, obviously"); PairS p = splitIt(s2); if (p == null) ret with emitAnswer(g ? "Ich verstehe diesen Satz nicht" : "I can't parse that sentence"); lastPair = p; S a = p.a, b = p.b; Collection mods = lookup(a, b); if (nempty(mods)) emitAnswer(join(" and ", mods)); else emitAnswer(ai_objectiveSpaceToBot(g ? "Ich weiß nicht, ob " + a + " wohl " + b + " " + linkWord : "I don't know if " + a + " " + linkWord + " " + b)); } }); } AttractorBot testBot(AttractorBot bot) { testAttractorBotResponses_noFail(bot, "is green green?", "yes, obviously", "is a man a child?", "I don't know if a man is a child", "is sleep pleasant", "I don't know if sleep is pleasant"); ret bot; } start { dbIndexingCI(Is, 'a, Is, 'b); dm_localMechListCopies(); persistBot(); crud = SimpleCRUD(db_mainConcepts(), Is); } afterVisualize { addTab(tabs, "CRUD" := crud.make_dontStartBots()); } }