Arriving here late, but since I came across this, trying to do something like this, I decided to share where I landed in 2019:
https://packagist.org/packages/yooper/php-text-analysis
This library made my task completely trivial. In my case, I had an array of search phrases, which I divided into separate terms, normalized, and then created ngrams from two and three words. Going through the obtained grams, I was able to easily summarize the frequency of specific phrases.
$words = tokenize($searchPhraseText); $words = normalize_tokens($words); $ngram2 = array_unique(ngrams($words, 2)); $ngram3 = array_unique(ngrams($words, 3));
Really cool library with a great deal.
source share