sbool ai_findInfixPhrases_debug; static ItIt> ai_findInfixPhrases(S s, Collection phrases) { final Set set = asCISet(phrases); L tok = javaTokNPunctuation(s); ret notNulls_iterator( // first, split on the left nestedIterator(allTokSplits_nOnRight_iterator(tok), func(final Pair p) -> ItIt> { // now split the right part if (ai_findInfixPhrases_debug) print("Looking at " + join(p.b)); L tok2 = javaTokNPunctuation(join(p.b)); ret mapI(allTokSplits_nOnLeft_iterator(tok2), func(Pair p2) -> T3 { if (ai_findInfixPhrases_debug) print(" Looking at " + p2.a); ret set.contains(trimJoin(simpleSpaces(p2.a))) ? t3(join(p.a), join(p2.a), join(p2.b)) : null; }); })); }