情感分析
京东万象 官方文档
针对中文文本内容,自动判断该文本的情感极性类别,并给出相应的置信度
基本说明:
接口地址:https://way.jd.com/JDAI/sentiment
返回格式:json
请求方式:get/post
请求示例:https://way.jd.com/JDAI/sentiment?appkey=key&body={ "type": 1, "text": "我的为什么是这样?" }
请求参数说明:
名称 类型 必填 说明
appkey string 必填 该平台密钥 扫码关注公众号
body string 必填 json字符串
返回参数说明:
名称 类型 说明
sentiment object 基于情感的观点
JSON返回示例:
{
	"code": "10000",
	"charge": false,
	"msg": "查询成功",
	"result": {
		"code": "10000",
		"charge": false,
		"msg": "查询成功",
		"result": {
			"status": 0,
			"request_id": "722de3199a524830b75953422a22dcf8",
			"message": "ok",
			"sentiment": [{
				"sentiment": "negative",
				"probability": 0.9997894167900085
			}, {
				"sentiment": "other",
				"probability": 0.00016664672875776887
			}, {
				"sentiment": "positive",
				"probability": 0.00004389955211081542
			}]
		}
	},
	"requestId": "63f2df1abb9e4715b130752bb801d9ff"
}
服务级错误码参照
错误码 说明
10000 查询成功
10001 错误的请求appkey
11010 商家接口调用异常,请稍后再试
11030 商家接口返回格式有误
10003 不存在相应的数据信息
10004 URL上appkey参数不能为空
10010 接口需要付费,请充值
10020 万象系统繁忙,请稍后再试
10030 调用万象网关失败, 请与万象联系
10040 超过每天限量,请明天继续
10050 用户已被禁用
10060 提供方设置调用权限,请联系提供方
10070 该数据只允许企业用户调用
10090 文件大小超限,请上传小于1M的文件
完整教学代码示例
<?php
/**
 * Created by PhpStorm.
 * User: FZS
 * Time: 2021/03/27 15:26
 */
class freeApi
{
    private $apiUrl;

    public function __construct()
    {
        $this->apiUrl = 'https://way.jd.com/JDAI/sentiment?appkey=key&body={ "type": 1, "text": "我的为什么是这样?" }';
    }

    /**
     * 获取结果
     * @return array
     */
    public function getResult()
    {
        return file_get_contents($this->apiUrl);
    }
}
package main

import (
	"fmt"
	"io/ioutil"
	"log"
	"net/http"
)

const (
	APIURL   = "https://way.jd.com/JDAI/sentiment?appkey=key&body={ "type": 1, "text": "我的为什么是这样?" }"
)

func main() {
	queryUrl := fmt.Sprintf("%s",APIURL)
	resp, err := http.Get(queryUrl)
	if err != nil {
		log.Println(err)
		return
	}

	defer resp.Body.Close()

	body, err := ioutil.ReadAll(resp.Body)

	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(string(body))
}