// If the pope is in the house and the house is in the world, then is the pope in the world? !752 p { makeBot("Is In Bot."); } static S answer(S s) { new MultiMap isIn; new Matches m; if ( flexmatch("if the * is in the *, and the * is in the *, then is the * in the *?", s, m) || flexmatch("if the * is in the *, and the * is in the *, is the * in the *?", s, m)) { S a = m.unq(0), b = m.unq(1), c = m.unq(2), d = m.unq(3), e = m.unq(4), f = m.unq(5); isIn.put(a, b); isIn.put(c, d); ret makeAnswer(isIn, e, f); } if ( flexmatch("if the * is in the *, and the * is in the *, and the * is in the *, then is the * in the *?", s, m) || flexmatch("if the * is in the *, and the * is in the *, and the * is in the *, is the * in the *?", s, m)) { S a = m.unq(0), b = m.unq(1), c = m.unq(2), d = m.unq(3), e = m.unq(4), f = m.unq(5), g = m.unq(6), h = m.unq(7); isIn.put(a, b); isIn.put(c, d); isIn.put(e, f); ret makeAnswer(isIn, g, h); } ret null; } static S makeAnswer(MultiMap isIn, S e, S f) { boolean result = hasTransitive(isIn, e, f); if (result) ret format("Yes, the * is in the *.", e, f); else ret format("No, the * is not in the *.", e, f); } static boolean flexmatch(S pat, S s, Matches m) { pat = simplify1(pat); s = simplify1(s); if (match(pat, s, m)) ret true; pat = simplify2(pat); s = simplify2(s); ret match(pat, s, m); } // simplifications that seem safe static S simplify1(S s) { s = dropWords(s, "the", "an", "my", "your", "his", "her", "our", "their"); ret replaceWords(s, "are", "is", "on", "in", "am", "is"); } // simplifications that might fail (because a is a popular noun for this bot, like in "if a is in b and...2) static S simplify2(S s) { ret dropWords(s, "a"); }