How to use the depccg.download.SEMANTIC_TEMPLATES.get function in depccg

To help you get started, we’ve selected a few depccg examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github masashi-y / depccg / depccg / __main__.py View on Github external
tag_list=tag_list,
                                   batchsize=args.batchsize,
                                   constraints=constraints)
        else:
            doc = [l.strip() for l in fin]
            doc = [sentence for sentence in doc if len(sentence) > 0]
            tagged_doc = annotate_fun([[word for word in sent.split(' ')] for sent in doc],
                                      tokenize=args.tokenize)
            if args.tokenize:
                tagged_doc, doc = tagged_doc
            res = parser.parse_doc(doc,
                                   probs=probs,
                                   tag_list=tag_list,
                                   batchsize=args.batchsize)

        semantic_templates = args.semantic_templates or SEMANTIC_TEMPLATES.get(args.lang)
        print_(res, tagged_doc,
                format=args.format,
                lang=args.lang,
                semantic_templates=semantic_templates)
        
        if input_type is None:
            sys.stdout.flush()
        else:
            break
github masashi-y / depccg / depccg / printer.py View on Github external
elif format == 'prolog':
        if lang == 'en':
            print(to_prolog_en(nbest_trees, tagged_doc), end='', file=file)
        elif lang == 'ja':
            print(to_prolog_ja(nbest_trees, tagged_doc), end='', file=file)
    elif format == 'html':
        print(to_mathml(nbest_trees), file=file)
    elif format == 'jigg_xml_ccg2lambda':
        jigg_xml = to_jigg_xml(nbest_trees, tagged_doc)
        templates = semantic_templates or SEMANTIC_TEMPLATES.get(lang)
        assert templates, f'--semantic-templates must be spcified for language: {lang}'
        result_xml_str, _ = ccg2lambda.parse(jigg_xml, str(templates))
        print(result_xml_str.decode('utf-8'), file=file)
    elif format == 'ccg2lambda':
        jigg_xml = to_jigg_xml(nbest_trees, tagged_doc)
        templates = semantic_templates or SEMANTIC_TEMPLATES.get(lang)
        assert templates, f'--semantic-templates must be spcified for language: {lang}'
        _, formulas_list = ccg2lambda.parse(jigg_xml, str(templates))
        for i, (parsed, formulas) in enumerate(zip(nbest_trees, formulas_list)):
            for (tree, prob), formula in zip(parsed, formulas):
                print(f'ID={i} log probability={prob:.4e}\n{formula}', file=file)
    elif format == 'conll':
        for i, (parsed, tokens) in enumerate(zip(nbest_trees, tagged_doc)):
            for tree, prob in parsed:
                print(f'# ID={i}\n# log probability={prob:.4e}\n{tree.conll(tokens=tokens)}', file=file)
    elif format == 'json':
        for i, (parsed, tokens) in enumerate(zip(nbest_trees, tagged_doc), 1):
            for tree, prob in parsed:
                res = tree.json(tokens=tokens)
                res['id'] = i
                res['prob'] = prob
                print(json.dumps(res), file=file)
github masashi-y / depccg / depccg / printer.py View on Github external
if format == 'xml':
        print(process_xml(to_xml(nbest_trees, tagged_doc)), file=file)
    elif format == 'jigg_xml':
        use_symbol = lang == 'ja'
        print(process_xml(to_jigg_xml(nbest_trees, tagged_doc, use_symbol=use_symbol)), file=file)
    elif format == 'prolog':
        if lang == 'en':
            print(to_prolog_en(nbest_trees, tagged_doc), end='', file=file)
        elif lang == 'ja':
            print(to_prolog_ja(nbest_trees, tagged_doc), end='', file=file)
    elif format == 'html':
        print(to_mathml(nbest_trees), file=file)
    elif format == 'jigg_xml_ccg2lambda':
        jigg_xml = to_jigg_xml(nbest_trees, tagged_doc)
        templates = semantic_templates or SEMANTIC_TEMPLATES.get(lang)
        assert templates, f'--semantic-templates must be spcified for language: {lang}'
        result_xml_str, _ = ccg2lambda.parse(jigg_xml, str(templates))
        print(result_xml_str.decode('utf-8'), file=file)
    elif format == 'ccg2lambda':
        jigg_xml = to_jigg_xml(nbest_trees, tagged_doc)
        templates = semantic_templates or SEMANTIC_TEMPLATES.get(lang)
        assert templates, f'--semantic-templates must be spcified for language: {lang}'
        _, formulas_list = ccg2lambda.parse(jigg_xml, str(templates))
        for i, (parsed, formulas) in enumerate(zip(nbest_trees, formulas_list)):
            for (tree, prob), formula in zip(parsed, formulas):
                print(f'ID={i} log probability={prob:.4e}\n{formula}', file=file)
    elif format == 'conll':
        for i, (parsed, tokens) in enumerate(zip(nbest_trees, tagged_doc)):
            for tree, prob in parsed:
                print(f'# ID={i}\n# log probability={prob:.4e}\n{tree.conll(tokens=tokens)}', file=file)
    elif format == 'json':