Пример #1
0
 def apply_iter(self, chart, grammar, right_edge):
     if (right_edge.is_incomplete() or       # use only completed edges
         isinstance(right_edge, LeafEdge) or # skip terminal leaves
         is_lexical(right_edge) or           # skip lexical productions
         right_edge.lhs().symbol() == 'G'):  # skip BRM rules
         return
     # We only merge if both the right end left edge are completed. The
     # left edge must be adjacent to the right edge in the chart.
     for left_edge in chart.select(end=right_edge.start(), is_complete=True):
         if isinstance(left_edge, LeafEdge) or is_lexical(left_edge):
             continue
         new_edge = TreeEdge(span=(left_edge.start(), right_edge.end()),
                             lhs=right_edge.lhs(),
                             rhs=[left_edge.lhs(), right_edge.lhs()],
                             dot=2) # edge is completed at initialization
         if chart.insert(new_edge, (left_edge, right_edge)):
             yield new_edge