Exemplo n.º 1
0
def main(args = None):
    DESCRIPTION=textwrap.dedent("""\
            Prints graphically in HTML the CCG tree. If <semantics> content
            is also present in the XML file, then logical formulas appear
            below the syntactic categories to show the semantic composition.
            The input file with the CCG tree should follow Jigg's format:
            https://github.com/mynlp/jigg
      """)

    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawDescriptionHelpFormatter,
        description=DESCRIPTION)
    parser.add_argument("trees_xml")
    args = parser.parse_args()
      
    if not os.path.exists(args.trees_xml):
        print('File does not exist: {0}'.format(args.trees_xml))
    
    logging.basicConfig(level=logging.WARNING)

    parser = etree.XMLParser(remove_blank_text=True)
    doc = etree.parse(args.trees_xml, parser)

    html_str = convert_doc_to_mathml(doc)
    print(html_str)
Exemplo n.º 2
0
def main(args = None):
    DESCRIPTION=textwrap.dedent("""\
            The input file sem should contain the parsed sentences. All CCG trees correspond
            to the premises, except the last one, which is the hypothesis.
      """)

    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawDescriptionHelpFormatter,
        description=DESCRIPTION)
    parser.add_argument("sem", help="XML input filename with semantics")
    parser.add_argument("--graph_out", nargs='?', type=str, default="",
        help="HTML graphical output filename.")
    parser.add_argument("--abduction", action="store_true", default=False)
    parser.add_argument("--gold_trees", action="store_true", default=False)
    args = parser.parse_args()
      
    if not os.path.exists(args.sem):
        print('File does not exist: {0}'.format(args.sem), file=sys.stderr)
        parser.print_help(file=sys.stderr)
        sys.exit(1)
    
    logging.basicConfig(level=logging.WARNING)

    parser = etree.XMLParser(remove_blank_text=True)
    doc = etree.parse(args.sem, parser)

    inference_result, coq_scripts = prove_doc(doc, args.abduction)
    print(inference_result, file=sys.stdout)

    if args.graph_out:
        html_str = convert_doc_to_mathml(doc, coq_scripts, args.gold_trees)
        with codecs.open(args.graph_out, 'w', 'utf-8') as fout:
            fout.write(html_str)
Exemplo n.º 3
0
def print_html_problem(doc, dir_name):
    prob_id = doc.get('pair_id', '00000')
    prob_html_fname = dir_name + '/' + prob_id + '.html'
    if prob_id == '00000':
        logging.warning('RTE problem ID unspecified. Overwriting ' +
                        prob_html_fname)
    coq_scripts = doc.xpath('./proof/theorems/theorem/coq_script/text()')
    mathml_str = convert_doc_to_mathml(doc)
    html_str = wrap_mathml_in_html(mathml_str)
    with codecs.open(prob_html_fname, 'w', 'utf-8') as fout:
        fout.write(html_str)
    return