| 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-train" |
| 13 |
parser.epilog = """ |
| 14 |
Simple usage example (train a model and save it to model.pickled): |
| 15 |
|
| 16 |
%(prog)s -s model.pickled training_corpus.txt |
| 17 |
|
| 18 |
Interactive use (read corpus from user): |
| 19 |
|
| 20 |
%(prog)s -m online -v 2 - |
| 21 |
|
| 22 |
""" |
| 23 |
|
| 24 |
keep_options = ['savesegfile', 'savefile', 'trainmode', 'dampening', |
| 25 |
'encoding', 'list', 'skips', 'annofile', 'develfile', |
| 26 |
'fullretrain', 'threshold', 'morphtypes', 'morphlength', |
| 27 |
'corpusweight', 'annotationweight', 'help', 'version'] |
| 28 |
for action_group in parser._action_groups: |
| 29 |
for arg in action_group._group_actions: |
| 30 |
if arg.dest not in keep_options: |
| 31 |
arg.help = argparse.SUPPRESS |
| 32 |
|
| 33 |
parser.add_argument('trainfiles', metavar='<file>', nargs='+', |
| 34 |
help='training data files') |
| 35 |
|
| 36 |
try: |
| 37 |
args = parser.parse_args(argv) |
| 38 |
morfessor.main(args) |
| 39 |
except morfessor.ArgumentException as e: |
| 40 |
parser.error(e) |
| 41 |
except Exception as e: |
| 42 |
_logger.error("Fatal Error {} {}".format(type(e), e)) |
| 43 |
raise |
| 44 |
|
| 45 |
|
| 46 |
if __name__ == "__main__": |
| 47 |
main(sys.argv[1:]) |