Skip to content

Commit

Permalink
Merge pull request #8 from bgruszka/fix-division-by-zero
Browse files Browse the repository at this point in the history
fixed "division by zero"
  • Loading branch information
bgruszka authored Aug 30, 2016
2 parents 12ed1b5 + 9b5bf43 commit 3cbef3e
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/DecisionMatrix/DefaultDecisionMatrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function getMostImportantLexemes()
$lexemes = $this->corpus->getLexemes($this->words);

foreach ($this->words as $word) {
if (strlen($word) > 0 && !in_array($word, $processedWords)) {
if (mb_strlen($word, 'utf-8') > 0 && !in_array($word, $processedWords)) {

// first occurrence of lexeme (unit lexeme)
if (!isset($lexemes[$word])) {
Expand Down
2 changes: 1 addition & 1 deletion src/Method/BurtonMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function calculate($text)
$this->setDecisionMatrix($text);
$this->setLexemesProbability();

return $this->bayes($this->decisionMatrix->getMostImportantLexemes(true));
return $this->bayes($this->decisionMatrix->getMostImportantLexemes());
}

protected function setDecisionMatrix($text)
Expand Down
2 changes: 1 addition & 1 deletion src/Method/FisherRobinsonInverseChiSquareMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class FisherRobinsonInverseChiSquareMethod extends Method
public function calculate($text)
{
$this->setDecisionMatrix($text);
$this->setLexemesProbability(true);
$this->setLexemesProbability();

return $this->fisherRobinsonsInverseChiSquareTest($this->decisionMatrix->getMostImportantLexemes());
}
Expand Down
6 changes: 2 additions & 4 deletions src/Method/Method.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected function calculateGrahamWordValue(
return $value;
}

protected function setLexemesProbability($withRobinson = false)
protected function setLexemesProbability()
{
$lexemes = $this->corpus->getLexemes($this->decisionMatrix->getWords());

Expand All @@ -73,9 +73,7 @@ protected function setLexemesProbability($withRobinson = false)
$this->corpus->messagesCount['nospam']
);

if ($withRobinson) {
$probability = $this->calculateRobinsonWordValue($value['spam'] + $value['nospam'], $probability);
}
$probability = $this->calculateRobinsonWordValue($value['spam'] + $value['nospam'], $probability);

$lexemes[$word]['probability'] = $probability;

Expand Down
2 changes: 1 addition & 1 deletion src/Method/RobinsonGeometricMeanTestMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class RobinsonGeometricMeanTestMethod extends Method
public function calculate($text)
{
$this->setDecisionMatrix($text);
$this->setLexemesProbability(true);
$this->setLexemesProbability();

return $this->robinsonGeometricMeanTest($this->decisionMatrix->getMostImportantLexemes());
}
Expand Down

0 comments on commit 3cbef3e

Please sign in to comment.