Skip to content

Instantly share code, notes, and snippets.

@komasaru
Last active October 16, 2018 02:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save komasaru/c19d10d4ba25377cc51e09fb5ac271bb to your computer and use it in GitHub Desktop.
Save komasaru/c19d10d4ba25377cc51e09fb5ac271bb to your computer and use it in GitHub Desktop.
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