src/NGrams/StatisticFacade.php
/**
    * Calculate the statistic for an ngram array
    * @param array $ngrams Array of ngrams
    * @param string $measure Name of the statistic measure
    * @param int $nGramSize Size of the ngrams
    * @return array Return the ngram array with the statistic values
    */
Calculate the statistic for an ngram array
@param array $ngrams Array of ngrams
@param string $measure Name of the statistic measure
@param int $nGramSize Size of the ngrams
@return array Return the ngram array with the statistic values
Calculate the statistic for an ngram array @param array $ngrams Array of ngrams @param string $measure Name of the statistic measure @param int $nGramSize Size of the ngrams @return array Return the ngram array with the statistic values
public static function calculate(array $ngrams, string $measure, int $nGramSize = 2) : array
    {
        $totalNgrams = array_sum(array_column($ngrams, 0));
        return array_map( function($item) use($measure, $totalNgrams, $nGramSize) {
            if ($nGramSize == 2) {
                return Statistic2D::$measure($item, $totalNgrams);
            } elseif ($nGramSize == 3) {
                return Statistic3D::$measure($item, $totalNgrams);
            } else {
                throw new \Exception("Size of the ngram informed invalid", 1);
            }
        }, $ngrams);
    }
public static function calculate ( array $ ngrams , string $ measure , int $ nGramSize = 2 ) : array { $ totalNgrams = array_sum ( array_column ( $ ngrams , 0 ) ) ; return array_map ( function ( $ item ) use ( $ measure , $ totalNgrams , $ nGramSize ) { if ( $ nGramSize == 2 ) { return Statistic2D :: $ measure ( $ item , $ totalNgrams ) ; } elseif ( $ nGramSize == 3 ) { return Statistic3D :: $ measure ( $ item , $ totalNgrams ) ; } else { throw new \ Exception ( " Size of the ngram informed invalid " , 1 ) ; } } , $ ngrams ) ; }
Calculate the statistic for an ngram array
 @param array $ngrams Array of ngrams
 @param string $measure Name of the statistic measure
 @param int $nGramSize Size of the ngrams
 @return array Return the ngram array with the statistic values
Calculate the statistic for an ngram array @param array $ngrams Array of ngrams @param string $measure Name of the statistic measure @param int $nGramSize Size of the ngrams @return array Return the ngram array with the statistic values