コード例 #1
0
ファイル: cfg.py プロジェクト: annkeenan/nlp-homework
    trees_file = 'trees/train.trees.pre.unk'
    strings_file = 'strings/dev.strings'
    output_file = 'output/dev.parses'

    parser = argparse.ArgumentParser()
    parser.add_argument(
        '-p',
        action='store_true',
        help='print the first five parses from parsing strings')
    parser.add_argument(
        '-g',
        action='store_true',
        help='show a plot of the parsing time vs sentence length')
    parser.add_argument('--trees', help='use the trees in the specified file')
    parser.add_argument('--strings',
                        help='use the strings in the specified file')
    parser.add_argument('--output', help='specify an output file')
    args = parser.parse_args()

    if args.trees:
        trees_file = args.trees
    if args.strings:
        strings_file = args.strings
    if args.output:
        output_file = args.output

    cfg = Grammar()
    cfg.construct_cfg(trees_file)
    cky = CKY(cfg, args.p, args.g)
    cky.parse_sentences(strings_file, output_file)