#NEWLINE# def _add_constituents_spanning( self , span , constituents , tokens ) : #NEWLINE# #INDENT# '\n        Find any constituents that might cover ``span``, and add them\n        to the most likely constituents table.\n\n        :rtype: None\n        :type span: tuple(int, int)\n        :param span: The section of the text for which we are\n            trying to find possible constituents.  The span is\n            specified as a pair of integers, where the first integer\n            is the index of the first token that should be included in\n            the constituent; and the second integer is the index of\n            the first token that should not be included in the\n            constituent.  I.e., the constituent should cover\n            ``text[span[0]:span[1]]``, where ``text`` is the text\n            that we are parsing.\n\n        :type constituents: dict(tuple(int,int,Nonterminal) -> ProbabilisticToken or ProbabilisticTree)\n        :param constituents: The most likely constituents table.  This\n            table records the most probable tree representation for\n            any given span and node value.  In particular,\n            ``constituents(s,e,nv)`` is the most likely\n            ``ProbabilisticTree`` that covers ``text[s:e]``\n            and has a node value ``nv.symbol()``, where ``text``\n            is the text that we are parsing.  When\n            ``_add_constituents_spanning`` is called, ``constituents``\n            should contain all possible constituents that are shorter\n            than ``span``.\n\n        :type tokens: list of tokens\n        :param tokens: The text we are parsing.  This is only used for\n            trace output.\n        ' #NEWLINE# changed = True #NEWLINE# while changed : #NEWLINE# #INDENT# changed = False #NEWLINE# instantiations = self . _find_instantiations ( span , constituents ) #NEWLINE# for ( production , children ) in instantiations : #NEWLINE# #INDENT# subtrees = [ c for c in children if isinstance ( c , Tree ) ] #NEWLINE# p = reduce ( ( lambda pr , t : ( pr * t . prob ( ) ) ) , subtrees , production . prob ( ) ) #NEWLINE# node = production . lhs ( ) . symbol ( ) #NEWLINE# tree = ProbabilisticTree ( node , children , prob = p ) #NEWLINE# c = constituents . get ( ( span [ 0 ] , span [ 1 ] , production . lhs ( ) ) ) #NEWLINE# if ( self . _trace > 1 ) : #NEWLINE# #INDENT# if ( ( c is None ) or ( c != tree ) ) : #NEWLINE# #INDENT# if ( ( c is None ) or ( c . prob ( ) < tree . prob ( ) ) ) : #NEWLINE# #INDENT# print ( '   Insert:' , end = ' ' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# print ( '  Discard:' , end = ' ' ) #NEWLINE# #UNINDENT# self . _trace_production ( production , p , span , len ( tokens ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( ( c is None ) or ( c . prob ( ) < tree . prob ( ) ) ) : #NEWLINE# #INDENT# constituents [ ( span [ 0 ] , span [ 1 ] , production . lhs ( ) ) ] = tree #NEWLINE# changed = True