Address to the bug that node.surface cannot be obtained with python3 + mecab

"Mecab" that can analyze Japanese morphological elements. It's also an excellent tool, and it's built into each programming language and used in many places.

However, when implemented on Python3, there are cases where "** characters cannot be acquired on node.surface, which should be able to acquire characters, resulting in an error **". Correspondence memo in such a case.

Execution environment

If you do the following, a bug will occur.

tagger = MeCab.Tagger('-Ochasen')
node = tagger.parseToNode(sentence)
while node:
	print(node.surface) # <=Characters cannot be acquired and an encoding error occurs
	node = node.next

The response to this works well if you "parse the empty string and then parse the target string". (Reference: How to use MeCab on Ubuntu 14.04 and Python 3 )

tagger = MeCab.Tagger('-Ochasen')
tagger.parse('') # <=Parse the empty string
node = tagger.parseToNode(sentence)
while node:
	print(node.surface) # <=You can get the characters!
	node = node.next

I'm not sure why, but this seems to be a known bug. I want you to respond as soon as possible because it is too trapped ...

Recommended Posts

Address to the bug that node.surface cannot be obtained with python3 + mecab
Workaround for the problem that UTF-8 Japanese mail cannot be sent with Flask-Mail (Python3)
Solution when the image cannot be displayed with tkinter [python]
[Raspberry Pi] Scraping of web pages that cannot be obtained with python requests + Beautiful Soup
Dealing with the error that HTTP fetch error occurs in gpg and the key cannot be obtained
Install packages that need to be compiled with Python3 with pip [Windows]
Python modules with "-(hyphen)" cannot be removed
Items that cannot be imported with sklearn
The road to compiling to Python 3 with Thrift
[Python] A program that calculates the number of socks to be paired
Project cannot be created with Python3.5 (Windows) + django1.7.1
Send an email to Spushi's address with python
The easiest way to synthesize speech with python
Try to solve the man-machine chart with Python
About the matter that localhost: 4040 cannot be accessed after running Spark with Docker
Specify the Python executable to use with virtualenv
I tried to predict the horses that will be in the top 3 with LightGBM
Say hello to the world with Python with IntelliJ
I tried to summarize the operations that are likely to be used with numpy-stl
Investigation when import cannot be done with python
Introduction to Python with Atom (on the way)
The problem that the ifconfig command cannot be used
Run the output code with tkinter, saying "A, pretending to be B" in python
Change the string to be replaced according to the matched string by replacing with Python regular expression
[Python] Introduction to web scraping | Summary of methods that can be used with webdriver
Starting with Python 3.10, the form returned by inspect.signature () seems to be based on typing.get_type_hints ().
Try to create a waveform (audio spectrum) that moves according to the sound with python
Try to solve the programming challenge book with python3
[Introduction to Python] How to iterate with the range function?
Import libraries that cannot be pip installed with PyCharm
Try to solve the internship assignment problem with Python
The first algorithm to learn with Python: FizzBuzz problem
I tried to solve the soma cube with python
[Python] How to specify the download location with youtube-dl
Python knowledge notes that can be used with AtCoder
Convert the image in .zip to PDF with Python
I want to inherit to the back with python dataclass
[Python] tkinter Code that is likely to be reused
[Python] pandas Code that is likely to be reused
Specify MinGW as the compiler to use with Python
A memo that I touched the Datastore with python
I tried to solve the problem with Python Vol.1
I felt that I ported the Python code to C ++ 98.
[Python] How to rewrite the table style with python-pptx [python-pptx]
Limits that can be analyzed at once with MeCab
Use mecab with Python3
I made a class to get the analysis result by MeCab in ndarray with python
Try to visualize the nutrients of corn flakes that M-1 champion Milkboy said with Python
[Python] A program to find the number of apples and oranges that can be harvested
I tried to find the entropy of the image with python
I want to be able to analyze data with Python (Part 3)
I tried to simulate how the infection spreads with Python
Try to play with the uprobe that supports Systemtap directly
I wanted to solve the Panasonic Programming Contest 2020 with Python
[Python] It might be useful to list the data frames
How to switch the configuration file to be read by Python
The first API to make with python Djnago REST framework
Minimum knowledge to get started with the Python logging module
Processing of python3 that seems to be usable in paiza
Probably the easiest way to create a pdf with Python3
Video cannot be loaded with Spyder in Python development environment