

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

# 主題建模的非同步分析
<a name="get-started-topics"></a>

 若要判斷文件集中的主題，請使用 [StartTopicsDetectionJob](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_StartTopicsDetectionJob.html) 啟動非同步任務。您可以監控以英文或西班牙文撰寫之文件中的主題。

**Topics**
+ [開始之前](#topics-before)
+ [使用 AWS Command Line Interface](#topics-cli)
+ [使用適用於 Python 的 SDK 或 適用於 .NET 的 SDK](#topic-java)

## 開始之前
<a name="topics-before"></a>

開始之前，請確定您已：
+ **輸入和輸出儲存貯**體 - 識別您要用於輸入和輸出的 Amazon S3 儲存貯體。儲存貯體必須與您呼叫的 API 位於相同的區域。
+ **IAM 服務角色** - 您必須擁有具有存取輸入和輸出儲存貯體許可的 IAM 服務角色。如需詳細資訊，請參閱[非同步操作所需的角色型許可](security_iam_id-based-policy-examples.md#auth-role-permissions)。

## 使用 AWS Command Line Interface
<a name="topics-cli"></a>

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

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

```
aws comprehend start-topics-detection-job \
                --number-of-topics {{topics to return}} \
                --job-name "{{job name}}" \
                --region {{region}} \
                --cli-input-json file://{{path to JSON input file}}
```

針對 `cli-input-json` 參數，您提供包含請求資料的 JSON 檔案路徑，如下列範例所示。

```
{
    "InputDataConfig": {
        "S3Uri": "s3://{{input bucket}}/{{input path}}",
        "InputFormat": "ONE_DOC_PER_FILE"
    },
    "OutputDataConfig": {
        "S3Uri": "s3://{{output bucket}}/{{output path}}"
    },
    "DataAccessRoleArn": "arn:aws:iam::{{account ID}}:role/{{data access role}}"
}
```

如果啟動主題偵測任務的請求成功，您將會收到下列回應：

```
{
    "JobStatus": "SUBMITTED",
    "JobId": "{{job ID}}"
}
```

使用 [ListTopicsDetectionJobs](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_ListTopicsDetectionJobs.html) 操作來查看您已提交的主題偵測任務清單。此清單包含您使用的輸入和輸出位置，以及每個偵測任務狀態的相關資訊。此範例格式適用於 Unix、Linux 和 macOS。用於 Windows 時，請以插入號 (^) 取代每一行結尾處的 Unix 接續字元斜線 (\\)。

```
aws comprehend list-topics-detection-jobs \-- {{region}}
```

您會得到類似以下內容的 JSON 來回應：

```
{
    "TopicsDetectionJobPropertiesList": [
        {
            "InputDataConfig": {
                "S3Uri": "s3://{{input bucket}}/{{input path}}",
                "InputFormat": "ONE_DOC_PER_LINE"
            },
            "NumberOfTopics": {{topics to return}},
            "JobId": "{{job ID}}",
            "JobStatus": "COMPLETED",
            "JobName": "{{job name}}",
            "SubmitTime": {{timestamp}},
            "OutputDataConfig": {
                "S3Uri": "s3://{{output bucket}}/{{output path}}"
            },
            "EndTime": {{timestamp}}
        },
        {
            "InputDataConfig": {
                "S3Uri": "s3://{{input bucket}}/{{input path}}",
                "InputFormat": "ONE_DOC_PER_LINE"
            },
            "NumberOfTopics": {{topics to return}},
            "JobId": "{{job ID}}",
            "JobStatus": "RUNNING",
            "JobName": "{{job name}}",
            "SubmitTime": {{timestamp}},
            "OutputDataConfig": {
                "S3Uri": "s3://{{output bucket}}/{{output path}}"
            }
        }
    ]
}
```

您可以使用 [DescribeTopicsDetectionJob](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_DescribeTopicsDetectionJob.html) 操作來取得現有任務的狀態。此範例格式適用於 Unix、Linux 和 macOS。用於 Windows 時，請以插入號 (^) 取代每一行結尾處的 Unix 接續字元斜線 (\\)。

```
aws comprehend describe-topics-detection-job --job-id {{job ID}} 
```

您將會收到下列 JSON 來回應：

```
{
    "TopicsDetectionJobProperties": {
        "InputDataConfig": {
            "S3Uri": "s3://{{input bucket}}/{{input path}}",
            "InputFormat": "ONE_DOC_PER_LINE"
        },
        "NumberOfTopics": {{topics to return}},
        "JobId": "{{job ID}}",
        "JobStatus": "COMPLETED",
        "JobName": "{{job name}}",
        "SubmitTime": {{timestamp}},
        "OutputDataConfig": {
            "S3Uri": "s3://{{output bucket}}/{{ouput path}}"
        },
        "EndTime": {{timestamp}}
    }
}
```

## 使用適用於 Python 的 SDK 或 適用於 .NET 的 SDK
<a name="topic-java"></a>

如需如何啟動主題建模任務的 SDK 範例，請參閱 [`StartTopicsDetectionJob` 搭配 AWS SDK 或 CLI 使用](example_comprehend_StartTopicsDetectionJob_section.md)。