文書のスペルの修正
この例では、Hunspell を使用して文書のスペルを修正する方法を示します。
テキスト データの読み込み
トークン化された文書の配列を作成します。
str = [
"Use MATLAB to correct spelling of words."
"Correctly spelled worrds are important for lemmatization."
"Text Analytics Toolbox providesfunctions for spelling correction."];
documents = tokenizedDocument(str)documents =
3×1 tokenizedDocument:
8 tokens: Use MATLAB to correct spelling of words .
8 tokens: Correctly spelled worrds are important for lemmatization .
8 tokens: Text Analytics Toolbox providesfunctions for spelling correction .
スペルの修正
関数 correctSpelling を使用して文書のスペルを修正します。
updatedDocuments = correctSpelling(documents)
updatedDocuments =
3×1 tokenizedDocument:
8 tokens: Use MATLAB to correct spelling of words .
8 tokens: Correctly spelled words are important for solemnization .
9 tokens: Text Analytics Toolbox provides functions for spelling correction .
次の点に注意してください。
入力単語 "MATLAB" が "MAT" と "LAB" の 2 つの単語に分割されている。
入力単語 "worrds" が "words" に変更されている。
入力単語 "lemmatization" が "solemnization" に変更されている。
入力単語 "Analytics" が "Analytic" に変更されている。
入力単語 "providesfunctions" が "provides" と "functions" の 2 つの単語に分割されている。
カスタム単語の指定
ソフトウェアが特定の単語を更新しないようにするために、関数 correctSpelling の 'KnownWords' オプションを使用して、既知の単語のリストを提供できます。
"MATLAB"、"Analytics"、および "lemmatization" という単語を既知の単語として指定し、文書のスペルを再度修正します。
updatedDocuments = correctSpelling(documents,'KnownWords',["MATLAB" "Analytics" "lemmatization"])
updatedDocuments =
3×1 tokenizedDocument:
8 tokens: Use MATLAB to correct spelling of words .
8 tokens: Correctly spelled words are important for lemmatization .
9 tokens: Text Analytics Toolbox provides functions for spelling correction .
ここで、"MATLAB"、"Analytics"、および "lemmatization" という単語が未変更のままであることに注意してください。
参考
correctSpelling | tokenizedDocument