Event extraction (English)
This service is provided by the NLP Self-Learning Platform. You can use this service by calling the API directly.
The English event extraction service extracts events from English news. It supports the following event categories:
‘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’ |
Service activation and resource plan purchase
Before you start, ensure that the service is activated. You can purchase a resource plan after the service is activated.
Activate service: Activation link
Purchase resource plan: Purchase link
Service invocation and debugging
For more information about model invocation, see Model invocation.
For more information about SDK examples, see SDK examples.
Debug
Configure access credentials using environment variables
Notes:
The AccessKey of an Alibaba Cloud account grants permissions for all API operations, which poses a high security risk. We recommend that you create and use a Resource Access Management (RAM) user for API calls or routine O&M. To create a RAM user, log on to the RAM console.
Do not save your AccessKey ID and AccessKey secret in your code. This practice poses a security risk. Instead, use environment variables to store and access your AccessKey ID and AccessKey secret.
Configuration for Linux and macOS
export NLP_AK_ENV=<access_key_id> export NLP_SK_ENV=<access_key_secret>Replace <access_key_id> with your AccessKey ID and <access_key_secret> with your AccessKey secret. For more information about how to obtain an AccessKey ID and an AccessKey secret, see Step 2: Obtain an AccessKey.
Configuration method for Windows
Create an environment variable file. Add the
NLP_AK_ENVandNLP_SK_ENVenvironment variables, and then specify your AccessKey ID and AccessKey secret as their values.Restart Windows.
Java code example
/**
* An AccessKey of an Alibaba Cloud account has permissions for all APIs. This poses a high security risk.
* Create and use a Resource Access Management (RAM) user for API calls or routine O&M.
* Log on to the RAM console to create a RAM user.
* This example shows how to store the AccessKey ID and AccessKey secret in environment variables.
* You can also store them in a configuration file as needed.
* Do not save your AccessKey ID and AccessKey secret in your code to prevent security risks.
*/
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 code example
# Install dependencies
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
# An AccessKey of an Alibaba Cloud account has permissions for all APIs. This poses a high security risk.
# Create and use a Resource Access Management (RAM) user for API calls or routine O&M.
# Log on to the RAM console to create a RAM user.
# This example shows how to store the AccessKey ID and AccessKey secret in environment variables.
# You can also store them in a configuration file as needed.
# Do not save your AccessKey ID and AccessKey secret in your code to prevent security risks.
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 example
{
"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."
}PredictResult example
{
"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 ."
}Request parameters
Parameter | Description |
text | The text for prediction. |
Response parameters
Parameter | Description |
predictions | The original text with annotated events. |