メインコンテンツ

文書のスペルの修正

この例では、Hunspell を使用して文書のスペルを修正する方法を示します。

テキスト データの読み込み

トークン化された文書の配列を作成します。

str = [
    "Correctly spelled worrds are important for lemmatization."
    "Text Analytics Toolbox providesfunctions for spelling correction."
    "The phrase Higgs boson is a technical term."];
documents = tokenizedDocument(str)
documents = 
  3×1 tokenizedDocument:

    8 tokens: Correctly spelled worrds are important for lemmatization .
    8 tokens: Text Analytics Toolbox providesfunctions for spelling correction .
    9 tokens: The phrase Higgs boson is a technical term .

スペルの修正

関数correctSpellingを使用して文書のスペルを修正します。

updatedDocuments = correctSpelling(documents)
updatedDocuments = 
  3×1 tokenizedDocument:

    8 tokens: Correctly spelled words are important for lemmatization .
    9 tokens: Text Analytics Toolbox provides functions for spelling correction .
    9 tokens: The phrase Riggs boson is a technical term .

次の点に注意してください。

  • 入力単語 "worrds" が "words" に変更されている。

  • 入力単語 "lemmatization" が "solemnization" に変更されている。

  • 入力単語 "providesfunctions" が "provides" と "functions" の 2 つの単語に分割されている。

  • 入力単語 "Higgs" が "Riggs" に変更されている。

カスタム単語の指定

ソフトウェアが特定の単語を更新しないようにするために、correctSpelling 関数の名前と値の引数 KnownWords を使用して、既知の単語のリストを提供できます。

"lemmatization" と "Higgs" を既知の単語として指定し、文書のスペルを再度修正します。

updatedDocuments = correctSpelling(documents,KnownWords=["lemmatization","Higgs"])
updatedDocuments = 
  3×1 tokenizedDocument:

    8 tokens: Correctly spelled words are important for lemmatization .
    9 tokens: Text Analytics Toolbox provides functions for spelling correction .
    9 tokens: The phrase Higgs boson is a technical term .

ここで、"lemmatization" および "Higgs" という単語が未変更のままであることに注意してください。

参考

|

トピック