/**
  * Q&Aを解析します。
  * @param Dictionary $dictioanry
  * @param string $question
  * @param string $answer
  */
 protected function parseQuizLines(Dictionary $dictioanry, string $question, string $answer)
 {
     $line = "{$question}\n{$answer}";
     $specifics = new URLSearchParams();
     $questionFields = explode(',', $question, 5);
     $answerFields = explode(',', $answer);
     if (!$this->isNumeric($questionFields[1])) {
         throw new SyntaxException(sprintf(_('出題の種類「%s」は数値として認識できません。'), $questionFields[1]));
     } elseif (!$this->isNumeric($answerFields[1])) {
         throw new SyntaxException(sprintf(_('解答の種類「%s」は数値として認識できません。'), $answerFields[1]));
     }
     /** @var int 出題の種類。 */
     $questionType = $this->convertToInt($questionFields[1]);
     switch ($questionType) {
         case 1:
             // 音声ファイルを再生
         // 音声ファイルを再生
         case 2:
             // 画像ファイルを表示
             if (empty($questionFields[3])) {
                 throw new SyntaxException(_('ファイルが指定されていません。'));
             }
             // ファイル名
             $fieldsAsMultiDimensionalArray[$questionType === 1 ? 'audio' : 'image'][] = $questionFields[3];
             // 問題オプション
             if (isset($questionFields[4])) {
                 foreach (explode(',', $questionFields[4]) as $option) {
                     $option = explode('=', $option, 2);
                     $name = $option[0];
                     $value = $option[1] ?? '';
                     if (!$this->isNumeric($value)) {
                         throw new SyntaxException(sprintf(_('問題オプション %1$s の値「%2$s」は数値として認識できません。'), $name, $value));
                     }
                     $int = $this->convertToInt($value);
                     switch ($name) {
                         case 'start':
                         case 'media_start':
                             $specifics->set('start', $int / self::SECONDS_TO_MILISECONDS);
                             break;
                         case 'repeat':
                             $specifics->set('repeat', $int);
                             break;
                         case 'length':
                             $specifics->set('length', $int / self::SECONDS_TO_MILISECONDS);
                             break;
                         case 'speed':
                             $specifics->set('speed', $int / self::DECIMAL_TO_PERCENT);
                             break;
                         case 'zoom_start':
                             $specifics->set('magnification', $int);
                             break;
                         case 'zoom_end':
                             $specifics->set('last-magnification', $int);
                             break;
                         case 'mozaic':
                             if ($int === 1) {
                                 $specifics->set('pixelization', '');
                             } else {
                                 $specifics->delete('pixelization');
                             }
                             break;
                         case 'score':
                             $specifics->set('score', $int);
                             break;
                         case 'finalscore':
                             $specifics->set('last-score', $int);
                             break;
                     }
                 }
             }
             break;
         case 3:
             // Wikipediaクイズ
         // Wikipediaクイズ
         case 4:
             // アンサイクロペディアクイズ
             $this->logInconvertibleError("{$question}\n{$answer}");
             return;
     }
     // 問題文
     if (isset($questionFields[2])) {
         $fieldsAsMultiDimensionalArray['question'][] = $this->parseQuestionSentence($questionFields[2]);
     }
     /** @var int 解答の種類。 */
     $answerType = $this->convertToInt($answerFields[1]);
     if (in_array($answerType, [1, 2, 3])) {
         $fieldsAsMultiDimensionalArray['type'][] = 'selection';
         if ($answerType === 3) {
             $specifics->set('require-all-right', '');
         }
     } else {
         $answerType = 0;
     }
     $mode = '|';
     $answerValidator = new \esperecyan\dictionary_php\validator\AnswerValidator();
     foreach (array_slice($answerFields, 2) as $i => $field) {
         if (isset($field[0]) && $field[0] === '\\' && isset($field[1]) && $field[1] !== '\\') {
             // 解答オプション
             if ($field === '\\norandom') {
                 // 選択肢をシャッフルしない
                 if (in_array($answerType, [1, 3])) {
                     $specifics->set('no-random', '');
                 }
             } elseif ($field === '\\seikai') {
                 // 直前の選択肢を正解扱いに
                 if (in_array($answerType, [1, 3])) {
                     if (empty($fieldsAsMultiDimensionalArray['option'])) {
                         throw new SyntaxException(_('\\seikai の前には選択肢が必要です。'));
                     }
                     $fieldsAsMultiDimensionalArray['answer'][] = end($fieldsAsMultiDimensionalArray['option']);
                 }
             } elseif (preg_match('/^\\\\explain=(.+)$/u', $field, $matches) === 1) {
                 // 解説
                 $fieldsAsMultiDimensionalArray['description'][] = $this->parseQuestionSentence($matches[1]);
             } elseif ($answerType === 0 && preg_match('/^\\\\bonus=(.*)$/u', $field, $matches) === 1) {
                 // ボーナスポイント
                 if (!$this->isNumeric($matches[1])) {
                     throw new SyntaxException(sprintf(_('解答オプション \\bonus の値「%s」は数値として認識できません。'), $matches[1]));
                 }
                 if (empty($answerPattenAndBonuses['|'])) {
                     throw new SyntaxException(sprintf(_('解答オプション「%s」の前には解答本体が必要です。'), $field));
                 }
                 $bonus = $this->convertToInt($matches[1]);
                 if ($bonus !== 0) {
                     $answerPattenAndBonuses['|'][count($answerPattenAndBonuses['|']) - 1]['bonus'] = $bonus;
                 }
             }
             continue;
         }
         switch ($answerType) {
             case 0:
                 // 記述形式
                 if ($field === '[[' || $field === '||') {
                     // 正規表現
                     if (empty($answerPattenAndBonuses['|'])) {
                         throw new SyntaxException(sprintf(_('「%s」の前には解答本体が必要です。'), $field));
                     }
                     $end = count($answerPattenAndBonuses['|']) - 1;
                     $answerPattenAndBonuses['|'][$end]['regexp'] = ($field === '||' ? '.*' : '') . preg_quote($answerPattenAndBonuses['|'][$end]['body'], '/') . '.*';
                 } elseif (in_array($field, ['[', '|', ']'])) {
                     // モード変更
                     $mode = $field;
                 } elseif ($mode === '|') {
                     $answerPattenAndBonuses['|'][]['body'] = $field;
                 } else {
                     $answerPattenAndBonuses[$mode][] = $field;
                 }
                 break;
             case 1:
                 // 選択形式
             // 選択形式
             case 3:
                 // 全選択形式
                 $fieldsAsMultiDimensionalArray['option'][] = $answerValidator->isRegExp($field) ? trim($field, '/') : $field;
                 break;
             case 2:
                 // 並べ替え形式
                 if ($i % 2 === 0) {
                     $numbersAndOptions[] = [$answerValidator->isRegExp($field) ? trim($field, '/') : $field];
                 } else {
                     $number = $this->isNumeric($field) ? $this->convertToInt($field) : 0;
                     if ($number > 0) {
                         array_unshift($numbersAndOptions[count($numbersAndOptions) - 1], $number);
                     } else {
                         // 順番が0以下であれば選択肢自体を削除
                         array_pop($numbersAndOptions);
                     }
                 }
                 break;
         }
     }
     switch ($answerType) {
         case 0:
             // 記述形式
             $noRegExpAnswerExisted = false;
             foreach ($answerPattenAndBonuses['|'] as $infix) {
                 // 接頭辞の付加
                 if (isset($answerPattenAndBonuses['['])) {
                     foreach ($answerPattenAndBonuses['['] as $prefix) {
                         $tmpInfix = $infix;
                         $tmpInfix['body'] = $prefix . $tmpInfix['body'];
                         if (isset($tmpInfix['regexp'])) {
                             $tmpInfix['regexp'] = preg_quote($prefix, '/') . $tmpInfix['regexp'];
                         }
                         $answersAndBonusesWithPrefix[] = $tmpInfix;
                     }
                 } else {
                     $answersAndBonusesWithPrefix[] = $infix;
                 }
                 // 接尾辞の付加
                 if (isset($answerPattenAndBonuses[']'])) {
                     foreach ($answerPattenAndBonuses[']'] as $suffix) {
                         foreach ($answersAndBonusesWithPrefix as $answer) {
                             $answer['body'] .= $suffix;
                             if (isset($answer['regexp'])) {
                                 $answer['regexp'] .= preg_quote($prefix, '/');
                             }
                             $answersAndBonusesWithPrefixAndSuffix[] = $answer;
                         }
                     }
                 } else {
                     $answersAndBonusesWithPrefixAndSuffix = $answersAndBonusesWithPrefix;
                 }
                 unset($answersAndBonusesWithPrefix);
                 foreach ($answersAndBonusesWithPrefixAndSuffix as &$answer) {
                     if ($answerValidator->isRegExp($answer['body'])) {
                         $answer['body'] = trim($answer['body'], '/');
                         if ($answer['body'] === '') {
                             unset($answer['body']);
                         }
                     }
                     if (isset($answer['regexp']) || isset($answer['body'])) {
                         $fieldsAsMultiDimensionalArray['answer'][] = isset($answer['regexp']) ? "/{$answer['regexp']}/" : $answer['body'];
                         if (isset($answer['regexp'])) {
                             if (!isset($noRegExpAnswerAndBonus)) {
                                 $noRegExpAnswerAndBonus = ['answer' => $answer['body'], 'bonus' => isset($answer['bonus']) ? (string) $answer['bonus'] : ''];
                             }
                         } else {
                             $noRegExpAnswerExisted = true;
                         }
                         $bonuses[] = isset($answer['bonus']) ? (string) $answer['bonus'] : '';
                     }
                 }
                 unset($answersAndBonusesWithPrefixAndSuffix);
             }
             if (!$noRegExpAnswerExisted) {
                 // answerフィールドがすべて正規表現なら
                 if (isset($noRegExpAnswerAndBonus)) {
                     array_unshift($fieldsAsMultiDimensionalArray['answer'], $noRegExpAnswerAndBonus['answer']);
                     array_unshift($bonuses, $noRegExpAnswerAndBonus['bonus']);
                 } else {
                     $this->logInconvertibleError($line);
                     return;
                 }
             }
             // specificsフィールドのbonusの設定
             if (isset($bonuses)) {
                 foreach (array_reverse($bonuses, true) as $i => $bonus) {
                     if ($bonus) {
                         $lastBonusPosition = $i;
                         break;
                     }
                 }
             }
             if (isset($lastBonusPosition)) {
                 foreach (array_slice($bonuses, 0, $lastBonusPosition + 1) as $bonus) {
                     $specifics->append('bonus', $bonus);
                 }
             }
             $fieldsAsMultiDimensionalArray['text'][] = $fieldsAsMultiDimensionalArray['answer'][0];
             if (count($fieldsAsMultiDimensionalArray['answer']) === 1) {
                 unset($fieldsAsMultiDimensionalArray['answer']);
             }
             break;
         case 1:
             // 選択形式
         // 選択形式
         case 3:
             // 全選択形式
             if (empty($fieldsAsMultiDimensionalArray['answer'])) {
                 throw new SyntaxException(_('\\seikai が設定されていません。'));
             }
             $fieldsAsMultiDimensionalArray['text'][] = count($fieldsAsMultiDimensionalArray['answer']) === 1 ? $fieldsAsMultiDimensionalArray['answer'][0] : '「' . implode('」' . ($answerType === 1 ? 'か' : 'と') . '「', $fieldsAsMultiDimensionalArray['answer']) . '」';
             break;
         case 2:
             // 並べ替え形式
             if (isset($numbersAndOptions)) {
                 if (count(end($numbersAndOptions)) === 1) {
                     // 順番が指定されていない選択肢を削除
                     array_pop($numbersAndOptions);
                 }
                 sort($numbersAndOptions);
                 $fieldsAsMultiDimensionalArray['option'] = array_column($numbersAndOptions, 1);
                 $fieldsAsMultiDimensionalArray['text'][] = implode(' → ', $fieldsAsMultiDimensionalArray['option']);
             }
             break;
     }
     $encoded = (string) $specifics;
     if ($encoded !== '') {
         $fieldsAsMultiDimensionalArray['specifics'][] = $encoded;
     }
     try {
         $dictioanry->addWord($fieldsAsMultiDimensionalArray);
         if ($answerType === 0) {
             // 記述形式
             $words = $dictioanry->getWords();
             $word = $words[count($words) - 1];
             if (isset($word['answer'])) {
                 foreach ($word['answer'] as $answer) {
                     $this->wholeText .= $answerValidator->isRegExp($answer) ? preg_replace('#^/|\\.\\*|/$#u', '', $answer) : $answer;
                 }
             } else {
                 $this->wholeText .= $word['text'][0];
             }
         }
     } catch (SyntaxException $e) {
         $this->logInconvertibleError($line, $e);
     }
 }