我一直在玩谷歌的实体分析器,它看起来真的很棒!
但我一直在反对这一点 - 我试图复制下面的图片(见google's natural language api page)
这是我从请求中获取的实体数据的格式。
数据没有顺序,只有事件发生 - 所以循环遍历每个单词,并检查整数似乎真的很慢,并且因为每个单词的多个 - 它可能会有点复杂
[
{
"mentions": [
{
"text": { "content": "group", "beginOffset": -1 },
"type": "COMMON",
"sentiment": { "magnitude": 0, "score": 0 }
},
{
"text": { "content": "group", "beginOffset": -1 },
"type": "COMMON",
"sentiment": { "magnitude": 0, "score": 0 }
},
{
"text": { "content": "group", "beginOffset": -1 },
"type": "COMMON",
"sentiment": { "magnitude": 0.30000001192092896, "score":0.30000001192092896 }
},
{
"text": { "content": "group", "beginOffset": -1 },
"type": "COMMON",
"sentiment": { "magnitude": 0.30000001192092896, "score":-0.30000001192092896 }
},
{
"text": { "content": "group", "beginOffset": -1 },
"type": "COMMON",
"sentiment": { "magnitude": 0, "score": 0 }
},
{
"text": { "content": "group", "beginOffset": -1 },
"type": "COMMON",
"sentiment": { "magnitude": 0, "score": 0 }
}
],
"metadata": {},
"name": "group",
"type": "ORGANIZATION",
"salience": 0.34768930077552795,
"sentiment": { "magnitude": 1.100000023841858, "score": 0 }
},
{
"mentions": [
{
"text": { "content": "Commonwealth", "beginOffset": -1 },
"type": "PROPER",
"sentiment": { "magnitude": 0, "score": 0 }
},
{
"text": { "content": "Commonwealth", "beginOffset": -1 },
"type": "PROPER",
"sentiment": { "magnitude": 0, "score": 0 }
},
{
"text": { "content": "Commonwealth", "beginOffset": -1 },
"type": "PROPER",
"sentiment": { "magnitude": 0, "score": 0 }
},
{
"text": { "content": "Commonwealth", "beginOffset": -1 },
"type": "PROPER",
"sentiment": { "magnitude": 0, "score": 0 }
},
{
"text": { "content": "Commonwealth", "beginOffset": -1 },
"type": "PROPER",
"sentiment": { "magnitude": 0, "score": 0 }
},
{
"text": { "content": "Commonwealth", "beginOffset": -1 },
"type": "PROPER",
"sentiment": { "magnitude": 0, "score": 0 }
},
{
"text": { "content": "Commonwealth", "beginOffset": -1 },
"type": "PROPER",
"sentiment": { "magnitude": 0, "score": 0 }
},
{
"text": { "content": "Commonwealth", "beginOffset": -1 },
"type": "PROPER",
"sentiment": { "magnitude": 0, "score": 0 }
},
{
"text": { "content": "Commonwealth", "beginOffset": -1 },
"type": "PROPER",
"sentiment": { "magnitude": 0, "score": 0 }
},
{
"text": { "content": "Commonwealth", "beginOffset": -1 },
"type": "PROPER",
"sentiment": { "magnitude": 0.10000000149011612, "score":-0.10000000149011612 }
},
{
"text": { "content": "Commonwealth", "beginOffset": -1 },
"type": "PROPER",
"sentiment": { "magnitude": 0, "score": 0 }
},
{
"text": { "content": "Commonwealth", "beginOffset": -1 },
"type": "PROPER",
"sentiment": { "magnitude": 0.20000000298023224, "score": -0.20000000298023224 }
},
{
"text": { "content": "Commonwealth", "beginOffset": -1 },
"type": "PROPER",
"sentiment": { "magnitude": 0, "score": 0 }
},
{
"text": { "content": "Commonwealth", "beginOffset": -1 },
"type": "PROPER",
"sentiment": { "magnitude": 0, "score": 0 }
},
{
"text": { "content": "Commonwealth", "beginOffset": -1 },
"type": "PROPER",
"sentiment": { "magnitude": 0, "score": 0 }
},
{
"text": { "content": "Commonwealth", "beginOffset": -1 },
"type": "PROPER",
"sentiment": { "magnitude": 0, "score": 0 }
},
{
"text": { "content": "Commonwealth", "beginOffset": -1 },
"type": "PROPER",
"sentiment": { "magnitude": 0, "score": 0 }
},
{
"text": { "content": "Commonwealth", "beginOffset": -1 },
"type": "PROPER",
"sentiment": { "magnitude": 0, "score": 0 }
},
{
"text": { "content": "Commonwealth", "beginOffset": -1 },
"type": "PROPER",
"sentiment": { "magnitude": 0, "score": 0 }
},
{
"text": { "content": "Commonwealth of Nations", "beginOffset": -1 },
"type": "PROPER",
"sentiment": { "magnitude": 0, "score": 0 }
},
{
"text": { "content": "Commonwealth\r\nOne", "beginOffset": -1 },
"type": "PROPER",
"sentiment": { "magnitude": 0, "score": 0 }
}
],
"metadata": {
"mid": "/m/0j7v_",
"wikipedia_url": "https://en.wikipedia.org/wiki/Commonwealth_of_Nations"
},
"name": "Commonwealth of Nations",
"type": "LOCATION",
"salience": 0.28001657128334045,
"sentiment": { "magnitude": 1.7000000476837158, "score": 0 }
},
...
]
有没有一种简单的方法可以做到这一点,我完全错过了? 感谢您的任何见解/想法。
奥利
答案 0 :(得分:0)
我相信您需要 beginOffset :
beginOffset指示句子开始的给定文本中的(从零开始)字符偏移量。请注意,此偏移量是使用传递的encodingType计算的。
如果您在请求中指定EncodingType,它应该有效。
如果未指定EncodingType,则编码相关信息(例如beginOffset)将设置为-1。