@@ -14,68 +14,68 @@ |
||
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 (empty($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 (empty($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 (empty($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 (empty($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 | } |
@@ -70,9 +70,9 @@ |
||
70 | 70 | public function getPercent() |
71 | 71 | { |
72 | 72 | if (empty($this->percent) && ($frequencies = $this->getFrequency())) { |
73 | - $ratio = max($frequencies) / 100; |
|
73 | + $ratio = max($frequencies)/100; |
|
74 | 74 | foreach ($frequencies as $word => $frequency) { |
75 | - $this->percent[$word] = $frequency / $ratio; |
|
75 | + $this->percent[$word] = $frequency/$ratio; |
|
76 | 76 | } |
77 | 77 | } |
78 | 78 |