词向量表示接口

@param string $word - 文本内容（GBK编码），最大64字节
@param array $options - 可选参数对象，key: value都为string类型
@description options列表:
@return array
765716
public function wordEmbedding($word, $options=array()){

        $data = array();
        
        $data['word'] = $word;

        $data = array_merge($data, $options);
        $data = mb_convert_encoding(json_encode($data), 'GBK', 'UTF8');

        return $this->request($this->wordEmbeddingUrl, $data);
    }
369384
public function grep( $word ) {
		$found = array();
		foreach($this->logs as $log) {
			if (strpos($log,$word)!==false) {
				$found[] = $log;
			}
		}
		return $found;
	}
1283981
public function suggest($word) 
    {
        if (!pspell_check($this->pSpell, $word)) {
            return pspell_suggest($this->pSpell, $word);
        }
        else {
            return [$word];
        }
    }
854406
protected function hasDash($word)
    {
        $wordWithoutDashes = str_replace('-', '', $word);

        return preg_match("/\-/", $word) && mb_strlen($wordWithoutDashes, $this->encoding) > 1;
    }
389215
private static function step0a($word)
    {
        $vstr = implode('', self::$vowels);
        $word = preg_replace('#([' . $vstr . '])u([' . $vstr . '])#u', '$1U$2', $word);
        $word = preg_replace('#([' . $vstr . '])y([' . $vstr . '])#u', '$1Y$2', $word);

        return $word;
    }
958811
protected function classify($word)
    {
        $s = strtolower(trim($word));
        $s = preg_replace('#([.-])(?=[a-z])#', '$1 ', $s);
        $s = preg_replace('#([._])(?=[a-z])#', '$1 ', $s);
        $s = ucwords($s);
        $s = str_replace('. ', ':', $s);

        return $s = str_replace(['_ ', '- '], '', $s);
    }
152651
protected function serializeAnswerLine(array $word): string
    {
        $line = ['A'];
        
        $specifics = new URLSearchParams($word['specifics'][0] ?? '');
        
        if (isset($word['option'][0])) {
            if (isset($word['type'][0]) && $word['type'][0] === 'selection' && empty($word['answer'])) {
                $line[] = 2;
            } elseif ($specifics->has('require-all-right')) {
                $line[] = 3;
            } else {
                $line[] = 1;
            }
            
            $answers = isset($word['answer'][0]) ? $word['answer'] : $word['text'];
            foreach ($word['option'] as $i => $option) {
                $line[] = $this->serializeQuizField($option);
                if ($line[1] === 2) {
                    $line[] = $i + 1;
                } elseif (in_array($option, $answers)) {
                    $line[] = '\\seikai';
                }
            }
            
            if ($specifics->has('no-random')) {
                $line[] = '\\norandom';
            }
        } else {
            $line[] = 0;
            
            $answers = $this->getAnswers($word, [$this, 'convertToShiftJISableInAnswerWithKatakana']);
            if (!$answers) {
                $this->logUnserializableError('Inteligenceω クイズ', $word);
                return '';
            }
            
            $bonuses = $specifics->getAll('bonus');
            foreach ($answers as $i => $answer) {
                $line[] = $answer;
                if (!empty($bonuses[$i])) {
                    $line[] = "\\bonus=$bonuses[$i]";
                }
            }
        }
        
        $explain[] = $word['text'][0];
        if (isset($word['description'][0])) {
            $explain[] = $word['description'][0]['lml'];
        }
        $line[] = '\\explain=' . $this->serializeQuizField(implode("\n\n", $explain));
        
        return implode(',', $line) . "\r\n";
    }
1296207
function get_suggestions($word)
    {
        $this->init();

        if (!$this->plink) {
            return array();
        }

        $suggestions = pspell_suggest($this->plink, $word);

        if (count($suggestions) > self::MAX_SUGGESTIONS)
            $suggestions = array_slice($suggestions, 0, self::MAX_SUGGESTIONS);

        return is_array($suggestions) ? $suggestions : array();
    }
1002696
public function getLemmas($word, $partOfSpeech = null) {
    if($partOfSpeech !== null && !isset(self::$partsOfSpeech[$partOfSpeech])) {
      $posAsString = implode(' or ', array_keys(self::$partsOfSpeech));
      throw new InvalidArgumentException("partsOfSpeech must be {$posAsString}.");
    }

    $wordEntity = new Word($word);
    if($partOfSpeech !== null) {
      $pos = $this->getPos($partOfSpeech);
      $lemmas = $this->getBaseForm($wordEntity, $pos);
      if(!$lemmas) {
        $lemmas[] = new Lemma($word, $partOfSpeech);
      }
    } else {
      $lemmas = [];
      /** @var PartOfSpeech $pos */
      foreach(self::$partsOfSpeech as $pos) {
        $lemmas = array_merge($lemmas, $this->getBaseForm($wordEntity, $pos));
      }

      if(!$lemmas) {
        /** @var PartOfSpeech $pos */
        foreach(self::$partsOfSpeech as $pos) {
          if(isset($pos->getWordsList()[$word])) {
            $lemmas[] = new Lemma($word, $pos->getPartOfSpeechAsString());
          }
        }
      }

      if(!$lemmas) {
        $lemmas[] = new Lemma($word);
      }
    }

    return array_unique($lemmas, SORT_REGULAR);
  }
709644
public function getWord(string $word)
    {
        if (isset($this->words[strtolower($word)])) {
            return new SpecialWord($word, $this->words[strtolower($word)][0], $this->words[strtolower($word)][1]);
        }

        return new Word($word);
    }
333389
private function parseSizeWord($word)
    {
        $sizeWord = strtoupper(preg_replace('/([a-z])([A-Z])/', '$1_$2', $word));
        if (array_key_exists($sizeWord, $this->sizes)) {
            $size = $this->sizes[$sizeWord];
        } else {
            $size = 0;
        }
        return $size;
    }
768366
private static function getStem($word)
    {
        $str = self::trim($word);
        $str = self::toLower($str);
        $str = self::replaceAccAcuti($str);
        $str = self::putUAfterQToUpper($str);
        $str = self::IUBetweenVowToUpper($str);
        $step0 = self::step0($str);
        $step1 = self::step1($step0);
        $step2 = self::step2($step0, $step1);
        $step3a = self::step3a($step2);
        $step3b = self::step3b($step3a);
        $step4 = self::step4($step3b);

        return $step4;
    }
747603
function _subWord($word)
    {
        static $sbox;
        if (empty($sbox)) {
            list(, , , , $sbox) = $this->_getTables();
        }

        return  $sbox[$word       & 0x000000FF]        |
               ($sbox[$word >>  8 & 0x000000FF] <<  8) |
               ($sbox[$word >> 16 & 0x000000FF] << 16) |
               ($sbox[$word >> 24 & 0x000000FF] << 24);
    }
439335
protected function serializeWord(array $word): string
    {
        if (!isset($word['type'][0]) || $word['type'][0] !== 'selection') {
            $answers = $this->getOrderedAnswers($word);
            if ($answers) {
                foreach ($answers as $answer) {
                    if (strpos($answer, '//') === false) {
                        $output = $answer;
                        break;
                    }
                }
                if (!isset($output)) {
                    $output = str_replace('/', '／', $answers[0]);
                }
                $output = strtolower($output);
                
                $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 .= "\t// " . str_replace("\n", ' ', $comment);
                }
                $output .= "\r\n";
            }
        }
        
        if (!isset($output)) {
            $output = '';
            $this->logUnserializableError('キャッチフィーリング', $word);
        }
        return $output;
    }
728202
public function findWord($word)
    {
        $key = $this->collator->getSortKey($word);

        /* In intl > 3.0.0a1, the key now ends with a trailing NUL byte.
         * We remove it for backward-compatibility with older releases. */
        if (substr($key, -1) === "\0") {
            $key = substr($key, 0, -1);
        }

        $this->existsQuery->execute(array(':key' => $key));
        $res = $this->existsQuery->fetchColumn();
        $this->existsQuery->closeCursor();
        if ($res === false || $res === null) {
            return null;
        }
        return $res;
    }
664836
public static function oneByWord($word)
	{
		$word = trim($word);
		$word = strtolower($word);

		return self::blank()
			->whereEquals('word', $word)
			->row();
	}
906711
public static function underscore($word) {
		if (isset(static::$_underscored[$word])) {
			return static::$_underscored[$word];
		}
		return static::$_underscored[$word] = strtolower(static::slug($word, '_'));
	}