Beispiel #1
0
def compare_hlds_variants():
    """
    TODO: kill bugs
    
    BUG1: sentence001-original-test contains 2(!) <item> sentences.
    
    """
    hlds_reader = hlds.HLDSReader(hlds.testbed_file)
    for i, sentence in enumerate(hlds_reader.sentences):
        xml_sentence_test = hlds.create_hlds_file(sentence, mode="test", 
                                                     output="xml")
        util.write_to_file(xml_sentence_test, 
                      "xmltest/sentence{0}-converted-test.xml".format(str(i).zfill(3)))

        xml_sentence_realize = hlds.create_hlds_file(sentence, mode="test", 
                                                        output="xml")        
        util.write_to_file(xml_sentence_test, 
                      "xmltest/sentence{0}-converted-realize.xml".format(str(i).zfill(3)))

    for i, item_etree in enumerate(hlds_reader.xml_sentences):
        root = etree.Element("regression")
        doc = etree.ElementTree(root)
        root.insert(0, item_etree)
        xml_sentence_original = hlds.etreeprint(doc)
        util.write_to_file(xml_sentence_original, 
                      "xmltest/sentence{0}-original-test.xml".format(str(i).zfill(3)))
Beispiel #2
0
def compare_hlds_variants():
    """
    TODO: kill bugs
    
    BUG1: sentence001-original-test contains 2(!) <item> sentences.
    
    """
    hlds_reader = hlds.HLDSReader(hlds.testbed_file)
    for i, sentence in enumerate(hlds_reader.sentences):
        xml_sentence_test = hlds.create_hlds_file(sentence,
                                                  mode="test",
                                                  output="xml")
        util.write_to_file(
            xml_sentence_test,
            "xmltest/sentence{0}-converted-test.xml".format(str(i).zfill(3)))

        xml_sentence_realize = hlds.create_hlds_file(sentence,
                                                     mode="test",
                                                     output="xml")
        util.write_to_file(
            xml_sentence_test,
            "xmltest/sentence{0}-converted-realize.xml".format(
                str(i).zfill(3)))

    for i, item_etree in enumerate(hlds_reader.xml_sentences):
        root = etree.Element("regression")
        doc = etree.ElementTree(root)
        root.insert(0, item_etree)
        xml_sentence_original = hlds.etreeprint(doc)
        util.write_to_file(
            xml_sentence_original,
            "xmltest/sentence{0}-original-test.xml".format(str(i).zfill(3)))
Beispiel #3
0
def test_textplan2xml_conversion():
    """
    test text plan to XML conversion with all the text plans that were
    generated for all test queries with debug.gen_all_textplans().
    """
    import cPickle

    atp = cPickle.load(open("data/alltextplans.pickle", "r"))

    print """### Output: One XML file per query ###\n\n"""
    for atp_count, textplans in enumerate(atp):
        xml_plan = textplans2xml(textplans)
        print "All text plans generated" " for test query #{0}:\n".format(atp_count)
        print etreeprint(xml_plan, debug=False), "\n\n\n"

    print """### Output: One XML file per text plan ###\n\n"""
    for atp_count, tp in enumerate(atp):
        for tp_count, docplan in enumerate(tp.document_plans):
            xml_plan = textplan2xml(docplan)
            print "Text plan {0} for " "test query {1}:\n".format(atp_count, tp_count)
            print etreeprint(xml_plan, debug=False), "\n\n\n"
Beispiel #4
0
def test_textplan2xml_conversion():
    """
    test text plan to XML conversion with all the text plans that were
    generated for all test queries with debug.gen_all_textplans().
    """
    import cPickle
    atp = cPickle.load(open("data/alltextplans.pickle", "r"))

    print """### Output: One XML file per query ###\n\n"""
    for atp_count, textplans in enumerate(atp):
        xml_plan = textplans2xml(textplans)
        print "All text plans generated" \
              " for test query #{0}:\n".format(atp_count)
        print etreeprint(xml_plan, debug=False), "\n\n\n"

    print """### Output: One XML file per text plan ###\n\n"""
    for atp_count, tp in enumerate(atp):
        for tp_count, docplan in enumerate(tp.document_plans):
            xml_plan = textplan2xml(docplan)
            print "Text plan {0} for " \
                  "test query {1}:\n".format(atp_count, tp_count)
            print etreeprint(xml_plan, debug=False), "\n\n\n"
Beispiel #5
0
                          "as follows:\n".format(msg_block[Feature("msgType")])
                    for lexicalized_phrase in lexicalized_msg_block:
                        lexicalized_sentence = phrase2sentence(lexicalized_phrase)

                        # TODO: refactor to avoid duplication w/ OpenCCG.realize
                        temp_sentence = deepcopy(lexicalized_sentence)

                        if isinstance(lexicalized_sentence, Diamond):
                            temp_sentence = diamond2sentence(temp_sentence)

                        add_nom_prefixes(temp_sentence)
                        print create_hlds_file(temp_sentence,
                            mode="realize", output="xml")

                except NotImplementedError, err:
                    print err
                    print "The message block contains these messages:\n", msg_block, \
                          "\n\n**********\n\n"

    elif output_format == 'textplan-featstruct':
        for i, textplan in enumerate(textplans.document_plans):
            print "Text plan #%i:\n" % i
            print textplan, "\n\n"

    else: # output_format == 'textplan-xml'
        etreeprint(textplans2xml(textplans))


if __name__ == "__main__":
    main()
Beispiel #6
0
                          "as follows:\n".format(msg_block[Feature("msgType")])
                    for lexicalized_phrase in lexicalized_msg_block:
                        lexicalized_sentence = phrase2sentence(lexicalized_phrase)

                        # TODO: refactor to avoid duplication w/ OpenCCG.realize
                        temp_sentence = deepcopy(lexicalized_sentence)

                        if isinstance(lexicalized_sentence, Diamond):
                            temp_sentence = diamond2sentence(temp_sentence)

                        add_nom_prefixes(temp_sentence)
                        print create_hlds_file(temp_sentence,
                            mode="realize", output="xml")

                except NotImplementedError, err:
                    print err
                    print "The message block contains these messages:\n", msg_block, \
                          "\n\n**********\n\n"

    elif output_format == 'textplan-featstruct':
        for i, textplan in enumerate(textplans.document_plans):
            print "Text plan #%i:\n" % i
            print textplan, "\n\n"

    else: # output_format == 'textplan-xml'
        etreeprint(textplans2xml(textplans))


if __name__ == "__main__":
    main()