php-ml/tests/FeatureExtraction/StopWordsTest.php

56 lines
1.6 KiB
PHP
Raw Normal View History

2016-06-14 09:54:04 +00:00
<?php
2016-11-20 21:53:17 +00:00
declare(strict_types=1);
2016-06-14 09:54:04 +00:00
namespace Phpml\Tests\FeatureExtraction;
2016-06-14 09:54:04 +00:00
use Phpml\Exception\InvalidArgumentException;
2016-06-14 09:54:04 +00:00
use Phpml\FeatureExtraction\StopWords;
2017-02-03 11:58:25 +00:00
use PHPUnit\Framework\TestCase;
2016-06-14 09:54:04 +00:00
2017-02-03 11:58:25 +00:00
class StopWordsTest extends TestCase
2016-06-14 09:54:04 +00:00
{
public function testCustomStopWords(): void
2016-06-14 09:54:04 +00:00
{
$stopWords = new StopWords(['lorem', 'ipsum', 'dolor']);
$this->assertTrue($stopWords->isStopWord('lorem'));
$this->assertTrue($stopWords->isStopWord('ipsum'));
$this->assertTrue($stopWords->isStopWord('dolor'));
$this->assertFalse($stopWords->isStopWord('consectetur'));
$this->assertFalse($stopWords->isStopWord('adipiscing'));
$this->assertFalse($stopWords->isStopWord('amet'));
}
public function testThrowExceptionOnInvalidLanguage(): void
2016-06-14 09:54:04 +00:00
{
$this->expectException(InvalidArgumentException::class);
2016-06-14 09:54:04 +00:00
StopWords::factory('Lorem');
}
public function testEnglishStopWords(): void
2016-06-14 09:54:04 +00:00
{
$stopWords = StopWords::factory('English');
$this->assertTrue($stopWords->isStopWord('again'));
$this->assertFalse($stopWords->isStopWord('strategy'));
}
public function testPolishStopWords(): void
2016-06-14 09:54:04 +00:00
{
$stopWords = StopWords::factory('Polish');
$this->assertTrue($stopWords->isStopWord('wam'));
$this->assertFalse($stopWords->isStopWord('transhumanizm'));
}
public function testFrenchStopWords(): void
{
$stopWords = StopWords::factory('French');
$this->assertTrue($stopWords->isStopWord('alors'));
$this->assertFalse($stopWords->isStopWord('carte'));
}
2016-06-14 09:54:04 +00:00
}