Skip to content

Instantly share code, notes, and snippets.

@komasaru komasaru/test_mecab.py
Last active Oct 16, 2018

Embed
What would you like to do?
Python script to test of MeCab.
#! /usr/local/bin/python3.7
"""
Test of MeCab library
"""
import sys
import traceback
import MeCab
class TestMecab:
DIR_DIC = "/usr/lib/x86_64-linux-gnu/mecab/dic/mecab-ipadic-neologd"
SENTENCE = "太郎はこの本を二郎を見た女性に渡した。"
def exec(self):
try:
t = MeCab.Tagger("-d " + self.DIR_DIC)
#print(t.parse(self.SENTENCE))
for c in t.parse(self.SENTENCE).splitlines()[:-1]:
surface, feature = c.split('\t')
print("{}\t{}".format(surface, feature))
except Exception as e:
raise
if __name__ == '__main__':
try:
obj = TestMecab()
obj.exec()
except Exception as e:
traceback.print_exc()
sys.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.