-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This includes one script that works as a command-line MeCab replacement and one that spits out dictionary info.
- Loading branch information
Showing
3 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
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
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) |
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
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) |
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