エンティティ分析は文章から重要な固有名詞を取り出してくれます
# エンティティ分析 analyzeEntities import sys import requests import json content = U'僕は、エヴァンゲリオン初号機のパイロット、碇シンジです!' ApiKey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" url = 'https://language.googleapis.com/v1/documents:analyzeEntities?key={}'.format(ApiKey) header = {'Content-Type': 'application/json'} body = { "document": { "type": "PLAIN_TEXT", "language": "JA", "content": content }, "encodingType": "UTF8" } response = requests.post(url, headers=header, json=body).json() text = json.dumps(response, sort_keys=True, ensure_ascii=False, indent=2) print(text)
エンティティ分析結果
エヴァは芸術作品 ( WORK_OF_ART ) らしいです
{ "entities": [ { "mentions": [ { "text": { "beginOffset": 9, "content": "エヴァンゲリオン" }, "type": "PROPER" } ], "metadata": {}, "name": "エヴァンゲリオン", "salience": 0.30763963, "type": "WORK_OF_ART" }, { "mentions": [ { "text": { "beginOffset": 63, "content": "碇シンジ" }, "type": "COMMON" } ], "metadata": {}, "name": "碇シンジ", "salience": 0.26153272, "type": "OTHER" }, { "mentions": [ { "text": { "beginOffset": 33, "content": "初号機" }, "type": "COMMON" } ], "metadata": {}, "name": "初号機", "salience": 0.24562897, "type": "OTHER" }, { "mentions": [ { "text": { "beginOffset": 45, "content": "パイロット" }, "type": "COMMON" } ], "metadata": {}, "name": "パイロット", "salience": 0.18519868, "type": "OTHER" } ], "language": "ja" }