Passed
Pull Request — master (#9)
by Peter
04:02
created
AnalyzerText/Analyzer/Frequency.php 2 patches
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -14,67 +14,67 @@
 block discarded – undo
14 14
  */
15 15
 class Frequency extends Analyzer
16 16
 {
17
-    /**
18
-     * Список слов с частотой их появления.
19
-     *
20
-     * @var array
21
-     */
22
-    protected $frequencies = array();
17
+	/**
18
+	 * Список слов с частотой их появления.
19
+	 *
20
+	 * @var array
21
+	 */
22
+	protected $frequencies = array();
23 23
 
24
-    /**
25
-     * Список слов с частотой их появления в процентах.
26
-     *
27
-     * @var array
28
-     */
29
-    protected $percent = array();
24
+	/**
25
+	 * Список слов с частотой их появления в процентах.
26
+	 *
27
+	 * @var array
28
+	 */
29
+	protected $percent = array();
30 30
 
31
-    /**
32
-     * Очищает анализатор
33
-     *
34
-     * @return \AnalyzerText\Analyzer\Frequency
35
-     */
36
-    public function clear()
37
-    {
38
-        $this->frequencies = array();
39
-        $this->percent = array();
31
+	/**
32
+	 * Очищает анализатор
33
+	 *
34
+	 * @return \AnalyzerText\Analyzer\Frequency
35
+	 */
36
+	public function clear()
37
+	{
38
+		$this->frequencies = array();
39
+		$this->percent = array();
40 40
 
41
-        return parent::clear();
42
-    }
41
+		return parent::clear();
42
+	}
43 43
 
44
-    /**
45
-     * Определяет частоту появления слов.
46
-     *
47
-     * @return array
48
-     */
49
-    public function getFrequency()
50
-    {
51
-        if (!$this->frequencies && $this->getText()->count()) {
52
-            foreach ($this->getText() as $word) {
53
-                if (!isset($this->frequencies[$word->getPlain()])) {
54
-                    $this->frequencies[$word->getPlain()] = 0;
55
-                }
56
-                ++$this->frequencies[$word->getPlain()];
57
-            }
58
-            arsort($this->frequencies);
59
-        }
44
+	/**
45
+	 * Определяет частоту появления слов.
46
+	 *
47
+	 * @return array
48
+	 */
49
+	public function getFrequency()
50
+	{
51
+		if (!$this->frequencies && $this->getText()->count()) {
52
+			foreach ($this->getText() as $word) {
53
+				if (!isset($this->frequencies[$word->getPlain()])) {
54
+					$this->frequencies[$word->getPlain()] = 0;
55
+				}
56
+				++$this->frequencies[$word->getPlain()];
57
+			}
58
+			arsort($this->frequencies);
59
+		}
60 60
 
61
-        return $this->frequencies;
62
-    }
61
+		return $this->frequencies;
62
+	}
63 63
 
64
-    /**
65
-     * Получение проуентное отнашение частоты слов из списка частот слов.
66
-     *
67
-     * @return array
68
-     */
69
-    public function getPercent()
70
-    {
71
-        if (!$this->percent && ($frequencies = $this->getFrequency())) {
72
-            $ratio = max($frequencies) / 100;
73
-            foreach ($frequencies as $word => $frequency) {
74
-                $this->percent[$word] = $frequency / $ratio;
75
-            }
76
-        }
64
+	/**
65
+	 * Получение проуентное отнашение частоты слов из списка частот слов.
66
+	 *
67
+	 * @return array
68
+	 */
69
+	public function getPercent()
70
+	{
71
+		if (!$this->percent && ($frequencies = $this->getFrequency())) {
72
+			$ratio = max($frequencies) / 100;
73
+			foreach ($frequencies as $word => $frequency) {
74
+				$this->percent[$word] = $frequency / $ratio;
75
+			}
76
+		}
77 77
 
78
-        return $this->percent;
79
-    }
78
+		return $this->percent;
79
+	}
80 80
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -69,9 +69,9 @@
 block discarded – undo
69 69
     public function getPercent()
70 70
     {
71 71
         if (!$this->percent && ($frequencies = $this->getFrequency())) {
72
-            $ratio = max($frequencies) / 100;
72
+            $ratio = max($frequencies)/100;
73 73
             foreach ($frequencies as $word => $frequency) {
74
-                $this->percent[$word] = $frequency / $ratio;
74
+                $this->percent[$word] = $frequency/$ratio;
75 75
             }
76 76
         }
77 77
 
Please login to merge, or discard this patch.
AnalyzerText/Analyzer/Analyzer.php 1 patch
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -17,57 +17,57 @@
 block discarded – undo
17 17
  */
18 18
 abstract class Analyzer
19 19
 {
20
-    /**
21
-     * Текст
22
-     *
23
-     * @var \AnalyzerText\Text
24
-     */
25
-    protected $text;
20
+	/**
21
+	 * Текст
22
+	 *
23
+	 * @var \AnalyzerText\Text
24
+	 */
25
+	protected $text;
26 26
 
27
-    /**
28
-     * Устанавливает аналезируемый текст
29
-     *
30
-     * @param \AnalyzerText\Text $text Текст
31
-     *
32
-     * @return \AnalyzerText\Analyzer\Analyze
33
-     */
34
-    public function setText(Text $text)
35
-    {
36
-        $this->clear();
37
-        $this->text = $text;
27
+	/**
28
+	 * Устанавливает аналезируемый текст
29
+	 *
30
+	 * @param \AnalyzerText\Text $text Текст
31
+	 *
32
+	 * @return \AnalyzerText\Analyzer\Analyze
33
+	 */
34
+	public function setText(Text $text)
35
+	{
36
+		$this->clear();
37
+		$this->text = $text;
38 38
 
39
-        return $this;
40
-    }
39
+		return $this;
40
+	}
41 41
 
42
-    /**
43
-     * Возвращает список слов.
44
-     *
45
-     * @return \AnalyzerText\Text
46
-     */
47
-    public function getText()
48
-    {
49
-        return $this->text;
50
-    }
42
+	/**
43
+	 * Возвращает список слов.
44
+	 *
45
+	 * @return \AnalyzerText\Text
46
+	 */
47
+	public function getText()
48
+	{
49
+		return $this->text;
50
+	}
51 51
 
52
-    /**
53
-     * Очищает анализатор
54
-     *
55
-     * @return \AnalyzerText\Analyzer\Analyze
56
-     */
57
-    public function clear()
58
-    {
59
-        $this->text = null;
52
+	/**
53
+	 * Очищает анализатор
54
+	 *
55
+	 * @return \AnalyzerText\Analyzer\Analyze
56
+	 */
57
+	public function clear()
58
+	{
59
+		$this->text = null;
60 60
 
61
-        return $this;
62
-    }
61
+		return $this;
62
+	}
63 63
 
64
-    /**
65
-     * Возвращает фабрику фильтров для применения их.
66
-     *
67
-     * @return AnalyzerText\Filter\Factory
68
-     */
69
-    public function applyFilters()
70
-    {
71
-        return new Factory($this);
72
-    }
64
+	/**
65
+	 * Возвращает фабрику фильтров для применения их.
66
+	 *
67
+	 * @return AnalyzerText\Filter\Factory
68
+	 */
69
+	public function applyFilters()
70
+	{
71
+		return new Factory($this);
72
+	}
73 73
 }
Please login to merge, or discard this patch.
AnalyzerText/Filter/Informative.php 1 patch
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -24,52 +24,52 @@
 block discarded – undo
24 24
  */
25 25
 class Informative extends Filter
26 26
 {
27
-    /**
28
-     * Список фильтров.
29
-     *
30
-     * @var array
31
-     */
32
-    private $filters = array();
27
+	/**
28
+	 * Список фильтров.
29
+	 *
30
+	 * @var array
31
+	 */
32
+	private $filters = array();
33 33
 
34
-    /**
35
-     * Конструктор
36
-     *
37
-     * @param \AnalyzerText\Text $iterator Текст
38
-     */
39
-    public function __construct(Text $iterator)
40
-    {
41
-        parent::__construct($iterator);
42
-        $this->filters = array(
43
-            new Interjection($this->getInnerIterator()),
44
-            new Particle($this->getInnerIterator()),
45
-            new Preposition($this->getInnerIterator()),
46
-            new Pronoun($this->getInnerIterator()),
47
-            new Union($this->getInnerIterator()),
48
-            new Adverb($this->getInnerIterator()),
49
-        );
50
-    }
34
+	/**
35
+	 * Конструктор
36
+	 *
37
+	 * @param \AnalyzerText\Text $iterator Текст
38
+	 */
39
+	public function __construct(Text $iterator)
40
+	{
41
+		parent::__construct($iterator);
42
+		$this->filters = array(
43
+			new Interjection($this->getInnerIterator()),
44
+			new Particle($this->getInnerIterator()),
45
+			new Preposition($this->getInnerIterator()),
46
+			new Pronoun($this->getInnerIterator()),
47
+			new Union($this->getInnerIterator()),
48
+			new Adverb($this->getInnerIterator()),
49
+		);
50
+	}
51 51
 
52
-    /**
53
-     * (non-PHPdoc).
54
-     *
55
-     * @see \FilterIterator::accept()
56
-     */
57
-    public function accept()
58
-    {
59
-        $word = $this->current();
60
-        // сначала ищем последовательности
61
-        foreach ($this->filters as $filter) {
62
-            if ($filter->isSequence($word)) {
63
-                return false;
64
-            }
65
-        }
66
-        // ищем простые и сложные формы
67
-        foreach ($this->filters as $filter) {
68
-            if ($filter->isSimple($word) || $filter->isComposite($word)) {
69
-                return false;
70
-            }
71
-        }
52
+	/**
53
+	 * (non-PHPdoc).
54
+	 *
55
+	 * @see \FilterIterator::accept()
56
+	 */
57
+	public function accept()
58
+	{
59
+		$word = $this->current();
60
+		// сначала ищем последовательности
61
+		foreach ($this->filters as $filter) {
62
+			if ($filter->isSequence($word)) {
63
+				return false;
64
+			}
65
+		}
66
+		// ищем простые и сложные формы
67
+		foreach ($this->filters as $filter) {
68
+			if ($filter->isSimple($word) || $filter->isComposite($word)) {
69
+				return false;
70
+			}
71
+		}
72 72
 
73
-        return true;
74
-    }
73
+		return true;
74
+	}
75 75
 }
Please login to merge, or discard this patch.
AnalyzerText/Filter/Factory.php 1 patch
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -20,91 +20,91 @@
 block discarded – undo
20 20
  */
21 21
 class Factory
22 22
 {
23
-    /**
24
-     * Анализатор
25
-     *
26
-     * @var \AnalyzerText\Analyzer\Analyzer
27
-     */
28
-    private $analyzer;
23
+	/**
24
+	 * Анализатор
25
+	 *
26
+	 * @var \AnalyzerText\Analyzer\Analyzer
27
+	 */
28
+	private $analyzer;
29 29
 
30
-    /**
31
-     * Конструктор
32
-     *
33
-     * @param \AnalyzerText\Analyzer\Analyzer $analyzer Анализатор
34
-     */
35
-    public function __construct(Analyzer $analyzer)
36
-    {
37
-        $this->analyzer = $analyzer;
38
-    }
30
+	/**
31
+	 * Конструктор
32
+	 *
33
+	 * @param \AnalyzerText\Analyzer\Analyzer $analyzer Анализатор
34
+	 */
35
+	public function __construct(Analyzer $analyzer)
36
+	{
37
+		$this->analyzer = $analyzer;
38
+	}
39 39
 
40
-    /**
41
-     * Применяет фильтр Informative.
42
-     *
43
-     * @return \AnalyzerText\Filter\Factory
44
-     */
45
-    public function Informative()
46
-    {
47
-        return $this->apply(new Informative($this->analyzer->getText()));
48
-    }
40
+	/**
41
+	 * Применяет фильтр Informative.
42
+	 *
43
+	 * @return \AnalyzerText\Filter\Factory
44
+	 */
45
+	public function Informative()
46
+	{
47
+		return $this->apply(new Informative($this->analyzer->getText()));
48
+	}
49 49
 
50
-    /**
51
-     * Применяет фильтр Preposition.
52
-     *
53
-     * @return \AnalyzerText\Filter\Factory
54
-     */
55
-    public function Preposition()
56
-    {
57
-        return $this->apply(new Preposition($this->analyzer->getText()));
58
-    }
50
+	/**
51
+	 * Применяет фильтр Preposition.
52
+	 *
53
+	 * @return \AnalyzerText\Filter\Factory
54
+	 */
55
+	public function Preposition()
56
+	{
57
+		return $this->apply(new Preposition($this->analyzer->getText()));
58
+	}
59 59
 
60
-    /**
61
-     * Применяет фильтр Pronoun.
62
-     *
63
-     * @return \AnalyzerText\Filter\Factory
64
-     */
65
-    public function Pronoun()
66
-    {
67
-        return $this->apply(new Pronoun($this->analyzer->getText()));
68
-    }
60
+	/**
61
+	 * Применяет фильтр Pronoun.
62
+	 *
63
+	 * @return \AnalyzerText\Filter\Factory
64
+	 */
65
+	public function Pronoun()
66
+	{
67
+		return $this->apply(new Pronoun($this->analyzer->getText()));
68
+	}
69 69
 
70
-    /**
71
-     * Применяет фильтр Union.
72
-     *
73
-     * @return \AnalyzerText\Filter\Factory
74
-     */
75
-    public function Union()
76
-    {
77
-        return $this->apply(new Union($this->analyzer->getText()));
78
-    }
70
+	/**
71
+	 * Применяет фильтр Union.
72
+	 *
73
+	 * @return \AnalyzerText\Filter\Factory
74
+	 */
75
+	public function Union()
76
+	{
77
+		return $this->apply(new Union($this->analyzer->getText()));
78
+	}
79 79
 
80
-    /**
81
-     * Применяет фильтр Adverb.
82
-     *
83
-     * @return \AnalyzerText\Filter\Factory
84
-     */
85
-    public function Adverb()
86
-    {
87
-        return $this->apply(new Adverb($this->analyzer->getText()));
88
-    }
80
+	/**
81
+	 * Применяет фильтр Adverb.
82
+	 *
83
+	 * @return \AnalyzerText\Filter\Factory
84
+	 */
85
+	public function Adverb()
86
+	{
87
+		return $this->apply(new Adverb($this->analyzer->getText()));
88
+	}
89 89
 
90
-    /**
91
-     * Применяет фильтр
92
-     *
93
-     * @param \AnalyzerText\Filter\Filter $filter Фильтр
94
-     *
95
-     * @return \AnalyzerText\Filter\Factory
96
-     */
97
-    private function apply(Filter $filter)
98
-    {
99
-        if ($filter->getText()->count()) {
100
-            $words = array();
101
-            foreach ($filter as $word) {
102
-                $words[] = $word->getWord();
103
-            }
104
-            $text_class = get_class($filter->getText());
105
-            $this->analyzer->setText(new $text_class(implode(' ', $words)));
106
-        }
90
+	/**
91
+	 * Применяет фильтр
92
+	 *
93
+	 * @param \AnalyzerText\Filter\Filter $filter Фильтр
94
+	 *
95
+	 * @return \AnalyzerText\Filter\Factory
96
+	 */
97
+	private function apply(Filter $filter)
98
+	{
99
+		if ($filter->getText()->count()) {
100
+			$words = array();
101
+			foreach ($filter as $word) {
102
+				$words[] = $word->getWord();
103
+			}
104
+			$text_class = get_class($filter->getText());
105
+			$this->analyzer->setText(new $text_class(implode(' ', $words)));
106
+		}
107 107
 
108
-        return $this;
109
-    }
108
+		return $this;
109
+	}
110 110
 }
Please login to merge, or discard this patch.
AnalyzerText/Filter/Filter.php 2 patches
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -17,87 +17,87 @@
 block discarded – undo
17 17
  */
18 18
 abstract class Filter extends \FilterIterator
19 19
 {
20
-    /**
21
-     * Конструктор
22
-     *
23
-     * @param \AnalyzerText\Text $iterator Текст
24
-     */
25
-    public function __construct(Text $iterator)
26
-    {
27
-        parent::__construct($iterator);
28
-    }
20
+	/**
21
+	 * Конструктор
22
+	 *
23
+	 * @param \AnalyzerText\Text $iterator Текст
24
+	 */
25
+	public function __construct(Text $iterator)
26
+	{
27
+		parent::__construct($iterator);
28
+	}
29 29
 
30
-    /**
31
-     * Возвращает текущее слово.
32
-     *
33
-     * @return \AnalyzerText\Text\Word
34
-     */
35
-    public function current()
36
-    {
37
-        return $this->getInnerIterator()->current();
38
-    }
30
+	/**
31
+	 * Возвращает текущее слово.
32
+	 *
33
+	 * @return \AnalyzerText\Text\Word
34
+	 */
35
+	public function current()
36
+	{
37
+		return $this->getInnerIterator()->current();
38
+	}
39 39
 
40
-    /**
41
-     * Возвращает текст
42
-     *
43
-     * @return \AnalyzerText\Text
44
-     */
45
-    public function getText()
46
-    {
47
-        return $this->getInnerIterator();
48
-    }
40
+	/**
41
+	 * Возвращает текст
42
+	 *
43
+	 * @return \AnalyzerText\Text
44
+	 */
45
+	public function getText()
46
+	{
47
+		return $this->getInnerIterator();
48
+	}
49 49
 
50
-    /**
51
-     * Возвращает текст
52
-     *
53
-     * @return \AnalyzerText\Text
54
-     */
55
-    public function getInnerIterator()
56
-    {
57
-        return parent::getInnerIterator();
58
-    }
50
+	/**
51
+	 * Возвращает текст
52
+	 *
53
+	 * @return \AnalyzerText\Text
54
+	 */
55
+	public function getInnerIterator()
56
+	{
57
+		return parent::getInnerIterator();
58
+	}
59 59
 
60
-    /**
61
-     * Заменяет слово в тексте.
62
-     *
63
-     * @param \AnalyzerText\Text\Word $word Слово
64
-     */
65
-    protected function replace(Word $word)
66
-    {
67
-        $this->getInnerIterator()->replace($word);
68
-    }
60
+	/**
61
+	 * Заменяет слово в тексте.
62
+	 *
63
+	 * @param \AnalyzerText\Text\Word $word Слово
64
+	 */
65
+	protected function replace(Word $word)
66
+	{
67
+		$this->getInnerIterator()->replace($word);
68
+	}
69 69
 
70
-    /**
71
-     * Возвращает предыдущее слово.
72
-     *
73
-     * @param int|null $shift Смещение
74
-     *
75
-     * @return \AnalyzerText\Text\Word|null
76
-     */
77
-    protected function getPreviousWord($shift = 1)
78
-    {
79
-        return $this->getNextWord($shift * -1);
80
-    }
70
+	/**
71
+	 * Возвращает предыдущее слово.
72
+	 *
73
+	 * @param int|null $shift Смещение
74
+	 *
75
+	 * @return \AnalyzerText\Text\Word|null
76
+	 */
77
+	protected function getPreviousWord($shift = 1)
78
+	{
79
+		return $this->getNextWord($shift * -1);
80
+	}
81 81
 
82
-    /**
83
-     * Возвращает следующее слово.
84
-     *
85
-     * @param int|null $shift Смещение
86
-     *
87
-     * @return \AnalyzerText\Text\Word|null
88
-     */
89
-    protected function getNextWord($shift = 1)
90
-    {
91
-        $position = $this->getText()->key();
82
+	/**
83
+	 * Возвращает следующее слово.
84
+	 *
85
+	 * @param int|null $shift Смещение
86
+	 *
87
+	 * @return \AnalyzerText\Text\Word|null
88
+	 */
89
+	protected function getNextWord($shift = 1)
90
+	{
91
+		$position = $this->getText()->key();
92 92
 
93
-        try {
94
-            $this->getText()->seek($position + $shift);
95
-        } catch (\OutOfBoundsException $e) {
96
-            return null;
97
-        }
98
-        $word = $this->getText()->current();
99
-        $this->getText()->seek($position);
93
+		try {
94
+			$this->getText()->seek($position + $shift);
95
+		} catch (\OutOfBoundsException $e) {
96
+			return null;
97
+		}
98
+		$word = $this->getText()->current();
99
+		$this->getText()->seek($position);
100 100
 
101
-        return $word;
102
-    }
101
+		return $word;
102
+	}
103 103
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
      */
77 77
     protected function getPreviousWord($shift = 1)
78 78
     {
79
-        return $this->getNextWord($shift * -1);
79
+        return $this->getNextWord($shift*-1);
80 80
     }
81 81
 
82 82
     /**
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
         $position = $this->getText()->key();
92 92
 
93 93
         try {
94
-            $this->getText()->seek($position + $shift);
94
+            $this->getText()->seek($position+$shift);
95 95
         } catch (\OutOfBoundsException $e) {
96 96
             return null;
97 97
         }
Please login to merge, or discard this patch.
AnalyzerText/Filter/WordList/WordList.php 2 patches
Indentation   +156 added lines, -156 removed lines patch added patch discarded remove patch
@@ -20,160 +20,160 @@
 block discarded – undo
20 20
  */
21 21
 abstract class WordList extends Filter
22 22
 {
23
-    /**
24
-     * Простые слова.
25
-     *
26
-     * @var array
27
-     */
28
-    private $simple = array();
29
-
30
-    /**
31
-     * Составные слова.
32
-     *
33
-     * Составные слова о части которого нам известно.
34
-     * Например слово пишется через тирэ
35
-     *
36
-     * @var array
37
-     */
38
-    private $composite = array();
39
-
40
-    /**
41
-     * Последовательности из набора слов.
42
-     *
43
-     * @var array
44
-     */
45
-    private $sequence = array();
46
-
47
-    /**
48
-     * Конструктор
49
-     *
50
-     * @param \AnalyzerText\Text $iterator Текст
51
-     */
52
-    public function __construct(Text $iterator)
53
-    {
54
-        parent::__construct($iterator);
55
-        $this->repackWordList();
56
-    }
57
-
58
-    /**
59
-     * Проверяет, является ли текущее слово допустимым
60
-     *
61
-     * @return bool
62
-     */
63
-    public function accept()
64
-    {
65
-        $word = $this->current();
66
-
67
-        return $this->isSequence($word) || $this->isSimple($word) || $this->isComposite($word);
68
-    }
69
-
70
-    /**
71
-     * Это последовательность.
72
-     *
73
-     * @param \AnalyzerText\Text\Word $word Слово
74
-     *
75
-     * @return bool
76
-     */
77
-    public function isSequence(Word $word)
78
-    {
79
-        $plain = $word->getPlain();
80
-        foreach ($this->sequence as $sequence) {
81
-            if ($sequence[0] == $plain) {
82
-                for ($i = 1; $i < count($sequence); ++$i) {
83
-                    if (!($word = $this->getNextWord($i)) || $word->getPlain() != $sequence[$i]) {
84
-                        return false;
85
-                    }
86
-                }
87
-                // удаляем слова из последовательности
88
-                $key = $this->getText()->key();
89
-                for ($i = 1; $i < count($sequence); ++$i) {
90
-                    $this->getText()->seek($key + $i);
91
-                    $this->getText()->remove();
92
-                }
93
-                $this->getText()->seek($key);
94
-
95
-                return true;
96
-            }
97
-        }
98
-
99
-        return false;
100
-    }
101
-
102
-    /**
103
-     * Это простое слово.
104
-     *
105
-     * @param \AnalyzerText\Text\Word $word Слово
106
-     *
107
-     * @return bool
108
-     */
109
-    public function isSimple(Word $word)
110
-    {
111
-        return in_array($word->getPlain(), $this->simple);
112
-    }
113
-
114
-    /**
115
-     * Это составное слово.
116
-     *
117
-     * @param \AnalyzerText\Text\Word $word Слово
118
-     *
119
-     * @return bool
120
-     */
121
-    public function isComposite(Word $word)
122
-    {
123
-        foreach ($this->composite as $reg) {
124
-            if (preg_match($reg, $word->getWord())) {
125
-                return true;
126
-            }
127
-        }
128
-
129
-        return false;
130
-    }
131
-
132
-    /**
133
-     * Возвращает список слов.
134
-     *
135
-     * Возвращает список слов которые необходимо удалить или оставить
136
-     * Если слово составное и пишестся через тире, но одна из частей может менятся например:
137
-     * <code>
138
-     *   подай-ка, налей-ка, молоко-то сбежало, наценка-с
139
-     * </code>
140
-     * то нужно писать шаблон вида:
141
-     * <code>
142
-     *   [ '*-ка', '*-то', '*-с' ]
143
-     * </code>
144
-     * Для удаления последовательности слов ячейка слова должна представляться в виде набора слов разделенных пробелом
145
-     * <code>
146
-     *   [ 'вовсе не', 'несмотря на то что' ]
147
-     * </code>
148
-     * Так же есть возможность указывать регулярные выражения для отлавливания сложных конструкций
149
-     * <code>
150
-     *   // ААааа Аааа-а-а
151
-     *   [ '/^а+(\-а+)*$/ui' ]
152
-     * </code>
153
-     * В регулярное выражение передается оригинальное слово, а не урощенная форма
154
-     *
155
-     * @return array
156
-     */
157
-    abstract public function getWords();
158
-
159
-    /**
160
-     * Разбор набора шаблонов слов и составление условий поиска соответствий.
161
-     */
162
-    private function repackWordList()
163
-    {
164
-        $words = $this->getWords();
165
-        // разбор на категории
166
-        foreach ($words as $word) {
167
-            if ($word[0] == '/') { // регулярное выражение
168
-                $this->composite[] = $word;
169
-            } elseif (strpos($word, ' ') !== false) { // последовательность
170
-                $this->sequence[] = explode(' ', $word);
171
-            } elseif (strpos($word, '*') !== false) { // псевдо регулярка
172
-                // из записи *-то делаем регулярное выражение вида: /^.+?\-то$/ui
173
-                $this->composite[] = '/^'.str_replace('\*', '.+?', preg_quote($word, '/')).'$/ui';
174
-            } else { // простое слово
175
-                $this->simple[] = $word;
176
-            }
177
-        }
178
-    }
23
+	/**
24
+	 * Простые слова.
25
+	 *
26
+	 * @var array
27
+	 */
28
+	private $simple = array();
29
+
30
+	/**
31
+	 * Составные слова.
32
+	 *
33
+	 * Составные слова о части которого нам известно.
34
+	 * Например слово пишется через тирэ
35
+	 *
36
+	 * @var array
37
+	 */
38
+	private $composite = array();
39
+
40
+	/**
41
+	 * Последовательности из набора слов.
42
+	 *
43
+	 * @var array
44
+	 */
45
+	private $sequence = array();
46
+
47
+	/**
48
+	 * Конструктор
49
+	 *
50
+	 * @param \AnalyzerText\Text $iterator Текст
51
+	 */
52
+	public function __construct(Text $iterator)
53
+	{
54
+		parent::__construct($iterator);
55
+		$this->repackWordList();
56
+	}
57
+
58
+	/**
59
+	 * Проверяет, является ли текущее слово допустимым
60
+	 *
61
+	 * @return bool
62
+	 */
63
+	public function accept()
64
+	{
65
+		$word = $this->current();
66
+
67
+		return $this->isSequence($word) || $this->isSimple($word) || $this->isComposite($word);
68
+	}
69
+
70
+	/**
71
+	 * Это последовательность.
72
+	 *
73
+	 * @param \AnalyzerText\Text\Word $word Слово
74
+	 *
75
+	 * @return bool
76
+	 */
77
+	public function isSequence(Word $word)
78
+	{
79
+		$plain = $word->getPlain();
80
+		foreach ($this->sequence as $sequence) {
81
+			if ($sequence[0] == $plain) {
82
+				for ($i = 1; $i < count($sequence); ++$i) {
83
+					if (!($word = $this->getNextWord($i)) || $word->getPlain() != $sequence[$i]) {
84
+						return false;
85
+					}
86
+				}
87
+				// удаляем слова из последовательности
88
+				$key = $this->getText()->key();
89
+				for ($i = 1; $i < count($sequence); ++$i) {
90
+					$this->getText()->seek($key + $i);
91
+					$this->getText()->remove();
92
+				}
93
+				$this->getText()->seek($key);
94
+
95
+				return true;
96
+			}
97
+		}
98
+
99
+		return false;
100
+	}
101
+
102
+	/**
103
+	 * Это простое слово.
104
+	 *
105
+	 * @param \AnalyzerText\Text\Word $word Слово
106
+	 *
107
+	 * @return bool
108
+	 */
109
+	public function isSimple(Word $word)
110
+	{
111
+		return in_array($word->getPlain(), $this->simple);
112
+	}
113
+
114
+	/**
115
+	 * Это составное слово.
116
+	 *
117
+	 * @param \AnalyzerText\Text\Word $word Слово
118
+	 *
119
+	 * @return bool
120
+	 */
121
+	public function isComposite(Word $word)
122
+	{
123
+		foreach ($this->composite as $reg) {
124
+			if (preg_match($reg, $word->getWord())) {
125
+				return true;
126
+			}
127
+		}
128
+
129
+		return false;
130
+	}
131
+
132
+	/**
133
+	 * Возвращает список слов.
134
+	 *
135
+	 * Возвращает список слов которые необходимо удалить или оставить
136
+	 * Если слово составное и пишестся через тире, но одна из частей может менятся например:
137
+	 * <code>
138
+	 *   подай-ка, налей-ка, молоко-то сбежало, наценка-с
139
+	 * </code>
140
+	 * то нужно писать шаблон вида:
141
+	 * <code>
142
+	 *   [ '*-ка', '*-то', '*-с' ]
143
+	 * </code>
144
+	 * Для удаления последовательности слов ячейка слова должна представляться в виде набора слов разделенных пробелом
145
+	 * <code>
146
+	 *   [ 'вовсе не', 'несмотря на то что' ]
147
+	 * </code>
148
+	 * Так же есть возможность указывать регулярные выражения для отлавливания сложных конструкций
149
+	 * <code>
150
+	 *   // ААааа Аааа-а-а
151
+	 *   [ '/^а+(\-а+)*$/ui' ]
152
+	 * </code>
153
+	 * В регулярное выражение передается оригинальное слово, а не урощенная форма
154
+	 *
155
+	 * @return array
156
+	 */
157
+	abstract public function getWords();
158
+
159
+	/**
160
+	 * Разбор набора шаблонов слов и составление условий поиска соответствий.
161
+	 */
162
+	private function repackWordList()
163
+	{
164
+		$words = $this->getWords();
165
+		// разбор на категории
166
+		foreach ($words as $word) {
167
+			if ($word[0] == '/') { // регулярное выражение
168
+				$this->composite[] = $word;
169
+			} elseif (strpos($word, ' ') !== false) { // последовательность
170
+				$this->sequence[] = explode(' ', $word);
171
+			} elseif (strpos($word, '*') !== false) { // псевдо регулярка
172
+				// из записи *-то делаем регулярное выражение вида: /^.+?\-то$/ui
173
+				$this->composite[] = '/^'.str_replace('\*', '.+?', preg_quote($word, '/')).'$/ui';
174
+			} else { // простое слово
175
+				$this->simple[] = $word;
176
+			}
177
+		}
178
+	}
179 179
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -87,7 +87,7 @@
 block discarded – undo
87 87
                 // удаляем слова из последовательности
88 88
                 $key = $this->getText()->key();
89 89
                 for ($i = 1; $i < count($sequence); ++$i) {
90
-                    $this->getText()->seek($key + $i);
90
+                    $this->getText()->seek($key+$i);
91 91
                     $this->getText()->remove();
92 92
                 }
93 93
                 $this->getText()->seek($key);
Please login to merge, or discard this patch.
AnalyzerText/Text.php 1 patch
Indentation   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -18,77 +18,77 @@
 block discarded – undo
18 18
  */
19 19
 class Text extends \ArrayIterator
20 20
 {
21
-    /**
22
-     * Спиок всех слов в тексте в простой форме.
23
-     *
24
-     * @var array
25
-     */
26
-    protected $plains = array();
21
+	/**
22
+	 * Спиок всех слов в тексте в простой форме.
23
+	 *
24
+	 * @var array
25
+	 */
26
+	protected $plains = array();
27 27
 
28
-    /**
29
-     * Конструктор
30
-     *
31
-     * @param string $text Текст
32
-     */
33
-    public function __construct($text)
34
-    {
35
-        $words = array();
36
-        // слово не может начинаться с тире и не может содержать только его
37
-        if (preg_match_all('/[[:alnum:]]+(?:[-\'][[:alnum:]]+)*/u', trim(strip_tags($text)), $match)) {
38
-            $words = $match[0];
39
-            // получение списка слов в нижнем регистре
40
-            $this->plains = explode(' ', mb_strtolower(implode(' ', $words), 'utf8'));
41
-        }
42
-        parent::__construct($words);
43
-    }
28
+	/**
29
+	 * Конструктор
30
+	 *
31
+	 * @param string $text Текст
32
+	 */
33
+	public function __construct($text)
34
+	{
35
+		$words = array();
36
+		// слово не может начинаться с тире и не может содержать только его
37
+		if (preg_match_all('/[[:alnum:]]+(?:[-\'][[:alnum:]]+)*/u', trim(strip_tags($text)), $match)) {
38
+			$words = $match[0];
39
+			// получение списка слов в нижнем регистре
40
+			$this->plains = explode(' ', mb_strtolower(implode(' ', $words), 'utf8'));
41
+		}
42
+		parent::__construct($words);
43
+	}
44 44
 
45
-    /**
46
-     * Возвращает список слов.
47
-     *
48
-     * @return array
49
-     */
50
-    public function getWords()
51
-    {
52
-        return $this->getArrayCopy();
53
-    }
45
+	/**
46
+	 * Возвращает список слов.
47
+	 *
48
+	 * @return array
49
+	 */
50
+	public function getWords()
51
+	{
52
+		return $this->getArrayCopy();
53
+	}
54 54
 
55
-    /**
56
-     * Возвращает текущий элемент
57
-     *
58
-     * @return \AnalyzerText\Text\Word
59
-     */
60
-    public function current()
61
-    {
62
-        return new Word(parent::current(), $this->plains[$this->key()]);
63
-    }
55
+	/**
56
+	 * Возвращает текущий элемент
57
+	 *
58
+	 * @return \AnalyzerText\Text\Word
59
+	 */
60
+	public function current()
61
+	{
62
+		return new Word(parent::current(), $this->plains[$this->key()]);
63
+	}
64 64
 
65
-    /**
66
-     * Удаляет слово из текста.
67
-     */
68
-    public function remove()
69
-    {
70
-        $this->offsetUnset($this->key());
71
-        unset($this->plains[$this->key()]);
72
-    }
65
+	/**
66
+	 * Удаляет слово из текста.
67
+	 */
68
+	public function remove()
69
+	{
70
+		$this->offsetUnset($this->key());
71
+		unset($this->plains[$this->key()]);
72
+	}
73 73
 
74
-    /**
75
-     * Заменяет слово в тексте.
76
-     *
77
-     * @param \AnalyzerText\Text\Word $word Слово
78
-     */
79
-    public function replace(Word $word)
80
-    {
81
-        $this->offsetSet($this->key(), $word->getWord());
82
-        $this->plains[$this->key()] = $word->getPlain();
83
-    }
74
+	/**
75
+	 * Заменяет слово в тексте.
76
+	 *
77
+	 * @param \AnalyzerText\Text\Word $word Слово
78
+	 */
79
+	public function replace(Word $word)
80
+	{
81
+		$this->offsetSet($this->key(), $word->getWord());
82
+		$this->plains[$this->key()] = $word->getPlain();
83
+	}
84 84
 
85
-    /**
86
-     * Возвращает текст
87
-     *
88
-     * @return string
89
-     */
90
-    public function __toString()
91
-    {
92
-        return implode(' ', $this->getWords());
93
-    }
85
+	/**
86
+	 * Возвращает текст
87
+	 *
88
+	 * @return string
89
+	 */
90
+	public function __toString()
91
+	{
92
+		return implode(' ', $this->getWords());
93
+	}
94 94
 }
Please login to merge, or discard this patch.
AnalyzerText/Text/Word.php 1 patch
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -14,59 +14,59 @@
 block discarded – undo
14 14
  */
15 15
 class Word
16 16
 {
17
-    /**
18
-     * Слово в тексте.
19
-     *
20
-     * @var string
21
-     */
22
-    protected $word = '';
17
+	/**
18
+	 * Слово в тексте.
19
+	 *
20
+	 * @var string
21
+	 */
22
+	protected $word = '';
23 23
 
24
-    /**
25
-     * Простая форма слова в тексте.
26
-     *
27
-     * @var string
28
-     */
29
-    protected $plain = '';
24
+	/**
25
+	 * Простая форма слова в тексте.
26
+	 *
27
+	 * @var string
28
+	 */
29
+	protected $plain = '';
30 30
 
31
-    /**
32
-     * Конструктор
33
-     *
34
-     * @param string $word       Слово в тексте
35
-     * @param string $lower_case Простая форма слова в тексте
36
-     */
37
-    public function __construct($word, $plain)
38
-    {
39
-        $this->word = $word;
40
-        $this->plain = $plain;
41
-    }
31
+	/**
32
+	 * Конструктор
33
+	 *
34
+	 * @param string $word       Слово в тексте
35
+	 * @param string $lower_case Простая форма слова в тексте
36
+	 */
37
+	public function __construct($word, $plain)
38
+	{
39
+		$this->word = $word;
40
+		$this->plain = $plain;
41
+	}
42 42
 
43
-    /**
44
-     * Возвращает слово из текста.
45
-     *
46
-     * @return string
47
-     */
48
-    public function getWord()
49
-    {
50
-        return $this->word;
51
-    }
43
+	/**
44
+	 * Возвращает слово из текста.
45
+	 *
46
+	 * @return string
47
+	 */
48
+	public function getWord()
49
+	{
50
+		return $this->word;
51
+	}
52 52
 
53
-    /**
54
-     * Возвращает простую форму слова из текста.
55
-     *
56
-     * @return string
57
-     */
58
-    public function getPlain()
59
-    {
60
-        return $this->plain;
61
-    }
53
+	/**
54
+	 * Возвращает простую форму слова из текста.
55
+	 *
56
+	 * @return string
57
+	 */
58
+	public function getPlain()
59
+	{
60
+		return $this->plain;
61
+	}
62 62
 
63
-    /**
64
-     * Возвращает слово.
65
-     *
66
-     * @return string
67
-     */
68
-    public function __toString()
69
-    {
70
-        return $this->getWord();
71
-    }
63
+	/**
64
+	 * Возвращает слово.
65
+	 *
66
+	 * @return string
67
+	 */
68
+	public function __toString()
69
+	{
70
+		return $this->getWord();
71
+	}
72 72
 }
Please login to merge, or discard this patch.
AnalyzerText/Filter/WordList/Interjection.php 1 patch
Indentation   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -14,70 +14,70 @@
 block discarded – undo
14 14
  */
15 15
 class Interjection extends WordList
16 16
 {
17
-    /**
18
-     * Возвращает список слов.
19
-     *
20
-     * @return array
21
-     */
22
-    public function getWords()
23
-    {
24
-        return array(
25
-            // русские междометья
26
-            'ох',
27
-            'ого',
28
-            'ого',
29
-            'эй',
30
-            'эх',
31
-            'цып',
32
-            'брысь',
33
-            'aх',
34
-            'ух',
35
-            'брр',
36
-            'тпру',
37
-            'гм',
38
-            'дзинь',
39
-            'тс',
40
-            'цс',
41
-            'тьфу',
42
-            'ой',
43
-            'фу',
44
-            'фи',
45
-            'ага',
46
-            'апчи',
47
-            'браво',
48
-            'ж',
49
-            'буль',
50
-            'ку',
51
-            'хлоп',
52
-            'бац',
53
-            'бух',
54
-            'шлёп',
55
-            'бум',
56
-            'бах',
57
-            'пли',
58
-            'гав',
59
-            'мяу',
60
-            'тра',
61
-            'ишь',
62
-            'вишь',
63
-            'то-то',
64
-            'эка',
65
-            'ш',
66
-            'вот те раз',
67
-            'ну',
68
-            'типа',
69
-            'хватит',
70
-            'лады',
71
-            'ок',
72
-            'хорош',
73
-            'короче',
74
-            '/^а+(\-а+)*$/ui', // ААааа Аааа-а-а
17
+	/**
18
+	 * Возвращает список слов.
19
+	 *
20
+	 * @return array
21
+	 */
22
+	public function getWords()
23
+	{
24
+		return array(
25
+			// русские междометья
26
+			'ох',
27
+			'ого',
28
+			'ого',
29
+			'эй',
30
+			'эх',
31
+			'цып',
32
+			'брысь',
33
+			'aх',
34
+			'ух',
35
+			'брр',
36
+			'тпру',
37
+			'гм',
38
+			'дзинь',
39
+			'тс',
40
+			'цс',
41
+			'тьфу',
42
+			'ой',
43
+			'фу',
44
+			'фи',
45
+			'ага',
46
+			'апчи',
47
+			'браво',
48
+			'ж',
49
+			'буль',
50
+			'ку',
51
+			'хлоп',
52
+			'бац',
53
+			'бух',
54
+			'шлёп',
55
+			'бум',
56
+			'бах',
57
+			'пли',
58
+			'гав',
59
+			'мяу',
60
+			'тра',
61
+			'ишь',
62
+			'вишь',
63
+			'то-то',
64
+			'эка',
65
+			'ш',
66
+			'вот те раз',
67
+			'ну',
68
+			'типа',
69
+			'хватит',
70
+			'лады',
71
+			'ок',
72
+			'хорош',
73
+			'короче',
74
+			'/^а+(\-а+)*$/ui', // ААааа Аааа-а-а
75 75
 
76
-            // английские междометья
77
-            'ok',
78
-            'oh',
79
-            'ah',
80
-            'bravo',
81
-        );
82
-    }
76
+			// английские междометья
77
+			'ok',
78
+			'oh',
79
+			'ah',
80
+			'bravo',
81
+		);
82
+	}
83 83
 }
Please login to merge, or discard this patch.