Skip to content

Instantly share code, notes, and snippets.

@butsugiri
Created June 27, 2016 12:48
Show Gist options
  • Save butsugiri/17412ee98c23dc1cc0d96e80581b4521 to your computer and use it in GitHub Desktop.
Save butsugiri/17412ee98c23dc1cc0d96e80581b4521 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
"""
docomoの言語解析API(固有表現抽出)を叩くサンプルコード
"""
import requests
import json
BASEURL = "https://api.apigw.smt.docomo.ne.jp/gooLanguageAnalysis/v1/entity?APIKEY="
APIKEY = "YOUR APIKEY" #ここにAPIKEYを入力
class Docomo(object):
def __init__(self, APIKEY=APIKEY):
self.uri = "{}{}".format(BASEURL, APIKEY)
self.payload = {
"sentence": None,
"class_filter": "PSN" #必要なフィルタを記述
}
self.headers = {'Content-Type': 'application/json'}
def parse(self, query):
self.payload["sentence"] = query
r = requests.post(self.uri, data=json.dumps(self.payload), headers=self.headers)
return json.loads(r.text)
def main():
agent = Docomo()
resp = agent.parse("田中さんの日常。")
for name, _type in resp["ne_list"]:
print "Entity: {}\t Type: {}".format(name, _type)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment