5
2

More than 5 years have passed since last update.

Yahooにも形態素解析APIがあるらしいので使ってみた

Last updated at Posted at 2019-06-06

動機

前回はCOTOHA APIで形態素解析をしました
せっかくCOTOHA APIで形態素解析をやってみたので、今度はYahooのAPIを使ってみます。

以下ソース

import requests
import xml.etree.ElementTree as ET

target_url = "https://jlp.yahooapis.jp/MAService/V1/parse"
client_id = "ID"

sentence = "私はその人の記憶を呼び起すごとに、すぐ「先生」といいたくなる"

data = {
    "appid":client_id,
    "results":"ma",
    "sentence":sentence
}

response = requests.post(target_url, data=data)

root = ET.fromstring(response.text)

for e in root.getiterator("{urn:yahoo:jp:jlp}surface"):
    print (e.text, end=" ")

結果

形態素解析の結果

入力文 私はその人の記憶を呼び起すごとに、すぐ「先生」といいたくなる
出力文 私 は その 人 の 記憶 を 呼び起す ごとに 、 すぐ 「 先生 」 と いい たく なる 

COTOHA APIとの出力の比較

入力文            私はその人の記憶を呼び起すごとに、すぐ「先生」といいたくなる
COTOHA APIの出力文 私 は その 人 の 記憶 を 呼び起 す ごと に 、 すぐ 「 先生 」 と い い た く な る  
Yahoo APIの出力文  私 は その 人 の 記憶 を 呼び起す ごとに 、 すぐ 「 先生 」 と いい たく なる 

まとめ

tokenをとらなくていいところは楽です。
返ってくるのがxmlなのはあまり好きじゃなくて、jsonで返してほしいですね。
あとはサンプルコードがあるのは嬉しいですが、phpだけなのは少し悲しいです。

参考記事

5
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
2