Last active
October 16, 2018 02:07
-
-
Save komasaru/c19d10d4ba25377cc51e09fb5ac271bb to your computer and use it in GitHub Desktop.
Python script to test of MeCab.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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