0

我是 Wit.ai 的新手,并且已经开始在我的代码中实现它。我正在考虑一种比硬编码更简单的方法来从给定的 wit.ai API 输出中提取所有置信度。

例如(API 输出):

{
  "_text": "I believe I am a human",
  "entities": {
    "statement": [
      {
        "confidence": 0.97691847787856,
        "value": "I",
        "type": "value"
      },
      {
        "confidence": 0.91728476663947,
        "value": "I",
        "type": "value"
      }
    ],
     "query": [
      {
        "confidence": 1,
        "value": "am",
        "type": "value"
      }
    ]
  },
  "msg_id": "0YKCUvDvHC2gyydiU"
}

先感谢您。

4

1 回答 1

0

你可以迭代entities得到confidence.

就像是 :

data = {
"_text": "I believe I am a human",
"entities": {
    "statement": [
    {
        "confidence": 0.97691847787856,
        "value": "I",
        "type": "value"
    },
    {
        "confidence": 0.91728476663947,
        "value": "I",
        "type": "value"
    }
    ],
    "query": [
    {
        "confidence": 1,
        "value": "am",
        "type": "value"
    }
    ]
},
"msg_id": "0YKCUvDvHC2gyydiU"
}
confidence = list()
for k , v in data['entities'].iteritems():
    for item in v:
        confidence.append( (item['value'], item['confidence']))

print confidence

这给了我们:

[('I', 0.97691847787856), ('I', 0.91728476663947), ('am', 1)]

希望这可以帮助

于 2018-08-17T05:31:10.063 回答