HunSpellChecker クラスを使用して文字列のスペル チェックを試みています ( https://web.archive.org/web/20130311163032/http://www.phpkode.com/source/s/php-spell-checker/php-を参照)。 spell-checker/HunSpellChecker.class.php ) および hunspell スペリング エンジン。関連する関数は次の場所にコピーされます。
public function checkSpelling ($text, $locale, $suggestions = true) {
$text = trim($text);
if ($this->textIsHtml == true) {
$text = strtr($text, "\n", ' ');
} elseif ($text == "") {
$this->spellingWarnings[] = array(self::SPELLING_WARNING__TEXT_EMPTY=>"Text empty");
return false;
}
$descspec = array(
0=>array('pipe', 'r'),
1=>array('pipe', 'w'),
2=>array('pipe', 'w')
);
$pipes = array();
$cmd = $this->hunspellPath;
$cmd .= ($this->textIsHtml) ? " -H ":"";
$cmd .= " -d ".dirname(__FILE__)."/dictionaries/hunspell/".$locale;
$process = proc_open($cmd, $descspec, $pipes);
if (!is_resource($process)) {
$this->spellingError[] = array(self::SPELLING_ERROR__INTERNAL_ERROR=>"Hunspell process could not be created.");
return false;
}
fwrite($pipes[0], $text);
fclose($pipes[0]);
$out = '';
while (!feof($pipes[1])) {
$out .= fread($pipes[1], 4096);
}
fclose($pipes[1]);
// check for errors
$err = '';
while (!feof($pipes[2])) {
$err .= fread($pipes[2], 4096);
}
if ($err != '') {
$this->spellingError[] = array(self::SPELLING_ERROR__INTERNAL_ERROR=>"Spell checking error: ".$err);
fclose($pipes[2]);
return false;
}
fclose($pipes[2]);
proc_close($process);
if (strlen($out) === 0) {
$this->spellingError[] = array(self::SPELLING_WARNING__EMPTY_RESULT=>"Empty result");
return false;
}
return $this->parseHunspellOutput(explode("\n", $out), $locale, $suggestions);
}
ASCII 文字列では問題なく動作しますが、アクセント付き文字 (necessário、segurança など) を含むさまざまな言語の文字列や、非ラテン アルファベット (ギリシャ語、アラビア語など) の文字列をチェックする必要があります。
これらの場合の問題は、ASCII 以外の単語が正しくセグメント化されておらず、Hunspell に送信された「スペルミス」の単語が実際には完全な単語ではなく部分文字列であることです (必要に応じて、セグラン)。
問題が発生した場所を追跡しようとしましたが、文字列がリソースに変換されたとき (またはその後のどこか) に、上記のリンクされたクラスの 072 行目にあるに違いないと思います。行 072 には以下が含まれます。
fwrite($pipes[0], $text);
クラスはコメントされていないので、そこで何が起こっているのかよくわかりません。
誰かが同様の問題に対処しましたか、または誰かが助けてくれますか?
このクラスは、examples/HunspellBased.php ファイル ( http://titirit.users.phpclasses.org/package/5597-PHP-Check-spelling-of-text-and-get-fix-suggestions.htmlからダウンロードしたパッケージ) に含まれています。 )。Enchant を使用しようとしましたが、まったく機能しませんでした。
ありがとうございました!乾杯、マヌエル