static Triple ai_tripelize(S s) { S x = ""; if (endsWith(s, "?")) x = " (?)"; // statement with question mark, e.g. "Al Gore invented the Internet?" Triple t = ai_tripelize_impl(dropCertainPunctuationAtEnd(s, ":;,?!.")); ai_fixTriple(t); //print("After fix: " + t); if (nempty(x) && t != null && !endsWith(t.a, "?") && !endsWith(t.b, "?") && !endsWith(t.c, "?")) t.b += x; ret t; } static Triple ai_tripelize_impl(S s) { L original = ai_tripelize_prepare(s); if (l(original) <= 1) null; // no tokens L tok = original; S a = get(tok, 1); T3 triple; ret optional triple = ai_tripelize_exclamCommand(s, original); ret optional triple = ai_tripelize_howLongEtc(s, original); if (ai_questionWord_1(a)) { tok = subList(tok, 2); a = get(tok, 1); } S before = trimJoinSubList(original, 0, indexOfSubList(original, tok)); if (ai_yesNoQuestionWord_1(a) && neqicOneOf(a, "am", "are", "is")) { L tok2 = subList(tok, 2); int i = indexOfFirstVerb(tok2); S v = get(tok2, i); if (v != null) { S middle = trimJoinSubList(tok2, 0, i); S rest = trimJoinSubList(tok2, i+1); v = ai_tripelize_helperVerb(a, v); ret triple(joinWithSpace2(before, middle), v, rest); } } if (isVerb(a)) { tok = subList(tok, 2); int i = ai_splitTwoNounPhrases(tok); //int i = ai_endOfNounPhrase(tok); ret triple( trimJoinSubList(tok, 0, i), a + "?", trimJoinSubList(tok, i)); } int i = ai_endOfNounPhrase(tok); int j = indexOfFirstVerb(tok, i); if (j < 0) ret triple(s, "?", "?"); ret triple( joinWithSpace2(before, trimJoinSubList(tok, 0, j)), tok.get(j), trimJoinSubList(tok, j+2)); }