Informative::accept()   A
last analyzed

Complexity

Conditions 6
Paths 7

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 6

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 6
eloc 8
c 1
b 1
f 0
nc 7
nop 0
dl 0
loc 17
ccs 9
cts 9
cp 1
crap 6
rs 9.2222
1
<?php
2
/**
3
 * AnalyzerText package.
4
 *
5
 * @author  Peter Gribanov <[email protected]>
6
 */
7
8
namespace AnalyzerText\Filter;
9
10
use AnalyzerText\Filter\WordList\Adverb;
11
use AnalyzerText\Filter\WordList\Interjection;
12
use AnalyzerText\Filter\WordList\Particle;
13
use AnalyzerText\Filter\WordList\Preposition;
14
use AnalyzerText\Filter\WordList\Pronoun;
15
use AnalyzerText\Filter\WordList\Union;
16
use AnalyzerText\Filter\WordList\WordList;
17
use AnalyzerText\Text;
18
19
/**
20
 * Оставляет только информационные слова.
21
 *
22
 * Сушествительные, глаголы, прилагательные, имена, фамилии
23
 *
24
 * @author  Peter Gribanov <[email protected]>
25
 */
26
class Informative extends Filter
27
{
28
    /**
29
     * Список фильтров.
30
     *
31
     * @var WordList[]
32
     */
33
    private $filters = array();
34
35
    /**
36
     * @param Text $iterator Текст
37
     */
38 8
    public function __construct(Text $iterator)
39
    {
40 8
        parent::__construct($iterator);
41 8
        $this->filters = array(
42 8
            new Interjection($this->getInnerIterator()),
43 8
            new Particle($this->getInnerIterator()),
44 8
            new Preposition($this->getInnerIterator()),
45 8
            new Pronoun($this->getInnerIterator()),
46 8
            new Union($this->getInnerIterator()),
47 8
            new Adverb($this->getInnerIterator()),
48
        );
49 8
    }
50
51
    /**
52
     * @see \FilterIterator::accept()
53
     */
54 8
    public function accept()
55
    {
56 8
        $word = $this->current();
57
        // сначала ищем последовательности
58 8
        foreach ($this->filters as $filter) {
59 8
            if ($filter->isSequence($word)) {
60 3
                return false;
61
            }
62
        }
63
        // ищем простые и сложные формы
64 7
        foreach ($this->filters as $filter) {
65 7
            if ($filter->isSimple($word) || $filter->isComposite($word)) {
66 7
                return false;
67
            }
68
        }
69
70 6
        return true;
71
    }
72
}
73