예제 #1
0
 def test_null_link_range_starting_with_zero(self):
     """Test parsing with a minimal number of null-links, including 0."""
     # This sentence has no complete linkage. Validate that the library
     # doesn't mangle parsing with null-count>0 due to power_prune()'s
     # connector-discard optimization at null-count==0.  Without commit
     # "Allow calling classic_parse() with and w/o nulls", the number of
     # linkages here is 1 instead of 2 and the unused_word_cost is 5.
     self.po = ParseOptions(min_null_count=0, max_null_count=999)
     linkages = Sentence('about people attended', self.d, self.po).parse()
     self.assertEqual(len(linkages), 2)
     self.assertEqual(linkages.next().unused_word_cost(), 1)
예제 #2
0
def linkage_testfile(self, dict, popt, desc=''):
    """
    Reads sentences and their corresponding
    linkage diagrams / constituent printings.
    """
    if '' != desc:
        desc = desc + '-'
    parses = open(clg.test_data_srcdir + "parses-" + desc +
                  clg.dictionary_get_lang(dict._obj) + ".txt")
    diagram = None
    sent = None
    for line in parses:
        # Lines starting with I are the input sentences
        if 'I' == line[0]:
            sent = line[1:]
            diagram = ""
            constituents = ""
            linkages = Sentence(sent, dict, popt).parse()
            linkage = linkages.next()

        # Generate the next linkage of the last input sentence
        if 'N' == line[0]:
            diagram = ""
            constituents = ""
            linkage = linkages.next()

        # Lines starting with O are the parse diagram
        # It ends with an empty line
        if 'O' == line[0]:
            diagram += line[1:]
            if '\n' == line[1] and 1 < len(diagram):
                self.assertEqual(linkage.diagram(), diagram)

        # Lines starting with C are the constituent output (type 1)
        # It ends with an empty line
        if 'C' == line[0]:
            if '\n' == line[1] and 1 < len(constituents):
                self.assertEqual(linkage.constituent_tree(), constituents)
            constituents += line[1:]
    parses.close()
예제 #3
0
def linkage_testfile(self, dict, popt, desc = ''):
    """
    Reads sentences and their corresponding
    linkage diagrams / constituent printings.
    """
    if '' != desc:
        desc = desc + '-'
    parses = open(clg.test_data_srcdir + "parses-" + desc + clg.dictionary_get_lang(dict._obj) + ".txt")
    diagram = None
    sent = None
    for line in parses:
        # Lines starting with I are the input sentences
        if 'I' == line[0]:
            sent = line[1:]
            diagram = ""
            constituents = ""
            linkages = Sentence(sent, dict, popt).parse()
            linkage = linkages.next()

        # Generate the next linkage of the last input sentence
        if 'N' == line[0]:
            diagram = ""
            constituents = ""
            linkage = linkages.next()

        # Lines starting with O are the parse diagram
        # It ends with an empty line
        if 'O' == line[0]:
            diagram += line[1:]
            if '\n' == line[1] and 1 < len(diagram):
                self.assertEqual(linkage.diagram(), diagram)

        # Lines starting with C are the constituent output (type 1)
        # It ends with an empty line
        if 'C' == line[0]:
            if '\n' == line[1] and 1 < len(constituents):
                self.assertEqual(linkage.constituent_tree(), constituents)
            constituents += line[1:]
    parses.close()