Skip to content

Commit d48e31d

Browse files
committed
Fixed variable names
The variable names were modified to the camelCase convention.
1 parent 252f6c8 commit d48e31d

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

src/NGrams/NGramFactory.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -55,54 +55,54 @@ static public function create(array $tokens, $nGramSize = self::BIGRAM, $separat
5555
static public function getFreq(array $ngrams, string $sep = ' ') : array
5656
{
5757
//getting the frequencies of the ngrams array and an array with no repetition
58-
$ngrams_unique = array_count_values($ngrams);
58+
$ngramsUnique = array_count_values($ngrams);
5959

6060
//array to be the product of this function
61-
$ngrams_final = array();
61+
$ngramsFinal = array();
6262

6363
//creates an array of tokens per ngram
64-
$ngrams_arry = self::ngramsAsArray($sep, $ngrams);
64+
$ngramsArray = self::ngramsAsArray($sep, $ngrams);
6565

6666
//interate the array with no repeated ngrams
67-
foreach ($ngrams_unique as $ngram_string => $ngram_frequency) {
68-
$ngrams_final[$ngram_string] = array($ngram_frequency); //putting into the final array an array of frequencies (first, the ngram frequency)
67+
foreach ($ngramsUnique as $ngramString => $ngramFrequency) {
68+
$ngramsFinal[$ngramString] = array($ngramFrequency); //putting into the final array an array of frequencies (first, the ngram frequency)
6969

70-
$ngram_array = explode($sep, $ngram_string); //getting an array of tokens of the ngram
71-
$ngram_size = count($ngram_array); //getting the size of ngram
72-
foreach ($ngram_array as $k_token => $token) { //iterating the array of tokens of the ngram
73-
$ngrams_final[$ngram_string][$k_token+1] = self::countFreq($ngrams_arry, $token, $k_token); //getting the frequency of the token
70+
$ngramArray = explode($sep, $ngramString); //getting an array of tokens of the ngram
71+
$ngramSize = count($ngramArray); //getting the size of ngram
72+
foreach ($ngramArray as $kToken => $token) { //iterating the array of tokens of the ngram
73+
$ngramsFinal[$ngramString][$kToken+1] = self::countFreq($ngramsArray, $token, $kToken); //getting the frequency of the token
7474

75-
if($ngram_size > 2) {
75+
if($ngramSize > 2) {
7676
//getting the combined frequency of the tokens
77-
for ($i = $k_token+1; $i < $ngram_size; $i++) {
78-
$ngrams_final[$ngram_string][$ngram_size+$k_token+$i] = self::countFreq($ngrams_arry, $token, $k_token, $ngram_array[$i], $i);
77+
for ($i = $kToken+1; $i < $ngramSize; $i++) {
78+
$ngramsFinal[$ngramString][$ngramSize+$kToken+$i] = self::countFreq($ngramsArray, $token, $kToken, $ngramArray[$i], $i);
7979
}
8080
}
8181
}
8282

8383
}
8484

85-
return $ngrams_final;
85+
return $ngramsFinal;
8686
}
8787

8888
/**
8989
* Count the number of times the given string(s) to the given position(s) occurs in the given ngrams array.
90-
* @param array $ngrams_arry
90+
* @param array $ngramsArray
9191
* @param string $str1
9292
* @param int $pos1
9393
* @param string $str2
9494
* @param int $pos2
9595
* @return int $count return the frequency
9696
*/
97-
static private function countFreq(array $ngrams_arry, string $str1, int $pos1, string $str2 = null, int $pos2 = null) : int
97+
static private function countFreq(array $ngramsArray, string $str1, int $pos1, string $str2 = null, int $pos2 = null) : int
9898
{
9999
$count = 0;
100100

101101
//counts the number of times the given string(s) to the given position(s) occurs in the given ngrams array.
102-
foreach ($ngrams_arry as $ngram_array) {
103-
if($str1 === $ngram_array[$pos1]) {
102+
foreach ($ngramsArray as $ngramArray) {
103+
if($str1 === $ngramArray[$pos1]) {
104104
if(isset($str2) && isset($pos2)) {
105-
if($str2 === $ngram_array[$pos2]) {
105+
if($str2 === $ngramArray[$pos2]) {
106106
$count++;
107107
}
108108
} else {
@@ -118,13 +118,13 @@ static private function countFreq(array $ngrams_arry, string $str1, int $pos1, s
118118
* Transform the ngram array to an array of their tokens
119119
* @param string $sep
120120
* @param array $ngrams
121-
* @return array $ngrams_arry
121+
* @return array $ngramsArray
122122
*/
123123
static private function ngramsAsArray(string $sep, array $ngrams) : array {
124-
$ngrams_arry = array();
124+
$ngramsArray = array();
125125
foreach($ngrams as $key => $ngram) {
126-
$ngrams_arry[] = explode($sep, $ngram);
126+
$ngramsArray[] = explode($sep, $ngram);
127127
}
128-
return $ngrams_arry;
128+
return $ngramsArray;
129129
}
130130
}

0 commit comments

Comments
 (0)