

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 使用 API 進行即時分析
<a name="using-api-sync"></a>

下列範例示範如何使用 Amazon Comprehend API 進行即時分析、使用 AWS CLI以及適用於 .NET、Java 和 AWS Python SDKs。使用範例來了解 Amazon Comprehend 同步操作，並做為您自己應用程式的建置區塊。

本節中的 .NET 範例使用 [適用於 .NET 的 AWS SDK](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)
+ [即時批次 APIs](#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) 操作。如需詳細資訊，請參閱[即時批次 APIs](#get-started-batch)。

**Topics**
+ [使用 AWS Command Line Interface](#get-started-api-dominant-language-cli)
+ [使用 適用於 Java 的 AWS SDK、適用於 Python 的 SDK 或 適用於 .NET 的 SDK](#get-started-api-dominant-language-java)

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

下列範例示範搭配 使用 `DetectDominantLanguage`操作 AWS CLI。

此範例格式適用於 Unix、Linux 和 macOS。用於 Windows 時，請以插入號 (^) 取代每一行結尾處的 Unix 接續字元斜線 (\$1)。

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

Amazon Comprehend 會以下列方式回應：

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

### 使用 適用於 Java 的 AWS SDK、適用於 Python 的 SDK 或 適用於 .NET 的 SDK
<a name="get-started-api-dominant-language-java"></a>

如需如何判斷主要語言的 SDK 範例，請參閱 [`DetectDominantLanguage` 搭配 AWS SDK 或 CLI 使用](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 個文件中的實體，請使用 [BatchDetectEntities](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_BatchDetectEntities.html) 操作。如需詳細資訊，請參閱[即時批次 APIs](#get-started-batch)。

**Topics**
+ [使用 AWS Command Line Interface](#get-started-api-entities-cli)
+ [使用 適用於 Java 的 AWS SDK、適用於 Python 的 SDK 或 適用於 .NET 的 SDK](#get-started-api-entities-java)

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

下列範例示範如何使用 `DetectEntities`操作 AWS CLI。您必須指定輸入文字的語言。

此範例格式適用於 Unix、Linux 和 macOS。用於 Windows 時，請以插入號 (^) 取代每一行結尾處的 Unix 接續字元斜線 (\$1)。

```
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"
}
```

### 使用 適用於 Java 的 AWS SDK、適用於 Python 的 SDK 或 適用於 .NET 的 SDK
<a name="get-started-api-entities-java"></a>

如需如何判斷主要語言的 SDK 範例，請參閱 [`DetectEntities` 搭配 AWS SDK 或 CLI 使用](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 個文件中的金鑰名詞片語，請使用 [BatchDetectKeyPhrases](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_BatchDetectKeyPhrases.html) 操作。如需詳細資訊，請參閱[即時批次 APIs](#get-started-batch)。

**Topics**
+ [使用 AWS Command Line Interface](#get-started-api-key-phrases-cli)
+ [使用 適用於 Java 的 AWS SDK、適用於 Python 的 SDK 或 適用於 .NET 的 SDK](#get-started-api-key-phrases-java)

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

下列範例示範搭配 使用 `DetectKeyPhrases`操作 AWS CLI。您必須指定輸入文字的語言。

此範例格式適用於 Unix、Linux 和 macOS。用於 Windows 時，請以插入號 (^) 取代每一行結尾處的 Unix 接續字元斜線 (\$1)。

```
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
        }
    ]
}
```

### 使用 適用於 Java 的 AWS SDK、適用於 Python 的 SDK 或 適用於 .NET 的 SDK
<a name="get-started-api-key-phrases-java"></a>

如需偵測金鑰片語的 SDK 範例，請參閱 [`DetectKeyPhrases` 搭配 AWS SDK 或 CLI 使用](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 個文件的整體情緒。如需詳細資訊，請參閱[即時批次 APIs](#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) – 取得與指定情緒偵測任務相關聯的屬性 （包括狀態）。
+  [StopSentimentDetectionJob](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_StopSentimentDetectionJob.html) – 停止指定的進行中情緒任務。

**Topics**
+ [使用 AWS Command Line Interface](#get-started-api-sentiment-cli)
+ [使用 適用於 Java 的 AWS SDK、適用於 Python 的 SDK 或 適用於 .NET 的 SDK](#get-started-api-sentiment-java)

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

下列範例示範搭配 使用 `DetectSentiment`操作 AWS CLI。此範例指定輸入文字的語言。

此範例格式適用於 Unix、Linux 和 macOS。用於 Windows 時，請以插入號 (^) 取代每一行結尾處的 Unix 接續字元斜線 (\$1)。

```
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"
}
```

### 使用 適用於 Java 的 AWS SDK、適用於 Python 的 SDK 或 適用於 .NET 的 SDK
<a name="get-started-api-sentiment-java"></a>

如需決定輸入文字情緒的 SDK 範例，請參閱 [`DetectSentiment` 搭配 AWS SDK 或 CLI 使用](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 個文件的目標情緒。如需詳細資訊，請參閱[即時批次 APIs](#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>

下列範例示範搭配 使用 `DetectTargetedSentiment`操作 AWS CLI。此範例指定輸入文字的語言。

此範例格式適用於 Unix、Linux 和 macOS。用於 Windows 時，請以插入號 (^) 取代每一行結尾處的 Unix 接續字元斜線 (\$1)。

```
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 個文件的語法，請使用 [BatchDetectSyntax](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_BatchDetectSyntax.html) 操作。如需詳細資訊，請參閱[即時批次 APIs](#get-started-batch)。

**Topics**
+ [使用 AWS Command Line Interface。](#get-started-api-syntax-cli)
+ [使用 適用於 Java 的 AWS SDK、適用於 Python 的 SDK 或 適用於 .NET 的 SDK](#get-started-api-syntax-java)

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

下列範例示範搭配 使用 `DetectSyntax`操作 AWS CLI。此範例指定輸入文字的語言。

此範例格式適用於 Unix、Linux 和 macOS。用於 Windows 時，請以插入號 (^) 取代每一行結尾處的 Unix 接續字元斜線 (\$1)。

```
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
        }
    ]
}
```

### 使用 適用於 Java 的 AWS SDK、適用於 Python 的 SDK 或 適用於 .NET 的 SDK
<a name="get-started-api-syntax-java"></a>

如需偵測輸入文字語法的 SDK 範例，請參閱 [`DetectSyntax` 搭配 AWS SDK 或 CLI 使用](example_comprehend_DetectSyntax_section.md)。

## 即時批次 APIs
<a name="get-started-batch"></a>

若要傳送最多 25 個文件的批次，您可以使用 Amazon Comprehend 即時批次操作。呼叫批次操作與呼叫請求中每個文件APIs 相同。使用批次 APIs 可以為您的應用程式提供更好的效能。如需詳細資訊，請參閱[多個文件同步處理](concepts-processing-modes.md#how-batch)。

**Topics**
+ [使用 進行批次處理 AWS CLI](#batch-cli)
+ [使用 進行批次處理 適用於 .NET 的 AWS SDK](#batch-csharp)

### 使用 進行批次處理 AWS CLI
<a name="batch-cli"></a>

這些範例示範如何使用 批次 API 操作 AWS Command Line Interface。除了 之外的所有操作都`BatchDetectDominantLanguage`使用稱為 的下列 JSON 檔案`process.json`做為輸入。對於該操作，不包含`LanguageCode`實體。

JSON 檔案 (`"$$$$$$$$"`) 中的第三個文件會在批次處理期間造成錯誤。它包含在其中，以便操作在回應中包含 [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 時，請以插入號 (^) 取代每一行結尾處的 Unix 接續字元斜線 (\$1)。

**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
```

### 使用 進行批次處理 適用於 .NET 的 AWS SDK
<a name="batch-csharp"></a>

下列範例程式示範如何搭配 使用 [BatchDetectEntities](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_BatchDetectEntities.html) 操作 適用於 .NET 的 SDK。伺服器的回應包含每個已成功處理之文件的 [BatchDetectEntitiesItemResult](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_BatchDetectEntitiesItemResult.html) 物件。如果處理文件時發生錯誤，回應中的錯誤清單中會有一個記錄。此範例會取得每個文件並顯示錯誤並重新傳送。

本節中的 .NET 範例使用 [適用於 .NET 的 AWS SDK](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");
        }
    }
}
```