一つのお題を表す配列を直列化します。
@param (string|string[]|float)[][] $word
@return string 末尾に改行 (CRLF) を含みます。直列化できないお題だった場合は空文字列を返します。
762888
protected function serializeWord(array $word): string
    {
        if (!isset($word['type'][0]) || $word['type'][0] !== 'selection') {
            $answers = $this->getOrderedAnswers($word);
            if ($answers) {
                $output = implode(',', array_map((function (string $answer, int $key): string {
                    $lowercase = strtolower($answer);
                    if ($key === 0) {
                        $serializedAnswer[] = $this->convertToFullwidth($lowercase);
                    }
                    if ($key > 0 || $serializedAnswer[0] !== $lowercase) {
                        $serializedAnswer[] = str_replace([',', '/', ';', '['], ['，', '／', '；', '［'], $lowercase);
                    }
                    return implode(',', $serializedAnswer);
                }), $answers, array_keys($answers)));
                
                $comment = '';
                if (isset($word['answer'][0])) {
                    $shiftJISableText = $this->convertToShiftJISable($word['text'][0]);
                    if ($answers[0] !== $shiftJISableText && $this->isShiftJISable($shiftJISableText)) {
                        $comment .= "【${shiftJISableText}】";
                    }
                }
                if (isset($word['description'][0])) {
                    $shiftJISableDescription = $this->convertToShiftJISable($word['description'][0]['lml']);
                    if ($this->isShiftJISable($shiftJISableDescription)) {
                        $comment .= $shiftJISableDescription;
                    }
                }
                if ($comment !== '') {
                    $output .= "// " . str_replace("\n", ' ', $comment);
                }
                $output .= "\r\n";
            }
        }
        
        if (!isset($output)) {
            $output = '';
            $this->logUnserializableError('きゃっちま', $word);
        }
        return $output;
    }
863909
public function hyphenateWord($word, $currptr)
	{
		// Do everything inside this function in utf-8
		// Don't hyphenate web addresses
		if (preg_match('/^(http:|www\.)/', $word)) {
			return -1;
		}

		$ptr = -1;

		if (!$this->dictionaryLoaded) {
			$this->loadDictionary();
		}

		if (!in_array($this->mpdf->SHYlang, $this->mpdf->SHYlanguages)) {
			return -1;
		}

		// If no pattern loaded or not the best one
		if (!$this->patternsLoaded()) {
			$this->loadPatterns();
		}

		if ($this->mpdf->usingCoreFont) {
			$word = mb_convert_encoding($word, 'UTF-8', $this->mpdf->mb_enc);
		}

		$prepre = '';
		$postpost = '';
		$startpunctuation = "\xc2\xab\xc2\xbf\xe2\x80\x98\xe2\x80\x9b\xe2\x80\x9c\xe2\x80\x9f";
		$endpunctuation = "\xe2\x80\x9e\xe2\x80\x9d\xe2\x80\x9a\xe2\x80\x99\xc2\xbb";

		if (preg_match('/^(["\'' . $startpunctuation . '])+(.{' . $this->mpdf->SHYcharmin . ',})$/u', $word, $m)) {
			$prepre = $m[1];
			$word = $m[2];
		}

		if (preg_match('/^(.{' . $this->mpdf->SHYcharmin . ',})([\'\.,;:!?"' . $endpunctuation . ']+)$/u', $word, $m)) {
			$word = $m[1];
			$postpost = $m[2];
		}

		if (mb_strlen($word, 'UTF-8') < $this->mpdf->SHYcharmin) {
			return -1;
		}

		$success = false;
		$preprelen = mb_strlen($prepre);

		if (isset($this->words[mb_strtolower($word)])) {
			foreach ($this->words[mb_strtolower($word)] as $i) {
				if (($i + $preprelen) >= $currptr) {
					break;
				}

				$ptr = $i + $preprelen;
				$success = true;
			}
		}

		if (!$success) {
			$text_word = '_' . $word . '_';
			$word_length = mb_strlen($text_word, 'UTF-8');
			$text_word = mb_strtolower($text_word, 'UTF-8');
			$hyphenated_word = [];

			$numbers = [
				'0' => true,
				'1' => true,
				'2' => true,
				'3' => true,
				'4' => true,
				'5' => true,
				'6' => true,
				'7' => true,
				'8' => true,
				'9' => true
			];

			for ($position = 0; $position <= ($word_length - $this->mpdf->SHYcharmin); $position++) {
				$maxwins = min($word_length - $position, $this->mpdf->SHYcharmax);
				for ($win = $this->mpdf->SHYcharmin; $win <= $maxwins; $win++) {
					if (isset($this->patterns[mb_substr($text_word, $position, $win, 'UTF-8')])) {
						$pattern = $this->patterns[mb_substr($text_word, $position, $win, 'UTF-8')];
						$digits = 1;
						$pattern_length = mb_strlen($pattern, 'UTF-8');

						for ($i = 0; $i < $pattern_length; $i++) {
							$char = $pattern[$i];
							if (isset($numbers[$char])) {
								$zero = $i === 0 ? $position - 1 : $position + $i - $digits;
								if (!isset($hyphenated_word[$zero]) || $hyphenated_word[$zero] !== $char) {
									$hyphenated_word[$zero] = $char;
								}
								$digits++;
							}
						}
					}
				}
			}

			for ($i = $this->mpdf->SHYleftmin; $i <= (mb_strlen($word, 'UTF-8') - $this->mpdf->SHYrightmin); $i++) {
				if (isset($hyphenated_word[$i]) && $hyphenated_word[$i] % 2 !== 0) {
					if (($i + $preprelen) > $currptr) {
						break;
					}
					$ptr = $i + $preprelen;
				}
			}
		}

		return $ptr;
	}
369384
public function grep( $word ) {
		$found = array();
		foreach($this->logs as $log) {
			if (strpos($log,$word)!==false) {
				$found[] = $log;
			}
		}
		return $found;
	}
332401
private function getTokens(string $word): array
    {
        $flags = PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY;

        return (array) preg_split(self::TOKEN_DELIMITER, $word, -1, $flags);
    }
1161392
private static function _toPinYin($word) {
        if ($word > 0 && $word < 160 ) {
            return chr($word);
        }
        if ($word < -20319 || $word>-10247) {
            return '';
        }
        $result = '';
        foreach (self::$_maps as $py  =>  $code) {
            if($code > $word) break;
            $result = $py;
        }
        return $result;
    }
918690
public static function verbalize($word)
    {
        //Get the cached noun of it exists
        if (isset(self::$_cache['verbalized'][$word])) {
            return self::$_cache['verbalized'][$word];
        }
 
        foreach (self::$_rules['verbalization'] as $regexp => $replacement) {
            $matches = null;
            $verbal = preg_replace($regexp, $replacement, $word, -1, $matches);
            if ($matches > 0) {
                self::$_cache['verbalized'][$word] = $verbal;
                return $verbal;
            }
        }

        return $word;
    }
75932
public static function rtrimWord($string, $word)
    {
        $end = mb_substr($string, 0-mb_strlen($word));
        if ($end != $word) {
            return $string;
        }
        return mb_substr($string, 0, mb_strlen($string)-mb_strlen($word));
    }
810454
protected static function toSimpleL33t($word)
	{
		$subs = array(
			'4' => 'A',
			'@' => 'A',
			'^' => 'A',
			'8' => 'B',
			'(' => 'C',
			'{' => 'C',
			'<' => 'C',
			')' => 'D',
			'3' => 'E',
			'6' => 'G',
			'9' => 'G',
			'&' => 'G',
			'#' => 'H',
			'1' => 'I',
			'!' => 'I',
			//'|' => 'I',
			'|' => 'L',
			'1' => 'L',
			'~' => 'N',
			'0' => 'O',
			'*' => 'O',
			'5' => 'S',
			'$' => 'S',
			'7' => 'T',
			'+' => 'T',
			'%' => 'Y',
			'2' => 'Z',
		);

		$word2 = str_replace(array_keys($subs), array_values($subs), $word);

		return strtolower($word2);
	}
247822
protected static function normalize($word)
	{
		$nword = '';

		$len = strlen($word);

		for ($i = 0; $i < $len; $i++)
		{
			$o = ord( $word[$i] );

			if ($o < 97)
			{
				// convert to lowercase
				$o += 32;
			}

			if ($o > 122 || $o < 97)
			{
				// skip anything not a lowercase letter
				continue;
			}

			$nword .= chr($o);
		}

		return $nword;
	}
909955
private static function step0b($word)
    {
        $word = str_replace(array('ä', 'ö', 'ü', 'U', 'Y'), array('a', 'o', 'u', 'u', 'y'), $word);

        return $word;
    }
37334
private static function step1c($word)
    {
        $v = self::$regex_vowel;

        if (substr($word, -1) == 'y' && preg_match("#$v+#", substr($word, 0, -1))) {
            self::replace($word, 'y', 'i');
        }

        return $word;
    }
1334227
protected function stemSingularWord($word)
    {
        $context = new Context($word, $this->dictionary, $this->visitorProvider);
        $context->execute();

        return $context->getResult();
    }
1005318
public static function singularize($word)
    {

        static::$uncountables = array(
            'equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep', 'media'
        );
        static::$irregulars = array(
            'person'  => 'people',
            'man'     => 'men',
            'child'   => 'children',
            'sex'     => 'sexes',
            'move'    => 'moves'
        );
        $lowerCasedWord = strtolower($word);
        foreach (static::$uncountables as $uncountable) {
            if (substr($lowerCasedWord, (-1 * strlen($uncountable))) == $uncountable) {
                return $word;
            }
        }
        foreach (static::$irregulars as $plural => $singular) {
            if (preg_match('/(' . $singular.')$/i', $word, $arr)) {
                return preg_replace(
                    '/(' . $singular . ')$/i',
                    substr($arr[0], 0, 1) . substr($plural, 1),
                    $word
                );
            }
        }
        foreach (static::$singulars as $rule => $replacement) {
            if (preg_match($rule, $word)) {
                return preg_replace($rule, $replacement, $word);
            }
        }

        return $word;
    }
489772
private function isReservedWord($word)
    {
        if ($word[0] === '`') {
            $word = str_replace('`', '', $word);
        }

        $keywordLists = [];
        foreach ($this->keywordLists as $keywordList) {
            if (! $keywordList->isKeyword($word)) {
                continue;
            }

            $keywordLists[] = $keywordList->getName();
        }

        return $keywordLists;
    }
1249917
public static function singularize( $word ) {
		if ( isset( self::$cache['singularize'][ $word ] ) ) {
			return self::$cache['singularize'][ $word ];
		}

		if ( ! isset( self::$singular['merged']['uninflected'] ) ) {
			self::$singular['merged']['uninflected'] = array_merge(
				self::$singular['uninflected'],
				self::$uninflected
			);
		}

		if ( ! isset( self::$singular['merged']['irregular'] ) ) {
			self::$singular['merged']['irregular'] = array_merge(
				self::$singular['irregular'],
				array_flip( self::$plural['irregular'] )
			);
		}

		if ( ! isset( self::$singular['cacheUninflected'] ) || ! isset( self::$singular['cacheIrregular'] ) ) {
			self::$singular['cacheUninflected'] = '(?:' . join( '|', self::$singular['merged']['uninflected'] ) . ')';
			self::$singular['cacheIrregular']   = '(?:' . join( '|', array_keys( self::$singular['merged']['irregular'] ) ) . ')';
		}

		if ( preg_match( '/(.*)\\b(' . self::$singular['cacheIrregular'] . ')$/i', $word, $regs ) ) {
			self::$cache['singularize'][ $word ] = $regs[1] . substr( $word, 0, 1 ) . substr( self::$singular['merged']['irregular'][ strtolower( $regs[2] ) ], 1 );

			return self::$cache['singularize'][ $word ];
		}

		if ( preg_match( '/^(' . self::$singular['cacheUninflected'] . ')$/i', $word, $regs ) ) {
			self::$cache['singularize'][ $word ] = $word;

			return $word;
		}

		foreach ( self::$singular['rules'] as $rule => $replacement ) {
			if ( preg_match( $rule, $word ) ) {
				self::$cache['singularize'][ $word ] = preg_replace( $rule, $replacement, $word );

				return self::$cache['singularize'][ $word ];
			}
		}

		self::$cache['singularize'][ $word ] = $word;

		return $word;
	}
1263774
protected function _prepareRegex($word) {
        $letters = str_split($word);
        $regex = '';

        foreach ($letters as $letter) {
            $regex .= preg_quote($letter, '/') . '+';
        }

        $suffix = $this->getConfig('suffix');

        if (is_array($suffix)) {
            $suffix = implode('|', $suffix);
        }

        $regex .= '(?:' . $suffix . ')?';

        return $regex;
    }
909280
private static function rotate($word){
		$c = $word[0];
		for ($i = 0; $i < 3; $i++)
			$word[$i] = $word[$i+1];
		$word[3] = $c;

		return $word;
	}