tags=[tag], extra_features={ 'duration': duration, 'time': time, }) tags.append(word_signs) tagger = PretaggedTagger(grammar, input.slice(start, end), tags=tags) # Use the directed parser to try parsing according to this tree parser = DirectedCkyParser(grammar, tagger, derivation_tree=sub_tree, options=popts) try: parser.parse(derivations=True) except DirectedParseError, err: # Parse failed, so we can't train on this sequence raise ParseError, "[Partial parse %d (%d-%d)] parsing using "\ "the derivation tree failed: %s" % (i,start,end,err) # We should now have a complete parse available parses = parser.chart.parses if len(parses) == 0: raise ParseError, "[Partial parse %d (%d-%d)] parsing using the "\ "derivation tree did not produce any results" % (i,start,end) elif len(parses) > 1: raise ParseError, "the annotated tree gave multiple "\ "parse results: %s" % ", ".join(["%s" % p for p in parses]) else: sub_parses.append(parses[0])
"grammar for the tag %s (chord %s)" % \ (tag, word) else: # Get all signs that correspond to this tag from the grammar word_signs = grammar.get_signs_for_word(word, tags=[tag], extra_features={ 'duration' : duration, 'time' : time, }) tags.append(word_signs) tagger = PretaggedTagger(grammar, input.slice(start,end), tags=tags) # Use the directed parser to try parsing according to this tree parser = DirectedCkyParser(grammar, tagger, derivation_tree=sub_tree, options=popts) try: parser.parse(derivations=True) except DirectedParseError, err: # Parse failed, so we can't train on this sequence raise ParseError, "[Partial parse %d (%d-%d)] parsing using "\ "the derivation tree failed: %s" % (i,start,end,err) # We should now have a complete parse available parses = parser.chart.parses if len(parses) == 0: raise ParseError, "[Partial parse %d (%d-%d)] parsing using the "\ "derivation tree did not produce any results" % (i,start,end) elif len(parses) > 1: raise ParseError, "the annotated tree gave multiple "\ "parse results: %s" % ", ".join(["%s" % p for p in parses]) else: sub_parses.append(parses[0])