全部产品

情感分析(俄语)

更新时间:2020-09-30 11:00:37

情感分析(西班牙语)预测服务适用于针对电商场景的社交媒体(短文本),预测文本所表达的情感,分为正,中,负,三种情感。

Java代码示例

  1. DefaultProfile defaultProfile = DefaultProfile.getProfile("cn-hangzhou","your-access-id-key","your-access-id-secret");
  2. IAcsClient client = new DefaultAcsClient(defaultProfile);
  3. Map<String, Object> map = new HashMap<>();
  4. List<String> messages = ArrayList<>();
  5. messages.add("Игровая консоль BoyHom RS37 (Dendy 8-бит) - Распаковка");
  6. map.put("messages", messages);
  7. RunPreTrainServiceRequest request = new RunPreTrainServiceRequest();
  8. request.setServiceName("NLP-Ru-Sentiment-Analysis");
  9. request.setPredictContent(JSON.toJSONString(map));
  10. RunPreTrainServiceResponse response = client.getAcsResponse(request);
  11. System.out.println(response.getPredictResult());

Python代码示例

  1. # 安装依赖
  2. pip install aliyun-python-sdk-core
  3. pip install aliyun-python-sdk-nlp-automl
  1. # -*- coding: utf8 -*-
  2. import json
  3. from aliyunsdkcore.client import AcsClient
  4. from aliyunsdkcore.acs_exception.exceptions import ClientException
  5. from aliyunsdkcore.acs_exception.exceptions import ServerException
  6. from aliyunsdknlp_automl.request.v20191111 import RunPreTrainServiceRequest
  7. # Initialize AcsClient instance
  8. client = AcsClient(
  9. "<your-access-key-id>",
  10. "<your-access-key-secret>",
  11. "cn-hangzhou"
  12. );
  13. messages=["Игровая консоль BoyHom RS37 (Dendy 8-бит) - Распаковка"]
  14. content ={"messages": messages}
  15. # Initialize a request and set parameters
  16. request = RunPreTrainServiceRequest.RunPreTrainServiceRequest()
  17. request.set_ServiceName('NLP-Ru-Sentiment-Analysis')
  18. request.set_PredictContent(json.dumps(content))
  19. # Print response
  20. response = client.do_action_with_exception(request)
  21. resp_obj = json.loads(response)
  22. predict_result = json.loads(resp_obj['PredictResult'])
  23. print(predict_result['predictions'])

PredictContent内容示例

  1. {
  2. "messages": ["Игровая консоль BoyHom RS37 (Dendy 8-бит) - Распаковка"],
  3. }

PredictResult内容示例

  1. {
  2. "predictions":["neutral"]
  3. }

入参说明

参数 说明
messages 待预测文本的列表

出参说明

参数 说明
predictions 文本对应的情感值列表