> ## Documentation Index
> Fetch the complete documentation index at: https://docs.abbyy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 辞書の利用

> 標準辞書、ユーザー辞書、正規表現辞書、または集約辞書を ABBYY FineReader Engine の認識言語にアタッチして、分野固有のテキストに対する OCR の精度を向上させます。

<Note>
  C# サンプルは、Windows 版 FRE でのみ使用できます。
</Note>

ABBYY FineReader Engine では、さまざまな種類の辞書を認識言語に追加でき、認識精度を大幅に向上させることができます。

<div id="dictionary-types">
  ## 辞書の種類
</div>

辞書にはいくつかの種類があります。

<Accordion title="標準辞書">
  この種類の辞書は、辞書サポートが組み込まれている定義済み言語用にあらかじめ用意されています ([定義済み言語の一覧](/ja/fine-reader/engine/specifications/predefined-languages)のコメントを参照) 。さらに、一部の言語については、.zmd アーカイブに専門用語辞書 (医療、法律など) が含まれています。標準辞書は 3 つまたは 4 つのファイルで構成されます。これらのファイル名は通常、言語の正式名または短縮名と同じで、拡張子は .amd、.amm、.amt、または .ame です。.amd、.amm、.amt 拡張子のファイルは常に存在します。これらのファイルは次のフォルダーに格納されており、変更することはできません。[Data/ExtendedDictionaries](/ja/fine-reader/engine/distribution/distribution-windows/distribution-kit#dictionaries) (Linux)、[Resources/ExtendedDictionaries](/ja/fine-reader/engine/distribution/distribution-windows/distribution-kit#dictionaries) (macOS)、[Data\ExtendedDictionaries](/ja/fine-reader/engine/distribution/distribution-windows/distribution-kit#dictionaries) (Windows)。

  ABBYY FineReader Engine には .ame ファイルは含まれていません。.ame は辞書拡張、つまりユーザーが辞書に追加した単語を保存するための形式です。辞書拡張は ABBYY FineReader で作成できます。ABBYY FineReader ではこれをユーザー辞書と呼びます。作成したファイルは、上記の ABBYY FineReader Engine フォルダー配下のフォルダーにコピーできます (または、[ILanguageDatabase::DictionaryExtensionsPath](/ja/fine-reader/engine/api-reference/language-related-objects/languagedatabase#dictionaryextensionspath) プロパティでそのフルパスを指定することもできます) 。ABBYY FineReader は、標準辞書の拡張を %appdata%\ABBYY\FineReader\15\FineReaderShell\UserDictionaries に保存します。辞書拡張は、ABBYY FineReader Engine で [ILanguageDatabase::OpenDictionaryExtension](/ja/fine-reader/engine/api-reference/language-related-objects/languagedatabase/opendictionaryextension-method) メソッドを使用して編集できます。

  この種類の辞書は、[StandardDictionaryDescription](/ja/fine-reader/engine/api-reference/language-related-objects/standarddictionarydescription) オブジェクトで記述されます。
</Accordion>

<Accordion title="ユーザー辞書">
  これは [Dictionary](/ja/fine-reader/engine/api-reference/language-related-objects/dictionary) オブジェクトを使用して作成できます。Dictionary オブジェクトでは、そのメソッドを使って単語を追加または削除できます。

  Windows では、Dictionary オブジェクトを使用して、[Dictionary ダイアログ](/ja/fine-reader/engine/api-reference/language-related-objects/dictionary/edit-method/dictionary-dialog-box) から辞書を編集することもできます。このダイアログでは、Windows ANSI および Unicode エンコーディングの任意のテキストファイルをインポートできます (唯一の要件は、単語がスペースまたはその他の非アルファベット文字で区切られていることです) 。

  この種類の辞書は、[UserDictionaryDescription](/ja/fine-reader/engine/api-reference/language-related-objects/userdictionarydescription) オブジェクトで記述されます。

  <Note>
    FineReader Engine のユーザー辞書は .amd ファイル形式で、どの言語に対しても作成できます。辞書サポートのない言語では、標準辞書の代わりとして使用できます。ABBYY FineReader のユーザー辞書は、FineReader Engine では辞書拡張と呼ばれ、.ame ファイルです。これは、辞書サポートがある言語についてのみ、その言語の標準辞書の拡張として作成できます。
  </Note>
</Accordion>

<Accordion title="正規表現ベースの辞書">
  ある言語でどの単語を許可し、どの単語を許可しないかを定義するルールを指定します。

  この種類の辞書は、[RegExpDictionaryDescription](/ja/fine-reader/engine/api-reference/language-related-objects/regexpdictionarydescription) オブジェクトで記述されます。
</Accordion>

<Accordion title="外部辞書">
  独自の種類の辞書を実装できます。この辞書は、クライアント側で実装される [IExternalDictionary](/ja/fine-reader/engine/api-reference/language-related-objects/iexternaldictionary-interface) インターフェイスとして表されます。外部辞書の作成に関するガイドラインについては、このインターフェイスの説明を参照してください。

  この種類の辞書は、[ExternalDictionaryDescription](/ja/fine-reader/engine/api-reference/language-related-objects/externaldictionarydescription) オブジェクトで記述されます。
</Accordion>

ABBYY FineReader Engine には、すべての種類の辞書を記述するための [DictionaryDescription](/ja/fine-reader/engine/api-reference/language-related-objects/dictionarydescription) オブジェクトが用意されています。これは、各種辞書の記述の基底となるオブジェクトです。

これらすべての辞書記述は、[DictionaryDescriptions](/ja/fine-reader/engine/api-reference/language-related-objects/dictionarydescriptions) コレクションの要素です。

<div id="creating-a-dictionary-description">
  ## 辞書記述の作成
</div>

辞書記述を作成するには、DictionaryDescriptions オブジェクトの [AddNew](/ja/fine-reader/engine/api-reference/language-related-objects/dictionarydescriptions/addnew-method) メソッドを使用します。このメソッドは、DictionaryDescription オブジェクトへの参照を返します。対応する辞書タイプを記述するオブジェクトへの参照を取得するには、DictionaryDescription オブジェクトの [GetAsStandardDictionaryDescription](/ja/fine-reader/engine/api-reference/language-related-objects/dictionarydescription/getasstandarddictionarydescription-method)、[GetAsUserDictionaryDescription](/ja/fine-reader/engine/api-reference/language-related-objects/dictionarydescription/getasuserdictionarydescription-method)、[GetAsRegExpDictionaryDescription](/ja/fine-reader/engine/api-reference/language-related-objects/dictionarydescription/getasregexpdictionarydescription-method)、[GetAsExternalDictionaryDescription](/ja/fine-reader/engine/api-reference/language-related-objects/dictionarydescription/getasexternaldictionarydescription-method) メソッドを使用します。

<div id="dictionary-properties">
  ## 辞書のプロパティ
</div>

各辞書では、その辞書を識別するプロパティを指定する必要があります。

* 標準辞書 (StandardDictionaryDescription) の場合は、言語の ID を定義する `LanguageId` プロパティを指定します。
* ユーザー辞書 (UserDictionaryDescription) の場合は、ユーザー辞書へのパスを指定する `FileName` プロパティを指定します。
* 正規表現ベースの辞書 (RegExpDictionaryDescription) の場合は、正規表現を指定するために [SetText](/ja/fine-reader/engine/api-reference/language-related-objects/regexpdictionarydescription/settext-method) メソッドを使用します。[ABBYY FineReader Engine での正規表現の使用](/ja/fine-reader/engine/guided-tour/advanced-techniques/working-with-regular-expressions)を参照してください。
* 外部辞書 (ExternalDictionaryDescription) の場合は、辞書を指定するために [SetDictionary](/ja/fine-reader/engine/api-reference/language-related-objects/externaldictionarydescription/setdictionary-method) メソッドを使用します。

すべての辞書タイプには重みが割り当てられます。辞書の重みは、認識時に検出されたその辞書内の単語の重みに影響します。weight パラメーターはパーセンテージで表され、0 以上である必要があります。重みが 0 であっても、その辞書が存在しないことを自動的に意味するわけではありません。100 パーセントを超える重みも使用できますが、このようなパラメーターを使用する際には十分な注意が必要です。重みは [IDictionaryDescription::Weight](/ja/fine-reader/engine/api-reference/language-related-objects/dictionarydescription#weight) プロパティで指定し、既定値は 100 です。

標準辞書には [CanUseTrigrams](/ja/fine-reader/engine/api-reference/language-related-objects/standarddictionarydescription#canusetrigrams) オプションもあり、選択した辞書に基づいて作成されたトライグラムをプログラムで使用することを許可または禁止できます。トライグラムは 3 文字の組み合わせです。こうした組み合わせのすべてが実際の単語に現れるわけではありません。辞書にないトライグラムを含む単語は、発音不能である可能性が非常に高くなります。トライグラムは、信頼性の低い単語を除外するために使用されます。"general" 標準辞書ではトライグラムを有効にし、用語辞書では無効にすることをお勧めします。

<div id="dictionaries-of-a-recognition-language">
  ## 認識言語の辞書
</div>

テキスト認識言語 ([TextLanguage](/ja/fine-reader/engine/api-reference/language-related-objects/textlanguage) オブジェクト) には、その言語の単語を含む辞書と、使用禁止語を含む辞書の両方を設定できます。前者は、テキスト言語の各[基本言語](/ja/fine-reader/engine/api-reference/language-related-objects/baselanguage)に対して指定され、[IBaseLanguage::DictionaryDescriptions](/ja/fine-reader/engine/api-reference/language-related-objects/baselanguage#dictionarydescriptions) プロパティから参照できます。基本言語には辞書が関連付けられていない場合もあります。使用禁止語辞書は、[ITextLanguage::ProhibitingDictionaries](/ja/fine-reader/engine/api-reference/language-related-objects/textlanguage#prohibitingdictionaries) プロパティを通じて、テキスト認識言語に直接関連付けられます。

認識時に辞書内の単語だけを許可する場合は、[IBaseLanguage::AllowWordsFromDictionaryOnly](/ja/fine-reader/engine/api-reference/language-related-objects/baselanguage#allowwordsfromdictionaryonly) プロパティを TRUE に設定します。この場合、基本言語の辞書に見つからない単語が認識結果のテキストに現れるのは、ABBYY FineReader Engine が辞書候補をまったく見つけられなかった場合に限られます。

<div id="how-to-attach-a-dictionary-to-a-recognition-language">
  ## 認識言語に辞書を関連付ける方法
</div>

1. 利用可能なメソッドのいずれかを使用して [TextLanguage](/ja/fine-reader/engine/api-reference/language-related-objects/textlanguage) オブジェクトを作成します (例: [LanguageDatabase](/ja/fine-reader/engine/api-reference/language-related-objects/languagedatabase) オブジェクトの [CreateTextLanguage](/ja/fine-reader/engine/api-reference/language-related-objects/languagedatabase/createtextlanguage-method) メソッド) 。
2. 新しいテキスト言語の基本言語コレクションを取得します ([BaseLanguages](/ja/fine-reader/engine/api-reference/language-related-objects/textlanguage#baselanguages) プロパティを使用) 。
3. 新しい [BaseLanguage](/ja/fine-reader/engine/api-reference/language-related-objects/baselanguage) オブジェクトを作成し、基本言語のコレクションに追加します。
4. 新しい基本言語の辞書記述コレクションを取得します ([DictionaryDescriptions](/ja/fine-reader/engine/api-reference/language-related-objects/baselanguage#dictionarydescriptions) プロパティ) 。
5. 辞書記述を作成し、それを基本言語の辞書記述コレクションに追加します。[DictionaryDescriptions](/ja/fine-reader/engine/api-reference/language-related-objects/dictionarydescriptions) コレクションの [AddNew](/ja/fine-reader/engine/api-reference/language-related-objects/dictionarydescriptions/addnew-method) メソッドを使用します。

<Note>
  種類の異なる辞書を複数作成し、それらを 1 つの基本認識言語の [DictionaryDescriptions](/ja/fine-reader/engine/api-reference/language-related-objects/dictionarydescriptions) コレクションに追加できます。
</Note>

6. \[任意] 作成した辞書の重みを指定します。
7. 辞書の識別プロパティを指定します。標準辞書の場合は LanguageId プロパティ、ユーザー辞書の場合は FileName プロパティ、正規表現ベースの辞書の場合は IRegExpDictionaryDescription::SetText メソッドを呼び出し、外部辞書の場合は IExternalDictionaryDescription::SetDictionary メソッドを呼び出します。
8. \[任意] [BaseLanguage](/ja/fine-reader/engine/api-reference/language-related-objects/baselanguage) オブジェクトのその他のプロパティを指定します。
9. \[任意] [TextLanguage](/ja/fine-reader/engine/api-reference/language-related-objects/textlanguage) オブジェクトの ProhibitingDictionaries プロパティを使用して禁止辞書を設定します。
10. 作成した [TextLanguage](/ja/fine-reader/engine/api-reference/language-related-objects/textlanguage) オブジェクトを [RecognizerParams](/ja/fine-reader/engine/api-reference/parameter-objects/preprocessing-analysis-recognition-and-synthesis-parameters/recognizerparams) オブジェクトの TextLanguage プロパティに割り当てます。

これらの手順を Windows で実装するには、以下のコード サンプルを参照してください。

<Accordion title="C++ (COM) コード">
  ```cpp theme={null}
  // グローバル ABBYY FineReader Engine オブジェクト
  FREngine::IEnginePtr Engine;
  // LanguageDatabase オブジェクト
  FREngine::ILanguageDatabasePtr languageDatabase;
  ...
  // TextLanguage オブジェクトを作成し、その基本言語コレクションを取得
  FREngine::ITextLanguagePtr pTextLang = languageDatabase->CreateTextLanguage();
  FREngine::IBaseLanguagesPtr pBaseLangCollection = pTextLang->BaseLanguages;
  // BaseLanguage オブジェクトを作成し、その辞書記述コレクションを取得
  FREngine::IBaseLanguagePtr pBaseLang = pBaseLangCollection->AddNew();
  pBaseLang->InternalName = L"SampleBaseLanguage";
  pBaseLang->PutLetterSet( FREngine::BLLS_Alphabet, L"abc123" );
  FREngine::IDictionaryDescriptionsPtr pDictDescCollection = pBaseLang->DictionaryDescriptions;
  // 標準辞書記述を作成し、コレクションに追加
  FREngine::IDictionaryDescriptionPtr pDicDescription =
   pDictDescCollection->AddNew( FREngine::DT_SystemDictionary);
  // [optional] 作成した辞書の重みを指定
  pDicDescription->Weight = 100;
  // 辞書の識別プロパティを指定
  FREngine::IStandardDictionaryDescriptionPtr pStandardDic = pDicDescription->GetAsStandardDictionaryDescription();
  pStandardDic->LanguageId = FREngine::LI_EnglishUnitedStates;
  // [optional] BaseLanguage のその他のプロパティを指定
  pBaseLang->AllowWordsFromDictionaryOnly = VARIANT_TRUE;
  // RecognizerParams オブジェクトを作成
  FREngine::IRecognizerParamsPtr pParams = Engine->CreateRecognizerParams();
  // 作成した TextLanguage オブジェクトを TextLanguage プロパティに割り当て
  pParams->TextLanguage = pTextLang;
  ...
  ```
</Accordion>

<Accordion title="C# コード">
  ```csharp theme={null}
  // グローバル ABBYY FineReader Engine オブジェクト
  FREngine.IEngine engine;
  // LanguageDatabase オブジェクト
  FREngine.ILanguageDatabase languageDatabase;
  ...
  // TextLanguage オブジェクトを作成し、そのベース言語のコレクションを取得します
  FREngine.ITextLanguage TextLang = languageDatabase.CreateTextLanguage();
  FREngine.IBaseLanguages BaseLangCollection = TextLang.BaseLanguages;
  // BaseLanguage オブジェクトを作成し、その辞書記述のコレクションを取得します
  FREngine.IBaseLanguage BaseLang = BaseLangCollection.AddNew();
  BaseLang.InternalName = "SampleBaseLanguage";
  BaseLang.set_LetterSet( FREngine.BaseLanguageLetterSetEnum.BLLS_Alphabet, "abc123" );
  FREngine.IDictionaryDescriptions DictDescCollection = BaseLang.DictionaryDescriptions;
  // 標準辞書の記述を作成してコレクションに追加します
  FREngine.IDictionaryDescription DicDescription = DictDescCollection.AddNew( FREngine.DictionaryTypeEnum.DT_SystemDictionary );
  // [任意] 作成した辞書の重みを指定します
  DicDescription.Weight = 100;
  // 辞書の識別プロパティを指定します
  FREngine.IStandardDictionaryDescription StandardDic = DicDescription.GetAsStandardDictionaryDescription();
  StandardDic.LanguageId = FREngine.LanguageIdEnum.LI_EnglishUnitedStates;
  // [任意] BaseLanguage のその他のプロパティを指定します
  BaseLang.AllowWordsFromDictionaryOnly = true;
  // RecognizerParams オブジェクトを作成します
  FREngine.IRecognizerParams recParams = engine.CreateRecognizerParams();
  // 作成した TextLanguage オブジェクトを TextLanguage プロパティに割り当てます
  recParams.TextLanguage = TextLang;
  ...
  ```
</Accordion>

<div id="cache-dictionary">
  ## キャッシュ辞書
</div>

キャッシュ辞書は、小規模な辞書 (約 100 語) で、処理中でも簡単に変更できます。キャッシュ辞書は、たとえば処理中に文書に関する新しい情報が見つかり、より適切な辞書をより絞り込んで選択できる場合に使用できます。このような辞書は、field 単位の認識に適しています。

たとえば、認識する必要があるフォーム上の field が 2 つあるとします。1 つは都市名、もう 1 つは通り名です。都市名はすでに認識されていて、その都市の通り名の一覧もあるとします。この場合、該当するキャッシュ辞書に通り名を読み込むことで、通り名をより高速かつ高精度に認識できます。

ABBYY FineReader Engine では、キャッシュ辞書を操作するために、[FRPage](/ja/fine-reader/engine/api-reference/document-related-objects/frpage) オブジェクトの [AddWordsToCacheDictionary](/ja/fine-reader/engine/api-reference/document-related-objects/frpage/addwordstocachedictionary-method)、[AddWordToCacheDictionary](/ja/fine-reader/engine/api-reference/document-related-objects/frpage/addwordtocachedictionary-method)、および [CleanCacheDictionary](/ja/fine-reader/engine/api-reference/document-related-objects/frpage/cleancachedictionary-method) メソッドが提供されています。

<Warning>
  キャッシュ辞書を使用するには、[IEngine::AutoCleanRecognizerSession](/ja/fine-reader/engine/api-reference/engine-object-iengine-interface/properties#autocleanrecognizersession) プロパティを FALSE に設定する必要があります。AutoCleanRecognizerSession プロパティの既定値は TRUE です。つまり、FineReader Engine は各ページの認識後に認識セッションをクリーンアップし、その際にキャッシュ辞書もクリーンアップされます。ユーザーデータが誤って破棄されるのを防ぐため、FineReader Engine はこのモードでのキャッシュ辞書の使用を禁止しています。キャッシュ辞書を使用する場合は、必要に応じて [IEngine::CleanRecognizerSession](/ja/fine-reader/engine/api-reference/engine-object-iengine-interface/supplementary-methods/cleanrecognizersession-method) メソッドを呼び出し、認識セッションを手動でクリーンアップする必要があります。認識セッションをクリーンアップする必要があるタイミングについては、このメソッドの説明を参照してください。
</Warning>

<div id="see-also">
  ## 関連項目
</div>

[言語の扱い](/ja/fine-reader/engine/guided-tour/advanced-techniques/working-with-languages)

[スペースを含むWordsの認識](/ja/fine-reader/engine/guided-tour/advanced-techniques/recognizing-words-with-spaces)
