@@ 31-62 (lines=32) @@ | ||
28 | ||
29 | use Org_Heigl\TextStatistics\Text; |
|
30 | ||
31 | class SentenceMaxSyllablesCalculator implements CalculatorInterface |
|
32 | { |
|
33 | protected $syllableCounter; |
|
34 | ||
35 | public function __construct(SyllableCounter $counter) |
|
36 | { |
|
37 | $this->syllableCounter = $counter; |
|
38 | } |
|
39 | ||
40 | /** |
|
41 | * Do the actual calculation of a statistic |
|
42 | * |
|
43 | * @param Text $text |
|
44 | * |
|
45 | * @return mixed |
|
46 | */ |
|
47 | public function calculate(Text $text) |
|
48 | { |
|
49 | $result = preg_split('/[\.\!\?]\s/mu', $text->getPlainText()); |
|
50 | ||
51 | $maxSyllables = 0; |
|
52 | ||
53 | foreach ($result as $sentence) { |
|
54 | $syllables = $this->syllableCounter->calculate(new Text($sentence)); |
|
55 | if ($syllables > $maxSyllables) { |
|
56 | $maxSyllables = $syllables; |
|
57 | } |
|
58 | } |
|
59 | ||
60 | return $maxSyllables; |
|
61 | } |
|
62 | } |
|
63 |
@@ 31-62 (lines=32) @@ | ||
28 | ||
29 | use Org_Heigl\TextStatistics\Text; |
|
30 | ||
31 | class SentenceMaxWordsCalculator implements CalculatorInterface |
|
32 | { |
|
33 | protected $wordCounter; |
|
34 | ||
35 | public function __construct(WordCounter $counter) |
|
36 | { |
|
37 | $this->wordCounter = $counter; |
|
38 | } |
|
39 | ||
40 | /** |
|
41 | * Do the actual calculation of a statistic |
|
42 | * |
|
43 | * @param Text $text |
|
44 | * |
|
45 | * @return mixed |
|
46 | */ |
|
47 | public function calculate(Text $text) |
|
48 | { |
|
49 | $result = preg_split('/[\.\!\?]\s/mu', $text->getPlainText()); |
|
50 | ||
51 | $maxWords = 0; |
|
52 | ||
53 | foreach ($result as $sentence) { |
|
54 | $words = $this->wordCounter->calculate(new Text($sentence)); |
|
55 | if ($words > $maxWords) { |
|
56 | $maxWords = $words; |
|
57 | } |
|
58 | } |
|
59 | ||
60 | return $maxWords; |
|
61 | } |
|
62 | } |
|
63 |