

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 主题建模的异步分析
<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 的软件开发工具包或 适用于 .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，请将每行末尾的反斜杠 (\$1) 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，请将每行末尾的反斜杠 (\$1) 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，请将每行末尾的反斜杠 (\$1) 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 的软件开发工具包或 适用于 .NET 的 SDK
<a name="topic-java"></a>

有关如何启动主题建模任务的 SDK 示例，请参阅 [`StartTopicsDetectionJob`与 AWS SDK 或 CLI 配合使用](example_comprehend_StartTopicsDetectionJob_section.md)。