Japanese morphological analysis with Python

I will try Japanese morphological analysis with Python. Since the API is from Yahoo, we will use it.

http://developer.yahoo.co.jp/webapi/jlp/ma/v1/parse.html

First of all, the essential parameters for POST are ・ Appid ・ Sentence ・ Results There are three points. If you want to POST in detail, please add a parameter.

You can get the appid by registering with Yahoo. sentence is the text to be morphologically analyzed. results is for specifying the format of the response.

Morphological analysis.py


#coding: utf-8

import requests
from xml.etree.ElementTree import *

def POST(body):
	request_URL = "http://jlp.yahooapis.jp/MAService/V1/parse"

	parameter = {'appid': 'Your appid!',
				'sentence': body,
				'results': 'ma'}
	r = requests.get(request_URL, params=parameter)
	yield (r, r.text)

def XML_parse(body):
	elem = fromstring(body)
	for e in elem.getiterator("{urn:yahoo:jp:jlp}surface"):
		print e.text

if __name__ == '__main__':
	for response in POST(body="It's nice weather today, is not it"):
		r = response[0]
		text = response[1]
	XML_parse(text.encode('utf-8'))#Unicode without encode-error

Recommended Posts

Japanese morphological analysis with Python
[Python] Morphological analysis with MeCab
Python: Japanese text: Morphological analysis
Text mining with Python ① Morphological analysis
Data analysis with python 2
Voice analysis with python
Voice analysis with python
Python: Simplified morphological analysis with regular expressions
Data analysis with Python
From the introduction of JUMAN ++ to morphological analysis of Japanese with Python
Send Japanese email with Python3
[Co-occurrence analysis] Easy co-occurrence analysis with Python! [Python]
Sentiment analysis with Python (word2vec)
Planar skeleton analysis with Python
Muscle jerk analysis with Python
[PowerShell] Morphological analysis with SudachiPy
Collecting information from Twitter with Python (morphological analysis with MeCab)
3D skeleton structure analysis with Python
Impedance analysis (EIS) with python [impedance.py]
Speak Japanese text with OpenJTalk + python
I played with Mecab (morphological analysis)!
Data analysis starting with python (data visualization 1)
Logistic regression analysis Self-made with python
Data analysis starting with python (data visualization 2)
Morphological analysis using Igo + mecab-ipadic-neologd in Python (with Ruby bonus)
FizzBuzz with Python3
Scraping with Python
[In-Database Python Analysis Tutorial with SQL Server 2017]
Marketing analysis with Python ① Customer analysis (decyl analysis, RFM analysis)
Two-dimensional saturated-unsaturated osmotic flow analysis with Python
Scraping with Python
Python with Go
Data analysis python
Generate Japanese test data with Python faker
Machine learning with python (2) Simple regression analysis
2D FEM stress analysis program with Python
Twilio with Python
Integrate with Python
Download Japanese stock price data with python
Notes on doing Japanese OCR with Python
Play with 2016-Python
AES256 with python
Tested with Python
python starts with ()
How to display python Japanese with lolipop
[Python] Let's make matplotlib compatible with Japanese
with syntax (Python)
Tweet analysis with Python, Mecab and CaboCha
Principal component analysis with Power BI + Python
Japanese with matplotlib
Bingo with python
Zundokokiyoshi with python
Data analysis starting with python (data preprocessing-machine learning)
How to enter Japanese with Python curses
Two-dimensional unsteady heat conduction analysis with Python
Excel with Python
Microcomputer with Python
Cast with python
From preparation for morphological analysis with python using polyglot to part-of-speech tagging
[Let's play with Python] Aiming for automatic sentence generation ~ Perform morphological analysis ~
Try it with Word Cloud Japanese Python JupyterLab.