> ## 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 FlexiCapture SDK による請求書の認識

請求書は flexible ドキュメントであり、field のデザインや数、レイアウトがドキュメントごとに大きく異なる場合があります。ABBYY FlexiCapture SDK を使用すると、請求書から情報を抽出できます。

## あらかじめ設定された FlexiCapture 請求書プロジェクトの使用

ABBYY FlexiCapture SDK には、あらかじめ設定された FlexiCapture 請求書プロジェクトが複数用意されています。これらのプロジェクトには、各国の請求書向けに最適化されたドキュメント定義が含まれています。sample プロジェクトは、**Samples** フォルダー (Start > Programs > ABBYY FlexiCapture 12 SDK > Code Samples Folder) 内の **SampleInvoiceProjects** にあります。または、事前定義された国と、そのうちいずれかの国向けに設定された Document Definition を含む空のプロジェクトを作成することもできます。

* オーストラリアまたはニュージーランド
* カナダ
* 欧州連合
* 日本
* スペイン
* アメリカ合衆国

FlexiCapture 開発者パッケージで作成・設定した FlexiCapture 請求書プロジェクトを使用することもできます。その場合は、[help.abbyy.com](http://help.abbyy.com/en-us/flexicapture/12/invoice_reader/ir_titletopic) を参照してください。

## 新規プロジェクトのセットアップ

請求書 プロジェクトは、[通常の FlexiCapture プロジェクト](https://docs.abbyy.com/ja/flexi-capture/sdk/guided-tour/tutorial-overview.md)と同じ方法でセットアップします。ただし、認識精度を最大限に高めるために、追加の設定を行うこともできます。

1. **Engine** オブジェクトの [**CreateInvoiceProject**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/engine-createinvoiceproject.md) メソッドを使用して空の 請求書 プロジェクトを作成するか、[**OpenProject**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/engine-openproject.md) メソッドを使用して既存のプロジェクトを開きます ([プロジェクトを開く](https://docs.abbyy.com/ja/flexi-capture/sdk/guided-tour/engine-openingproject.md)も参照してください) 。

2. 事業部門とベンダーのデータセットをロードします。
   1. [**Project**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/project.md) の [**DocumentDefinitions**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/documentdefinitions.md) コレクションから [**DocumentDefinition**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/documentdefinition.md) を取得します。**DocumentDefinitions** オブジェクトの [**CheckOut**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/documentdefinitions-checkout.md) メソッドを呼び出して、Document Definition を編集モードに切り替えます。
   2. [**DataSets**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/datasets.md) オブジェクトの [**Find**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/datasets-find.md) メソッドを使用して、「Vendors」および「BusinessUnits」データセットを取得します。
   3. ベンダーと事業部門の情報をデータセットに登録します。[**DataSetTableRecords**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/datasettablerecords.md) オブジェクトの [**AddNew**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/datasets-addnew.md) メソッドと [**Field**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/datasettablerecord-field.md) プロパティを使用してレコードを 1 件ずつ追加するか、[**UpdateFromDB**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/datasettablerecords-updatefromdb.md) メソッドを使用して 1 回の操作でデータセット全体にデータを入力します。
      注：**UpdateFromDB** を使用するには、外部データベースへの接続を構成しておく必要があります。接続は FlexiCapture 開発者パッケージで設定できます。
   4. **DataSetTableRecords** オブジェクトの [**Commit**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/datasettablerecords-commit.md) メソッドを呼び出して、データセットへの変更を保存します。続いて、**DocumentDefinitions** オブジェクトの [**CheckIn**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/documentdefinitions-checkin.md) メソッドを呼び出します。

      > [!NOTE]
      >
      > リリース 1 Update 4 以降では、データベースが接続されていない場合でも、ベンダーと事業部門に関する一部の情報が検出されます。会社名と住所は機械学習によって検出され、税務識別番号と IBAN (国際銀行口座番号) はその特徴的な形式に基づいて認識されます。

3. より良い結果を得るために、[追加オプション](#additional-options)を指定することもできます。

## 請求書からのデータ抽出

1. バッチを作成し、そこに[画像を追加](https://docs.abbyy.com/ja/flexi-capture/sdk/guided-tour/engine-addingimages.md)します。
2. [画像を認識](https://docs.abbyy.com/ja/flexi-capture/sdk/guided-tour/engine-recognizing.md)します。認識の過程で、プログラムは Document Definition を適用してフィールド値を抽出します。
3. 抽出データを操作します。検出されたすべての field を順に確認し、それぞれの値を取得できます ([認識データの操作](https://docs.abbyy.com/ja/flexi-capture/sdk/guided-tour/workingwithrecognizeddata.md)を参照) 。field が正しく検出されなかった場合は、正しい領域を設定し、今後この field をより正確に抽出できるよう認識エンジンを学習させることができます ([フィールド抽出の学習](https://docs.abbyy.com/ja/flexi-capture/sdk/guided-tour/fieldsextractiontraining.md)を参照) 。
4. [結果をエクスポート](https://docs.abbyy.com/ja/flexi-capture/sdk/guided-tour/engine-exporting.md)します。

> [accordion] C# コード
>
> ```csharp theme={null}
> IProject project = engine.CreateInvoiceProject(projectPath,
>     InvoiceProjectTypeEnum.IPT_EuropeanUnion);
>
> IDocumentDefinitions documentDefinitions = project.DocumentDefinitions;
> IDocumentDefinition documentDefinition = documentDefinitions[0];
> documentDefinitions.CheckOut(documentDefinition);
>
> // Vendors データセットのレコードを取得してデータを入力する
> IDataSet vendorsDataSet = documentDefinition.DataSets.Find("", "Vendors");
> IDataSetTableRecords records = vendorsDataSet.TableRecords;
> IDataSetTableRecord record = records.AddNew();
> record.Field["Name"] = "The Hotel";
> record.Field["CountryCode"] = "FR";
>
> // 変更をコミットする
> records.Commit(null);
> documentDefinitions.CheckIn(documentDefinition);
>
> // 認識用の画像を含むバッチを作成する
> IBatch workingBatch = project.Batches.AddNew();
> workingBatch.Open();
> workingBatch.AddImage("ImagePath");
> workingBatch.Recognize(null, RecognitionModeEnum.RM_ReApplyDocumentDefinitions, null);
> workingBatch.Export(null, null);
> workingBatch.Close();
> project.Close();
> ```

## データセットを使用しない請求書の処理

請求書のデータ抽出は、「Vendors」および「BusinessUnits」データセットを使用せずに行うこともできます。その場合は、クラスタリング機能を使用してフィールドを学習させる必要があります。

1. [**CreateInvoiceProject**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/engine-createinvoiceproject.md) メソッドを使用して空の請求書プロジェクトを作成するか、**Engine** オブジェクトの [**OpenProject**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/engine-openproject.md) メソッドを使用してデータセットのないプロジェクトを開きます。
2. [**InvoiceSettings**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/invoicesettings.md) オブジェクトの [**InvoiceFeatures**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/invoicesettings.md#invoicefeatures) プロパティを使用して、クラスタリング機能を有効にします。
3. [**FieldsExtractionTrainingBatches**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/fieldsextractiontrainingbatches.md) オブジェクトの [**AddNew**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/fieldsextractiontrainingbatches-addnew.md) メソッドを使用して、新しい学習用バッチを追加します。*Record* パラメーターの値には、ベンダーのレコードの代わりに NULL を渡します。
4. 学習用のドキュメントを何件か追加します。各ページで、学習させるフィールド (*Total* フィールドなど) を指定します。なお、ベンダーおよび事業部門のフィールドは学習させることができません。
5. [**FieldsExtractionTrainingBatch**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/fieldsextractiontrainingbatch.md) オブジェクトの [**FieldsExtractionTrainer**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/fieldsextractiontrainingbatch.md#fieldsextractiontrainer) プロパティを使用して、[**FieldsExtractionTrainer**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/fieldsextractiontrainer.md) オブジェクトを取得します。
6. トレーナーオブジェクトの [**Train**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/fieldsextractiontrainer-train.md) メソッドを呼び出して、フィールド抽出の学習を実行します。
7. これで、[**Batch**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/batch.md) オブジェクトの [**Recognize**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/batch-recognize.md) メソッドを呼び出すことで、作業バッチ内にある、学習に使用したものと類似したドキュメントを認識できます。学習させたフィールドは、より高い精度で検出および抽出されるようになります。

## その他のオプション

#### 国と言語一覧

請求書の認識には事前定義された多数の国と言語が用意されていますが、必要な国が一覧にない場合は追加できます。[**ICountries::AddNew**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/countries-addnew.md) メソッドを使用し、新しい [**Country**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/country.md) オブジェクトの [**Name**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/country.md#name) プロパティと [**Alpha2Code**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/country.md#alpha2code) プロパティに国名と ISO alpha-2 コードを指定します。その国で発行される請求書に使用されている言語は、[**AddRecognitionLanguage**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/country-addrecognitionlanguage.md) メソッドで追加します。その言語が [**InvoiceLanguages**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/invoicelanguages.md) コレクションにまだ存在しない場合は、このコレクションにも追加され、キーワードリストなどの請求書関連のプロパティを編集できるようになります。また、国が自動的に検出されなかった場合に備えて、事前定義された国の一覧からデフォルトの国を設定することもできます。それには、[**InvoiceSettings**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/invoicesettings.md) オブジェクトの [**DefaultCountry**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/invoicesettings.md#defaultcountry) プロパティを使用します。

> [accordion] C# コード
>
> ```csharp theme={null}
> documentDefinitions.CheckOut(documentDefinition);
> IInvoiceSettings invoiceSettings = documentDefinition.InvoiceSettings;
> ICountry country = invoicesSettings.Countries.AddNew();
> country.Alpha2Code = "MC";
> country.Name = "SomeCountry";
> country.AddRecognitionLanguage("German");
>
> documentDefinitions.CheckIn(documentDefinition);
> ```

#### キーワード

請求書の認識用に事前定義されているすべての国と言語には、特定のフィールドに対応するキーワードが含まれています。画像上でキーワードが認識されると、処理エンジンはその付近で対応するフィールドを検索します。お使いの請求書に記載されているキーワードがリストにない場合は、フィールド抽出の品質を高めるために、それらのキーワードを追加することをお勧めします。国固有のキーワードは [**Country**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/country.md) オブジェクトの各種プロパティで指定できます。一方、言語固有のキーワードには [**InvoiceLanguage**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/invoicelanguage.md) オブジェクトの [**KeywordLists**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/invoicelanguage.md#keywordlists) プロパティを介してアクセスします。キーワードリストのセットは利用可能な請求書のフィールドと関連付けられているため、あらかじめ定義されています。

> [accordion] C# コード
>
> ```csharp theme={null}
> documentDefinitions.CheckOut(documentDefinition);
>
> country.BankAccountKeywords = "Keyword_1|Keyword_2|Keyword_3";
> IInvoiceLanguage someLanguage = invoicesSettings.InvoiceLanguages[0];
> IKeywordLists keywordLists = someLanguage.KeywordLists;
> foreach (IKeywordList someKeywordList in keywordLists)
> {
>     if (someKeywordList.Name == "InvoiceNumberHighConfidenceLabels")
>     {
>         someKeywordList.Keywords = someKeywordList.Keywords + "|Invoice#";
>     }
> }
>
> documentDefinitions.CheckIn(documentDefinition);
> ```

#### 追加フィールド

請求書で認識できる追加フィールドの中には、デフォルトでは有効になっていないものがあります (例: 配送日) 。これらは [**InvoiceFeatures**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/invoicefeatures.md) オブジェクトを使用して管理できます。

> [accordion] C# コード
>
> ```csharp theme={null}
> documentDefinitions.CheckOut(documentDefinition);
>
> IInvoiceFeatures invoiceFeatures = invoicesSettings.InvoiceFeatures;
> IInvoiceFeature someFeature = invoiceFeatures[0];
> bool isEnabled = someFeature.IsEnabled;
> // 例: 明細項目の抽出
> string featureName = someFeature.Name;
>
> documentDefinitions.CheckIn(documentDefinition);
> ```

#### 明細

請求書の主要なフィールド (番号、日付、ベンダー、事業部門など) に加えて、繰り返し出現するフィールド、つまり複数のインスタンスを持つフィールドからもデータを抽出する必要がある場合があります。これらのフィールドは請求書内に複数回出現します。ABBYY FlexiCapture SDK では、請求書の繰り返しフィールドのグループは*明細*として表されます。明細の認識データにアクセスするには、次の手順を実行します。

1. 対応する [**Field**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/field.md) オブジェクトの [**Instances**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/field.md#instances) プロパティを使用して、フィールドのインスタンスにアクセスします。
2. **Field** オブジェクトの [**Children**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/field.md#children) プロパティを使用して、インスタンスの子フィールドを取得します。
3. **Field** オブジェクトの [**Value**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/field.md#value) プロパティを使用して、指定したフィールドの値を取得します。

   > [!NOTE]
   >
   > 明細を処理するには、[**InvoiceFeatures**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/invoicefeatures.md) オブジェクトを使用して明細項目の抽出機能を有効にする必要があります。

明細の検証時に、多数の明細がまとめて誤って抽出された場合は、[**Document**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/document.md) オブジェクトの [**ContinueLineItems**](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/document-continuelineitems.md) メソッドを使用します。まず、オペレーターに最初の明細項目を手動でマークアップしてもらいます。次にこのメソッドを呼び出すと、同じパターンを使用して残りの明細が検出されます。なお、この操作はベンダーまたは購入者の国が検出されている場合にのみ実行できます。

## 関連項目

[フィールド抽出のトレーニング用オブジェクト](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/training-overview.md)

[Invoice Processing のオブジェクト](https://docs.abbyy.com/ja/flexi-capture/sdk/api-reference/invoiceprocessing-overview.md)
