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