static BasicLogicRule ai_sharedPhrasesIntoDollarVars(BasicLogicRule r) { LLS splits = stringsToLineCompSplits_wordMode(r.lhs, r.rhs); ifdef ai_sharedPhrasesIntoDollarVars_debug print(+splits); endifdef LS phrases = antiFilter isDollarVar(intersectCISets(splits)); SS map = ciMapWithUnusedCountingDollarVars(phrases, linesLL(r.lhs, r.rhs)); LLS splits2 = map(splits, l -> replaceElementsUsingMap(l, map)); ret listToBasicLogicRule(lambdaMap nlJoin(splits2)); }