public function getCollocationsByPmi()
    {
        $nGramFreqDist = freq_dist(ngrams($this->tokens, $this->nGramSize));
        $unigramsFreqDist = freq_dist($this->tokens);
        
        $dataSet = [];
        foreach($nGramFreqDist->getKeys() as $nGramToken)
        {            
            $tokens = explode(" ", $nGramToken);
            $tally = 1;
            foreach($tokens as $unigramToken)
            {      
                $tally *= $unigramsFreqDist->getKeyValuesByWeight()[$unigramToken];
            }        
            
            // get probabilities of all tokens
            $dataSet[$nGramToken] = log($nGramFreqDist->getKeyValuesByWeight()[$nGramToken] / $tally );            
        }
        arsort($dataSet);
        return $dataSet;
    }
public function getCollocationsByPmi()
    {
        $nGramFreqDist = freq_dist(ngrams($this->tokens, $this->nGramSize));
        $unigramsFreqDist = freq_dist($this->tokens);
        
        $dataSet = [];
        foreach($nGramFreqDist->getKeys() as $nGramToken)
        {            
            $tokens = explode(" ", $nGramToken);
            $tally = 1;
            foreach($tokens as $unigramToken)
            {      
                $tally *= $unigramsFreqDist->getKeyValuesByWeight()[$unigramToken];
            }        
            
            // get probabilities of all tokens
            $dataSet[$nGramToken] = log($nGramFreqDist->getKeyValuesByWeight()[$nGramToken] / $tally );            
        }
        arsort($dataSet);
        return $dataSet;
    }
public function getCollocationsByPmi ( ) { $ nGramFreqDist = freq_dist ( ngrams ( $ this -> tokens , $ this -> nGramSize ) ) ; $ unigramsFreqDist = freq_dist ( $ this -> tokens ) ; $ dataSet = [ ] ; foreach ( $ nGramFreqDist -> getKeys ( ) as $ nGramToken ) { $ tokens = explode ( " " , $ nGramToken ) ; $ tally = 1 ; foreach ( $ tokens as $ unigramToken ) { $ tally *= $ unigramsFreqDist -> getKeyValuesByWeight ( ) [ $ unigramToken ] ; } // get probabilities of all tokens $ dataSet [ $ nGramToken ] = log ( $ nGramFreqDist -> getKeyValuesByWeight ( ) [ $ nGramToken ] / $ tally ) ; } arsort ( $ dataSet ) ; return $ dataSet ; }
Compute the Pointwise Mutual Information on the collocations
@return array
Compute the Pointwise Mutual Information on the collocations