| 1234567891011121314151617181920212223242526272829303132333435363738 |
- <?php
- namespace App\Support;
- class GradingMarkBoxCounter
- {
- public function countFillBlanks(?string $text): int
- {
- $text = (string) $text;
- $count = 0;
- $count += preg_match_all('/_{2,}/u', $text, $m);
- $count += preg_match_all('/(\s*)/u', $text, $m);
- $count += preg_match_all('/\(\s*\)/', $text, $m);
- return max(1, $count);
- }
- public function countAnswerSteps(?string $text): int
- {
- $text = (string) $text;
- $stepPattern = '(步骤\s*[0-9一二三四五六七八九十百零两]+\s*[::]?|第\s*[0-9一二三四五六七八九十百零两]+\s*步\s*[::]?)';
- if (!preg_match('/' . $stepPattern . '/u', $text)) {
- return 1;
- }
- $parts = preg_split('/(?=' . $stepPattern . ')/u', $text, -1, PREG_SPLIT_NO_EMPTY) ?: [];
- $count = 0;
- foreach ($parts as $part) {
- $stepText = trim((string) $part);
- if ($stepText !== '' && preg_match('/^' . $stepPattern . '/u', $stepText)) {
- $count++;
- }
- }
- return max(1, $count);
- }
- }
|