Skip to content

Commit

Permalink
Add command line scripts
Browse files Browse the repository at this point in the history
This includes one script that works as a command-line MeCab replacement
and one that spits out dictionary info.
  • Loading branch information
polm committed May 21, 2020
1 parent 12a0628 commit a148201
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
24 changes: 24 additions & 0 deletions bin/mecab-py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env python

"""mecab-py
This is a simple wrapper for mecab-python3 so you can test it from the command
line. Like the mecab binary, it treats each line of stdin as one sentence. You
can pass tagger arguments here too.
"""

from MeCab import Tagger
import sys
import fileinput

def parse(args=''):
"""Parse input from stdin."""
tagger = Tagger(args)

for line in fileinput.input([]):
print(tagger.parse(line.strip()))


if __name__ == '__main__':
args = ' '.join(sys.argv[1:])
parse(args)
29 changes: 29 additions & 0 deletions bin/mecab-py-info
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env python3

"""mecab-py-info
This is a script to print out mecab-python3's dictionary info. It's useful for
debugging and checking your configuration.
"""

from MeCab import Tagger
import sys

def info(args=''):
"""Print configuration info."""
tagger = Tagger(args)
di = tagger.dictionary_info()
#TODO get the package version here too
print("mecab-py dictionary info:")
print("-----")
while di:
print('version:'.ljust(10), di.version)
print('size:'.ljust(10), di.size)
print('charset:'.ljust(10), di.charset)
print('filename:'.ljust(10), di.filename)
print("-----")
di = di.next

if __name__ == '__main__':
args = ' '.join(sys.argv[1:])
info(args)
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ def _get_pkg_data_files(self, package):
data_files = data_files,
ext_modules = [MECAB_EXTENSION],
cmdclass = cmdclass,
scripts=['bin/mecab-py', 'bin/mecab-py-info'],
setup_requires = ["setuptools_scm"],
extras_require = {
'unidic': ['unidic'],
Expand Down

0 comments on commit a148201

Please sign in to comment.