|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* AnalyzerText package. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Peter Gribanov <[email protected]> |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace AnalyzerText\Filter; |
|
9
|
|
|
|
|
10
|
|
|
use AnalyzerText\Analyzer\Analyzer; |
|
11
|
|
|
use AnalyzerText\Filter\WordList\Adverb; |
|
12
|
|
|
use AnalyzerText\Filter\WordList\Preposition; |
|
13
|
|
|
use AnalyzerText\Filter\WordList\Pronoun; |
|
14
|
|
|
use AnalyzerText\Filter\WordList\Union; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Фабрика фильтров. |
|
18
|
|
|
* |
|
19
|
|
|
* @author Peter Gribanov <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class Factory |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @var Analyzer |
|
25
|
|
|
*/ |
|
26
|
|
|
private $analyzer; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param Analyzer $analyzer |
|
30
|
|
|
*/ |
|
31
|
13 |
|
public function __construct(Analyzer $analyzer) |
|
32
|
|
|
{ |
|
33
|
13 |
|
$this->analyzer = $analyzer; |
|
34
|
13 |
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Применяет фильтр Informative. |
|
38
|
|
|
* |
|
39
|
|
|
* @return Factory |
|
40
|
|
|
*/ |
|
41
|
8 |
|
public function Informative() |
|
42
|
|
|
{ |
|
43
|
8 |
|
return $this->apply(new Informative($this->analyzer->getText())); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Применяет фильтр Preposition. |
|
48
|
|
|
* |
|
49
|
|
|
* @return Factory |
|
50
|
|
|
*/ |
|
51
|
1 |
|
public function Preposition() |
|
52
|
|
|
{ |
|
53
|
1 |
|
return $this->apply(new Preposition($this->analyzer->getText())); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Применяет фильтр Pronoun. |
|
58
|
|
|
* |
|
59
|
|
|
* @return Factory |
|
60
|
|
|
*/ |
|
61
|
1 |
|
public function Pronoun() |
|
62
|
|
|
{ |
|
63
|
1 |
|
return $this->apply(new Pronoun($this->analyzer->getText())); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Применяет фильтр Union. |
|
68
|
|
|
* |
|
69
|
|
|
* @return Factory |
|
70
|
|
|
*/ |
|
71
|
1 |
|
public function Union() |
|
72
|
|
|
{ |
|
73
|
1 |
|
return $this->apply(new Union($this->analyzer->getText())); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Применяет фильтр Adverb. |
|
78
|
|
|
* |
|
79
|
|
|
* @return Factory |
|
80
|
|
|
*/ |
|
81
|
1 |
|
public function Adverb() |
|
82
|
|
|
{ |
|
83
|
1 |
|
return $this->apply(new Adverb($this->analyzer->getText())); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Применяет фильтр |
|
88
|
|
|
* |
|
89
|
|
|
* @param Filter $filter |
|
90
|
|
|
* |
|
91
|
|
|
* @return Factory |
|
92
|
|
|
*/ |
|
93
|
12 |
|
private function apply(Filter $filter) |
|
94
|
|
|
{ |
|
95
|
12 |
|
if ($filter->getText()->count()) { |
|
96
|
12 |
|
$words = array(); |
|
97
|
12 |
|
foreach ($filter as $word) { |
|
98
|
10 |
|
$words[] = $word->getWord(); |
|
99
|
|
|
} |
|
100
|
12 |
|
$text_class = get_class($filter->getText()); |
|
101
|
12 |
|
$this->analyzer->setText(new $text_class(implode(' ', $words))); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
12 |
|
return $this; |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|