I've been trying to parse 300-400 word pieces of text and get all repeating 2/3/4 word phrases and I can't figure out the solution.
With one word commonalities I simply .split the text, .each_slice 1, then .map and .tally.
But with 2+ words, .each_slice doesn't work since I can't account for order.. For example the text is:
An alligator walked and an alligator walked alone.
It's gonna split to:
The alligator | walked and | another alligator | walked alone
What can I code to recognize that "alligator walked" repeats itself?
The only solution I can think of is removing the first word each time, that way the pair is gonna change constantly and get all options, but that seems awfully stupid..
Any help is appreciated!