| 1 |
#!/usr/bin/env python |
| 2 |
|
| 3 |
import argparse |
| 4 |
import sys |
| 5 |
|
| 6 |
import morfessor |
| 7 |
from morfessor import _logger |
| 8 |
|
| 9 |
|
| 10 |
def main(argv): |
| 11 |
parser = morfessor.get_default_argparser() |
| 12 |
parser.prog = "morfessor-segment" |
| 13 |
parser.epilog = """ |
| 14 |
Simple usage example (load model.pickled and use it to segment test corpus): |
| 15 |
|
| 16 |
%(prog)s -l model.pickled -o test_corpus.segmented test_corpus.txt |
| 17 |
|
| 18 |
Interactive use (read corpus from user): |
| 19 |
|
| 20 |
%(prog)s -l model.pickled - |
| 21 |
|
| 22 |
""" |
| 23 |
|
| 24 |
keep_options = ['encoding', 'loadfile', 'loadsegfile', 'outfile'] |
| 25 |
# FIXME Disabled to work around an argparse bug |
| 26 |
#'help', 'version'] |
| 27 |
for action_group in parser._action_groups: |
| 28 |
for arg in action_group._group_actions: |
| 29 |
if arg.dest not in keep_options: |
| 30 |
arg.help = argparse.SUPPRESS |
| 31 |
|
| 32 |
parser.add_argument('testfiles', metavar='<file>', nargs='+', |
| 33 |
help='corpus files to segment') |
| 34 |
|
| 35 |
try: |
| 36 |
args = parser.parse_args(argv) |
| 37 |
morfessor.main(args) |
| 38 |
except morfessor.ArgumentException as e: |
| 39 |
parser.error(e) |
| 40 |
except Exception as e: |
| 41 |
_logger.error("Fatal Error %s %s" % (type(e), e)) |
| 42 |
raise |
| 43 |
|
| 44 |
|
| 45 |
if __name__ == "__main__": |
| 46 |
main(sys.argv[1:]) |