Completed
Push — develop ( 2f5171...da6d94 )
by Arkadiusz
03:00
created

StopWords::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
declare (strict_types = 1);
4
5
namespace Phpml\FeatureExtraction;
6
7
use Phpml\Exception\InvalidArgumentException;
8
9
class StopWords
10
{
11
    /**
12
     * @var array
13
     */
14
    protected $stopWords;
15
16
    /**
17
     * @param array $stopWords
18
     */
19
    public function __construct(array $stopWords)
20
    {
21
        $this->stopWords = array_fill_keys($stopWords, true);
22
    }
23
24
    /**
25
     * @param string $token
26
     *
27
     * @return bool
28
     */
29
    public function isStopWord(string $token): bool
30
    {
31
        return isset($this->stopWords[$token]);
32
    }
33
34
    /**
35
     * @param string $language
36
     *
37
     * @return StopWords
38
     *
39
     * @throws InvalidArgumentException
40
     */
41
    public static function factory($language = 'English'): StopWords
42
    {
43
        $className = __NAMESPACE__."\\StopWords\\$language";
44
45
        if (!class_exists($className)) {
46
            throw InvalidArgumentException::invalidStopWordsLanguage($language);
47
        }
48
49
        return new $className();
50
    }
51
}
52