文档

事件抽取(英文)

更新时间:

说明

本服务由NLP自学习平台提供,直接调用API即可使用。

事件抽取(英文)服务适用于对英文新闻事件抽取,包含如下事件类别:

‘Personnel.Nominate’

‘Contact.Phone-Write’

‘Business.Declare-Bankruptcy’

‘Justice.Release-Parole’

‘Justice.Extradite’

‘Personnel.Start-Position’

‘Justice.Fine’

‘Transaction.Transfer-Money’

‘Personnel.End-Position’

‘Justice.Acquit’

‘Life.Injure’

‘Conflict.Attack’

‘Justice.Arrest-Jail’

‘Justice.Pardon’

‘Justice.Charge-Indict’

‘Conflict.Demonstrate’

‘Contact.Meet’

‘Business.End-Org’

‘Life.Be-Born’

‘Personnel.Elect’

‘Justice.Trial-Hearing’

‘Life.Divorce’

‘Justice.Sue’

‘Justice.Appeal’

‘Business.Merge-Org’

‘Life.Die’

‘Business.Start-Org’

‘Justice.Convict’

‘Movement.Transport’

‘Life.Marry’

‘Justice.Sentence’

‘Justice.Execute’

‘Transaction.Transfer-Ownership’

服务开通与资源包购买

使用前,请确认是否已经开通服务,开通后可购买资源包。

服务调用与调试

模型调用文档参考:模型调用

SDK示例文档参考:SDK示例

调试

您可以在OpenAPI开发者门户中直接运行该接口,免去您计算签名的困扰。运行成功后,OpenAPI开发者门户可以自动生成SDK代码示例。

通过环境变量配置访问凭证(AKSK)

  1. 说明:

    1. 阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户。

    2. 强烈建议不要把AccessKey和AccessKeySecret保存到代码里,会存在密钥泄漏风险,在此提供通过配置环境变量的方式来保存和访问aksk

  2. Linux和macOS系统配置方法

    export NLP_AK_ENV=<access_key_id>
    export NLP_SK_ENV=<access_key_secret>

    其中<access_key_id>替换为已准备好的AccessKey ID,<access_key_secret>替换为AccessKey Secret,AccessKey ID和AccessKey Secret的获取方式见步骤二:获取账号的AccessKey

  3. Windows系统配置方法

    1. 新建环境变量文件,添加环境变量NLP_AK_ENVNLP_SK_ENV,并写入已准备好的AccessKey ID和AccessKey Secret。

    2. 重启Windows系统。

Java代码示例

/**
 * 阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户。
 * 此处以把AccessKey和AccessKeySecret保存在环境变量为例说明。您也可以根据业务需要,保存到配置文件里。
 * 强烈建议不要把AccessKey和AccessKeySecret保存到代码里,会存在密钥泄漏风险
 */
String accessKeyId = System.getenv("NLP_AK_ENV");
String accessKeySecret = System.getenv("NLP_SK_ENV");
DefaultProfile defaultProfile = DefaultProfile.getProfile("cn-hangzhou",accessKeyId,accessKeySecret);
IAcsClient client = new DefaultAcsClient(defaultProfile);
Map<String, Object> map = new HashMap<>();
String text = "As part of the 11-billion-dollar sale of USA Interactive's film and television operations to the French media company in December 2001, USA Interactive received 2.5 billion dollars in preferred shares in Vivendi Universal Entertainment.";
map.put("text", text);
RunPreTrainServiceRequest request = new RunPreTrainServiceRequest();
request.setServiceName("NLP-Event-Extraction-En");
request.setPredictContent(JSON.toJSONString(map));
RunPreTrainServiceResponse response = client.getAcsResponse(request);
System.out.println(response.getPredictResult());

Python代码示例

# 安装依赖
pip install aliyun-python-sdk-core
pip install aliyun-python-sdk-nlp-automl
# -*- coding: utf8 -*-
import json
import os

from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdknlp_automl.request.v20191111 import RunPreTrainServiceRequest

/**
 * 阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户。
 * 此处以把AccessKey和AccessKeySecret保存在环境变量为例说明。您也可以根据业务需要,保存到配置文件里。
 * 强烈建议不要把AccessKey和AccessKeySecret保存到代码里,会存在密钥泄漏风险
 */
access_key_id = os.environ['NLP_AK_ENV']
access_key_secret = os.environ['NLP_SK_ENV']

# Initialize AcsClient instance
client = AcsClient(
  access_key_id,
  access_key_secret,
  "cn-hangzhou"
);
text = "As part of the 11-billion-dollar sale of USA Interactive's film and television operations to the French media company in December 2001, USA Interactive received 2.5 billion dollars in preferred shares in Vivendi Universal Entertainment."
content ={"text": text}
# Initialize a request and set parameters
request = RunPreTrainServiceRequest.RunPreTrainServiceRequest()
request.set_ServiceName('NLP-Event-Extraction-En')
request.set_PredictContent(json.dumps(content))
# Print response
response = client.do_action_with_exception(request)
resp_obj = json.loads(response)
predict_result = json.loads(resp_obj['PredictResult'])
print(predict_result['predictions'])

PredictContent内容示例

{
  "messages":  "As part of the 11-billion-dollar sale of USA Interactive's film and television operations to the French media company in December 2001, USA Interactive received 2.5 billion dollars in preferred shares in Vivendi Universal Entertainment."
}

PredictResult内容示例

{
  "predictions":"As part of the 11-billion-dollar <event type = Transaction.Transfer-Ownership>sale<event> of USA Interactive's film and television operations to the French media company in December 2001, USA Interactive <event type = Transaction.Transfer-Money>received<event> 2.5 billion dollars in preferred shares in Vivendi Universal Entertainment ."
}

入参说明

参数

说明

text

待预测文本

出参说明

参数

说明

predictions

原文本上标注事件

  • 本页导读 (0)
文档反馈