

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# API を使用したリアルタイムの分析
<a name="using-api-sync"></a>

次の例は、 および AWS CLI SDKs for .NET、Java、Python を使用した AWS リアルタイム分析に Amazon Comprehend API を使用する方法を示しています。これらの例を使用して、Amazon Comprehend 非同期オペレーションについて、またご自身のアプリケーションの構成要素として説明します。

このセクションの .NET 例では [AWS SDK for .NET](https://docs.aws.amazon.com/sdk-for-net/latest/developer-guide/welcome.html) を使用します。を使用して[AWS Toolkit for Visual Studio](https://docs.aws.amazon.com/AWSToolkitVS/latest/UserGuide/welcome.html)、.NET を使用して AWS アプリケーションを開発できます。これには、アプリケーションのデプロイとサービスの管理に役立つテンプレートと AWS Explorer が含まれています。.NET 開発者の視点については AWS、[AWS .NET 開発者向けガイド](https://docs.aws.amazon.com/sdk-for-net/latest/developer-guide/welcome.html)を参照してください。

**Topics**
+ [主要言語の検出](#get-started-api-dominant-language)
+ [名前付きエンティティを検出する](#get-started-api-entities)
+ [キーフレーズの検出](#get-started-api-key-phrases)
+ [感情の判断](#get-started-api-sentiment)
+ [ターゲット感情のリアルタイム分析](#get-started-api-targeted-sentiment)
+ [構文の検出](#get-started-api-syntax)
+ [リアルタイムバッチ API](#get-started-batch)

## 主要言語の検出
<a name="get-started-api-dominant-language"></a>

テキストで使用されている主要言語を判別するには、[「DetectDominantLanguage」](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_DetectDominantLanguage.html) オペレーションを使用します。バッチ内の最大 25 件の文書から主要言語を検出するには、[「BatchDetectDominantLanguage」](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_BatchDetectDominantLanguage.html) オペレーションを使用します。詳細については、「[リアルタイムバッチ API](#get-started-batch)」を参照してください。

**Topics**
+ [の使用 AWS Command Line Interface](#get-started-api-dominant-language-cli)
+ [AWS SDK for Java、 SDK for Python、または の使用 SDK for .NET](#get-started-api-dominant-language-java)

### の使用 AWS Command Line Interface
<a name="get-started-api-dominant-language-cli"></a>

次の例は、 AWS CLIで `DetectDominantLanguage` オペレーションを使用する方法を示しています。

例は、Unix、Linux、および macOS 用にフォーマットされています。Windows の場合は、各行末のバックスラッシュ (\$1) Unix 連結文字をキャレット (^) に置き換えてください。

```
aws comprehend detect-dominant-language \
    --region region \
    --text "It is raining today in Seattle."
```

Amazon Comprehend は次のように応答します。

```
{
    "Languages": [
        {
            "LanguageCode": "en",
            "Score": 0.9793661236763
        }
    ]
}
```

### AWS SDK for Java、 SDK for Python、または の使用 SDK for .NET
<a name="get-started-api-dominant-language-java"></a>

主要言語を判別する方法を示す SDK の例については、「[AWS SDK または CLI `DetectDominantLanguage`で を使用する](example_comprehend_DetectDominantLanguage_section.md)」を参照してください。

## 名前付きエンティティを検出する
<a name="get-started-api-entities"></a>

ドキュメント内の名前付きエンティティを判別するには、[「DetectEntities」](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_DetectEntities.html) オペレーションを使用します。バッチ内の最大 25 件の文書からエンティティを検出するには、[「BatchDetectDominantLanguage」](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_BatchDetectEntities.html) オペレーションを使用します。詳細については、「[リアルタイムバッチ API](#get-started-batch)」を参照してください。

**Topics**
+ [の使用 AWS Command Line Interface](#get-started-api-entities-cli)
+ [AWS SDK for Java、 SDK for Python、または の使用 SDK for .NET](#get-started-api-entities-java)

### の使用 AWS Command Line Interface
<a name="get-started-api-entities-cli"></a>

次の例は、 AWS CLIを使用した `DetectEntities` オペレーションを使用する方法を示しています。入力テキストの言語を指定する必要があります。

例は、Unix、Linux、および macOS 用にフォーマットされています。Windows の場合は、各行末のバックスラッシュ (\$1) Unix 連結文字をキャレット (^) に置き換えてください。

```
aws comprehend detect-entities \
    --region region \
    --language-code "en" \
    --text "It is raining today in Seattle."
```

Amazon Comprehend は次のように応答します。

```
{
    "Entities": [
        {
            "Text": "today",
            "Score": 0.97,
            "Type": "DATE",
            "BeginOffset": 14,
            "EndOffset": 19
        },
        {
            "Text": "Seattle",
            "Score": 0.95,
            "Type": "LOCATION",
            "BeginOffset": 23,
            "EndOffset": 30
        }
    ],
    "LanguageCode": "en"
}
```

### AWS SDK for Java、 SDK for Python、または の使用 SDK for .NET
<a name="get-started-api-entities-java"></a>

主要言語を判別する方法を示す SDK の例については、「[AWS SDK または CLI `DetectEntities`で を使用する](example_comprehend_DetectEntities_section.md)」を参照してください。

## キーフレーズの検出
<a name="get-started-api-key-phrases"></a>

テキストで使用されている主要な名詞フレーズを判別するには、[「DetectKeyPhrases」](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_DetectKeyPhrases.html) オペレーションを使用します。バッチ内の最大 25 件の文書から主要な名詞フレーズを検出するには、[「BatchDetectDominantLanguage」](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_BatchDetectKeyPhrases.html) オペレーションを使用します。詳細については、「[リアルタイムバッチ API](#get-started-batch)」を参照してください。

**Topics**
+ [の使用 AWS Command Line Interface](#get-started-api-key-phrases-cli)
+ [AWS SDK for Java、 SDK for Python、または の使用 SDK for .NET](#get-started-api-key-phrases-java)

### の使用 AWS Command Line Interface
<a name="get-started-api-key-phrases-cli"></a>

次の例は、 AWS CLIで `DetectKeyPhrases` オペレーションを使用する方法を示しています。入力テキストの言語を指定する必要があります。

例は、Unix、Linux、および macOS 用にフォーマットされています。Windows の場合は、各行末のバックスラッシュ (\$1) Unix 連結文字をキャレット (^) に置き換えてください。

```
aws comprehend detect-key-phrases \
    --region region \
    --language-code "en" \
    --text "It is raining today in Seattle."
```

Amazon Comprehend は次のように応答します。

```
{
    "LanguageCode": "en",
    "KeyPhrases": [
        {
            "Text": "today",
            "Score": 0.89,
            "BeginOffset": 14,
            "EndOffset": 19
        },
        {
            "Text": "Seattle",
            "Score": 0.91,
            "BeginOffset": 23,
            "EndOffset": 30
        }
    ]
}
```

### AWS SDK for Java、 SDK for Python、または の使用 SDK for .NET
<a name="get-started-api-key-phrases-java"></a>

キーフレーズを検出する SDK の例については、「[AWS SDK または CLI `DetectKeyPhrases`で を使用する](example_comprehend_DetectKeyPhrases_section.md)」を参照してください。

## 感情の判断
<a name="get-started-api-sentiment"></a>

Amazon Comprehend には、感情を分析するための次の API オペレーションが用意されています。
+ [「DetectSentiment」](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_DetectSentiment.html) — ドキュメント全体の感情を判断します。
+  [「BatchDetectSentiment」](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_BatchDetectSentiment.html) — 最大 25 件のドキュメントをまとめて全体の感情を測定します。詳細については、[リアルタイムバッチ API](#get-started-batch)を参照してください。
+  [StartSentimentDetectionJob](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_StartSentimentDetectionJob.html) – ドキュメントのコレクション用に非同期の感情検出ジョブを開始します。
+  [ListSentimentDetectionJobs](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_ListSentimentDetectionJobs.html) — 提出した感情検出ジョブのリストを返します。
+  [DescribeSentimentDetectionJob](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_DescribeSentimentDetectionJob.html) — 指定された感情検出ジョブに関連するプロパティ (ステータスを含む) を取得します。
+  [StopTargetdSentimentDetectionJob](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_StopSentimentDetectionJob.html) — 指定された進行中のターゲット感情ジョブを停止します。

**Topics**
+ [の使用 AWS Command Line Interface](#get-started-api-sentiment-cli)
+ [AWS SDK for Java、 SDK for Python、または の使用 SDK for .NET](#get-started-api-sentiment-java)

### の使用 AWS Command Line Interface
<a name="get-started-api-sentiment-cli"></a>

次の例は、 AWS CLIで `DetectSentiment` オペレーションを使用する方法を示しています。この例では、入力テキストの言語を指定します。

例は、Unix、Linux、および macOS 用にフォーマットされています。Windows の場合は、各行末のバックスラッシュ (\$1) Unix 連結文字をキャレット (^) に置き換えてください。

```
aws comprehend detect-sentiment \
    --region region \
    --language-code "en" \
    --text "It is raining today in Seattle."
```

 Amazon Comprehend は次のように応答します。

```
{
    "SentimentScore": {
        "Mixed": 0.014585512690246105,
        "Positive": 0.31592071056365967,
        "Neutral": 0.5985543131828308,
        "Negative": 0.07093945890665054
    },
    "Sentiment": "NEUTRAL",
    "LanguageCode": "en"
}
```

### AWS SDK for Java、 SDK for Python、または の使用 SDK for .NET
<a name="get-started-api-sentiment-java"></a>

入力テキストの感情を決定する SDK の例については、「[AWS SDK または CLI `DetectSentiment`で を使用する](example_comprehend_DetectSentiment_section.md)」を参照してください。

## ターゲット感情のリアルタイム分析
<a name="get-started-api-targeted-sentiment"></a>

Amazon Comprehend には、ターゲット感情のリアルタイム分析のための次の API オペレーションが用意されています。
+ [DetectTargetedSentiment](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_DetectTargetedSentiment.html) — ドキュメントに記載されているエンティティの感情を分析します。
+  [BatchDetectTargetedSentiment](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_BatchDetectTargetedSentiment.html) — 最大 25 件の文書のターゲット感情を一括して分析します。詳細については、[リアルタイムバッチ API](#get-started-batch)を参照してください。

分析しているテキストにターゲット感情「[エンティティタイプ](how-targeted-sentiment.md#how-targeted-sentiment-entities)」が含まれていない場合、API は空のエンティティ配列を返します。

### の使用 AWS Command Line Interface
<a name="get-started-api-targeted-sentiment-cli"></a>

次の例は、 AWS CLIで `DetectTargetedSentiment` オペレーションを使用する方法を示しています。この例では、入力テキストの言語を指定します。

例は、Unix、Linux、および macOS 用にフォーマットされています。Windows の場合は、各行末のバックスラッシュ (\$1) Unix 連結文字をキャレット (^) に置き換えてください。

```
aws comprehend detect-targeted-sentiment \
    --region region \
    --language-code "en" \
    --text "The burger was cooked perfectly but it was cold. The service was OK."
```

 Amazon Comprehend は次のように応答します。

```
{
"Entities": [
    {
      "DescriptiveMentionIndex": [
        0
      ],
      "Mentions": [
        {
          "BeginOffset": 4,
          "EndOffset": 10,
          "Score": 1,
          "GroupScore": 1,
          "Text": "burger",
          "Type": "OTHER",
          "MentionSentiment": {
            "Sentiment": "POSITIVE",
            "SentimentScore": {
              "Mixed": 0.001515,
              "Negative": 0.000822,
              "Neutral": 0.000243,
              "Positive": 0.99742
            }
          }
        },
        {
          "BeginOffset": 36,
          "EndOffset": 38,
          "Score": 0.999843,
          "GroupScore": 0.999661,
          "Text": "it",
          "Type": "OTHER",
          "MentionSentiment": {
            "Sentiment": "NEGATIVE",
            "SentimentScore": {
              "Mixed": 0,
              "Negative": 0.999996,
              "Neutral": 0.000004,
              "Positive": 0
            }
          }
        }
      ]
    },
    {
      "DescriptiveMentionIndex": [
        0
      ],
      "Mentions": [
        {
          "BeginOffset": 53,
          "EndOffset": 60,
          "Score": 1,
          "GroupScore": 1,
          "Text": "service",
          "Type": "ATTRIBUTE",
          "MentionSentiment": {
            "Sentiment": "NEUTRAL",
            "SentimentScore": {
              "Mixed": 0.000033,
              "Negative": 0.000089,
              "Neutral": 0.993325,
              "Positive": 0.006553
            }
          }
        }
      ]
    }
  ]
}
```

## 構文の検出
<a name="get-started-api-syntax"></a>

テキストを解析して個々の単語を抽出し、各単語の品詞を決定するには、[detectSyntax](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_DetectSyntax.html) オペレーションを使用します。バッチ内の最大 25 件の文書から構文をパースするには、[BatchDetectDominantLanguage](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_BatchDetectSyntax.html) オペレーションを使用します。詳細については、「[リアルタイムバッチ API](#get-started-batch)」を参照してください。

**Topics**
+ [の使用 AWS Command Line Interface。](#get-started-api-syntax-cli)
+ [AWS SDK for Java、 SDK for Python、または の使用 SDK for .NET](#get-started-api-syntax-java)

### の使用 AWS Command Line Interface。
<a name="get-started-api-syntax-cli"></a>

次の例は、 AWS CLIで `DetectSyntax` オペレーションを使用する方法を示しています。この例では、入力テキストの言語を指定します。

例は、Unix、Linux、および macOS 用にフォーマットされています。Windows の場合は、各行末のバックスラッシュ (\$1) Unix 連結文字をキャレット (^) に置き換えてください。

```
aws comprehend detect-syntax \
   --region region \
   --language-code "en" \
   --text "It is raining today in Seattle."
```

Amazon Comprehend は次のように応答します。

```
{
    "SyntaxTokens": [
        {
            "Text": "It",
            "EndOffset": 2,
            "BeginOffset": 0,
            "PartOfSpeech": {
                "Tag": "PRON",
                "Score": 0.8389829397201538
            },
            "TokenId": 1
        },
        {
            "Text": "is",
            "EndOffset": 5,
            "BeginOffset": 3,
            "PartOfSpeech": {
                "Tag": "AUX",
                "Score": 0.9189288020133972
            },
            "TokenId": 2
        },
        {
            "Text": "raining",
            "EndOffset": 13,
            "BeginOffset": 6,
            "PartOfSpeech": {
                "Tag": "VERB",
                "Score": 0.9977611303329468
            },
            "TokenId": 3
        },
        {
            "Text": "today",
            "EndOffset": 19,
            "BeginOffset": 14,
            "PartOfSpeech": {
                "Tag": "NOUN",
                "Score": 0.9993606209754944
            },
            "TokenId": 4
        },
        {
            "Text": "in",
            "EndOffset": 22,
            "BeginOffset": 20,
            "PartOfSpeech": {
                "Tag": "ADP",
                "Score": 0.9999061822891235
            },
            "TokenId": 5
        },
        {
            "Text": "Seattle",
            "EndOffset": 30,
            "BeginOffset": 23,
            "PartOfSpeech": {
                "Tag": "PROPN",
                "Score": 0.9940338730812073
            },
            "TokenId": 6
        },
        {
            "Text": ".",
            "EndOffset": 31,
            "BeginOffset": 30,
            "PartOfSpeech": {
                "Tag": "PUNCT",
                "Score": 0.9999997615814209
            },
            "TokenId": 7
        }
    ]
}
```

### AWS SDK for Java、 SDK for Python、または の使用 SDK for .NET
<a name="get-started-api-syntax-java"></a>

入力テキストの構文を検出する SDK の例については、「[AWS SDK または CLI `DetectSyntax`で を使用する](example_comprehend_DetectSyntax_section.md)」 を参照してください。

## リアルタイムバッチ API
<a name="get-started-batch"></a>

Amazon Comprehend のリアルタイムバッチオペレーションを使用すると、最大 25 件のドキュメントのバッチを送信できます。バッチオペレーションを呼び出すことは、リクエスト内のドキュメントごとに単一ドキュメント API を呼び出すことと同じです。バッチ API を使用すると、アプリケーションのパフォーマンスが向上します。詳細については、「[複数ドキュメントの同期処理](concepts-processing-modes.md#how-batch)」を参照してください。

**Topics**
+ [を使用したバッチ処理 AWS CLI](#batch-cli)
+ [を使用したバッチ処理 AWS SDK for .NET](#batch-csharp)

### を使用したバッチ処理 AWS CLI
<a name="batch-cli"></a>

以下の例では、 AWS Command Line Interfaceでバッチ API オペレーションを使用する方法を示します。`BatchDetectDominantLanguage` 以外のすべての操作では、 `process.json` という名前の次のJSONファイルがインプットとして使用されます。その操作に `LanguageCode` エンティティは含まれません。

JSON ファイル (`"$$$$$$$$"`) の 3 番目のドキュメントは、バッチ処理中にエラーの原因となります。このドキュメントは、オペレーションのレスポンスに [BatchItemError](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_BatchItemError.html) が含まれるようになっています。

```
{
   "LanguageCode": "en",
   "TextList": [
      "I have been living in Seattle for almost 4 years",
      "It is raining today in Seattle",
      "$$$$$$$$"
   ]
}
```

例は、Unix、Linux、macOS 用にフォーマットされています。Windows の場合は、各行末のバックスラッシュ (\$1) Unix 連結文字をキャレット (^) に置き換えてください。

**Topics**
+ [バッチ (AWS CLI) を使用して主要言語を検出します。](#batch-dominant-language)
+ [バッチ (AWS CLI) を使用してエンティティを検出します。](#batch-entities)
+ [バッチ (AWS CLI) を使用してキーフレーズを検出します。](#batch-key-phrase)
+ [バッチ (AWS CLI) を使用して感情を検出します。](#batch-sentiment)

#### バッチ (AWS CLI) を使用して主要言語を検出します。
<a name="batch-dominant-language"></a>

[BatchDetectDominantLanguage](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_BatchDetectDominantLanguage.html) オペレーションは、バッチに含まれる各ドキュメントの主要言語を決定します。Amazon Comprehend が検出できる言語のリストについては、「[主要言語](how-languages.md)」を参照してください。次の AWS CLI コマンドは、 `BatchDetectDominantLanguage`オペレーションを呼び出します。

```
aws comprehend batch-detect-dominant-language \
    --endpoint endpoint \
    --region region \
    --cli-input-json file://path to input file/process.json
```

`BatchDetectDominantLanguage` オペレーションからのレスポンスは次のとおりです。

```
{
    "ResultList": [
        {
          "Index": 0,
          "Languages":[
            {
              "LanguageCode":"en",
              "Score": 0.99
            }
          ]
        },
        {
          "Index": 1
          "Languages":[
            {
              "LanguageCode":"en",
              "Score": 0.82
            }
          ]
        }
    ],
    "ErrorList": [
      {
        "Index": 2,
        "ErrorCode": "InternalServerException",
        "ErrorMessage": "Unexpected Server Error. Please try again."
      }
    ]
}
```

#### バッチ (AWS CLI) を使用してエンティティを検出します。
<a name="batch-entities"></a>

[BatchDetectEntities](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_BatchDetectEntities.html) オペレーションを使用して、ドキュメントのバッチに含まれるエンティティを検索します。エンティティの詳細については、「[エンティティ](how-entities.md)」を参照してください。以下の AWS CLI コマンドは、`BatchDetectEntities` オペレーションを呼び出します。

```
aws comprehend batch-detect-entities \
    --endpoint endpoint \
    --region region \
    --cli-input-json file://path to input file/process.json
```

#### バッチ (AWS CLI) を使用してキーフレーズを検出します。
<a name="batch-key-phrase"></a>

[BatchDetectKeyPhrases](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_BatchDetectKeyPhrases.html)オペレーションは、ドキュメントのバッチに含まれる主要な名詞フレーズを返します。次の AWS CLI コマンドは、 `BatchDetectKeyNounPhrases`オペレーションを呼び出します。

```
aws comprehend batch-detect-key-phrases
    --endpoint endpoint
    --region region
    --cli-input-json file://path to input file/process.json
```

#### バッチ (AWS CLI) を使用して感情を検出します。
<a name="batch-sentiment"></a>

[BatchDetectSentiment](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_BatchDetectSentiment.html) オペレーションを使用して、ドキュメントのバッチの全体的な感情を検出します。次の AWS CLI コマンドは、 `BatchDetectSentiment`オペレーションを呼び出します。

```
aws comprehend batch-detect-sentiment \
    --endpoint endpoint \
    --region region \
    --cli-input-json file://path to input file/process.json
```

### を使用したバッチ処理 AWS SDK for .NET
<a name="batch-csharp"></a>

次のサンプルプログラムは、 SDK for .NETで [BatchDetectEntities](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_BatchDetectEntities.html) オペレーションを使用する方法を示しています。サーバーからのレスポンスには、正常に処理された各ドキュメントの [BatchDetectEntitiesItemResult](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_BatchDetectEntitiesItemResult.html) オブジェクトが含まれています。ドキュメントの処理中にエラーが発生した場合は、レスポンスのエラーリストにレコードが記録されます。この例では、エラーのある各ドキュメントを取得して再送信します。

このセクションの .NET 例では [AWS SDK for .NET](https://docs.aws.amazon.com/sdk-for-net/latest/developer-guide/welcome.html) を使用します。を使用して[AWS Toolkit for Visual Studio](https://docs.aws.amazon.com/AWSToolkitVS/latest/UserGuide/welcome.html)、.NET を使用して AWS アプリケーションを開発できます。これには、アプリケーションのデプロイとサービスの管理に役立つテンプレートと AWS Explorer が含まれています。.NET 開発者の視点については AWS、[AWS .NET 開発者向けガイド](https://docs.aws.amazon.com/sdk-for-net/latest/developer-guide/welcome.html)を参照してください。

```
using System;
using System.Collections.Generic;
using Amazon.Comprehend;
using Amazon.Comprehend.Model;

namespace Comprehend
{
    class Program
    {
        // Helper method for printing properties
        static private void PrintEntity(Entity entity)
        {
            Console.WriteLine("     Text: {0}, Type: {1}, Score: {2}, BeginOffset: {3} EndOffset: {4}",
                entity.Text, entity.Type, entity.Score, entity.BeginOffset, entity.EndOffset);
        }

        static void Main(string[] args)
        {
            AmazonComprehendClient comprehendClient = new AmazonComprehendClient(Amazon.RegionEndpoint.USWest2);

            List<String> textList = new List<String>()
            {
                { "I love Seattle" },
                { "Today is Sunday" },
                { "Tomorrow is Monday" },
                { "I love Seattle" }
            };

            // Call detectEntities API
            Console.WriteLine("Calling BatchDetectEntities");
            BatchDetectEntitiesRequest batchDetectEntitiesRequest = new BatchDetectEntitiesRequest()
            {
                TextList = textList,
                LanguageCode = "en"
            };
            BatchDetectEntitiesResponse batchDetectEntitiesResponse = comprehendClient.BatchDetectEntities(batchDetectEntitiesRequest);

            foreach (BatchDetectEntitiesItemResult item in batchDetectEntitiesResponse.ResultList)
            {
                Console.WriteLine("Entities in {0}:", textList[item.Index]);
                foreach (Entity entity in item.Entities)
                    PrintEntity(entity);
            }

            // check if we need to retry failed requests
            if (batchDetectEntitiesResponse.ErrorList.Count != 0)
            {
                Console.WriteLine("Retrying Failed Requests");
                List<String> textToRetry = new List<String>();
                foreach(BatchItemError errorItem in batchDetectEntitiesResponse.ErrorList)
                    textToRetry.Add(textList[errorItem.Index]);

                batchDetectEntitiesRequest = new BatchDetectEntitiesRequest()
                {
                    TextList = textToRetry,
                    LanguageCode = "en"
                };

                batchDetectEntitiesResponse = comprehendClient.BatchDetectEntities(batchDetectEntitiesRequest);

                foreach(BatchDetectEntitiesItemResult item in batchDetectEntitiesResponse.ResultList)
                {
                    Console.WriteLine("Entities in {0}:", textList[item.Index]);
                    foreach (Entity entity in item.Entities)
                        PrintEntity(entity);
                }
            }
            Console.WriteLine("End of DetectEntities");
        }
    }
}
```