Skip to content

Commit

Permalink
#10. Add checking the worst words with probability to be mutated
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurkushman committed Jul 3, 2018
1 parent 2bb9565 commit 9f82391
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
15 changes: 15 additions & 0 deletions src/core/Words.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function processWords() : void
// to match lower case letters in words set array
$lowerSource = $this->addLowSpaces($this->text->getString());
/**
* 1st level checking discrete words with spaces
* @var string $points
* @var array $words
*/
Expand All @@ -57,6 +58,20 @@ public function processWords() : void
}
}
}
if ($this->score < self::ASTERISKS_MIDDLE) {
// 2nd level checking the worst (3 highest levels) words with probability to be mutated ex.: shittyass, crappish, unfuckkish etc
$slice = array_slice($this->dataSet->getWords(), 0, 3);
foreach ($slice as $points => $words) {
foreach ($words as $word) {
if (mb_strpos($lowerSource, $word) !== false) {
$this->score += (float)$points;
if ($this->text->isReplaceable()) {
$this->replace($word);
}
}
}
}
}
if ($this->score >= self::MAX_SCORE) {
$this->score = self::MAX_SCORE;
}
Expand Down
8 changes: 4 additions & 4 deletions src/dataset/EnglishSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ class EnglishSet implements SetContract
'vagina',
],
'0.9' => ['ugly', 'stupid', 'dumb', 'boobs', 'pish', 'fanny', 'slag', 'squirt', 'torture', 'ass', 'nitwit', 'whiffet'],
'0.8' => ['silly', 'tit', 'tits', 'pussy', 'sick', 'git', 'poop', 'slaughter'],
'0.7' => ['shallow', 'foolish', 'nonce', 'bugger', 'naught', 'prick', 'schmuck', 'nonentity', 'idiot'],
'0.8' => ['silly', 'pussy', 'sick', 'git', 'poop', 'slaughter', 'sperm'],
'0.7' => ['shallow', 'tit', 'tits', 'foolish', 'nonce', 'bugger', 'naught', 'prick', 'schmuck', 'nonentity', 'idiot'],
'0.6' => ['rednack', 'mindless', 'fat', 'nude', 'wft', 'snot', 'bloodbath', 'massacre', 'massacrer'],
'0.5' => ['bully', 'sneaky', 'greedy', 'creep', 'kill', 'revenge', 'catfight', 'die', 'death', 'nought', 'nonentity'],
'0.4' => ['superficial', 'numb', 'clown', 'villager', 'flatter', 'murder', 'nothingness'],
'0.3' => ['fake', 'strange', 'ignorant', 'critical', 'nuts', 'cum', 'genitals', 'retaliation', 'freak'],
'0.3' => ['fake', 'strange', 'ignorant', 'critical', 'nuts', 'cum', 'genitals', 'retaliation', 'freak', 'kick'],
'0.2' => ['useless', 'thoughtless', 'crazy', 'bollocks', 'bit', 'hit', 'exterminate', 'gangster'],
// <= 0.1 is almost noise for detox
'0.1' => ['punch', 'insect', 'annihilate', 'steal', 'kick', 'kidnap'],
'0.1' => ['punch', 'insect', 'annihilate', 'steal', 'kidnap'],
'0.06' => ['dude', 'pal', 'yo'],
];

Expand Down
20 changes: 16 additions & 4 deletions tests/dataset/WordsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ public function it_checks_words_on_score()
$this->assertEquals(0.9, $this->words->getScore());
// 0.8 level
$this->words->setScore(0);
$this->text->setString('She has tits');
$this->text->setString('There was a slaughter, they told me');
$this->words->setText($this->text);
$this->words->processWords();
$this->assertEquals(0.8, $this->words->getScore());
// 0.7 level
$this->words->setScore(0);
$this->text->setString('She is so foolish');
$this->text->setString('She has tits');
$this->words->setText($this->text);
$this->words->processWords();
$this->assertEquals(0.7, $this->words->getScore());
Expand Down Expand Up @@ -92,12 +92,12 @@ public function it_checks_words_on_score()
$this->words->setText($this->text);
$this->words->processWords();
$this->assertEquals(0.2, $this->words->getScore());
// 0.1 level
// 0.1 level and lower/noisier
$this->words->setScore(0);
$this->text->setString('Dude why are you saying so');
$this->words->setText($this->text);
$this->words->processWords();
$this->assertEquals(0.1, $this->words->getScore());
$this->assertEquals(0.06, $this->words->getScore());
}

/**
Expand Down Expand Up @@ -179,4 +179,16 @@ public function it_sets_custom_dict()
$this->words->processWords();
$this->assertEquals(0.9, $this->words->getScore());
}

/**
* @test
*/
public function it_checks_mutated_words()
{
$this->words->setScore(0);
$this->text->setString('Dude you look fuckingly cockish in that crappy situation');
$this->words->setText($this->text);
$this->words->processWords();
$this->assertEquals(1.0, $this->words->getScore());
}
}

0 comments on commit 9f82391

Please sign in to comment.