def phrase_extent_for_head(tokens, head_index):
 begin = tokens[head_index]['text']['beginOffset']
 end = (begin + len(tokens[head_index]['text']['content']))
 for child in dependents(tokens, head_index):
  (child_begin, child_end) = phrase_extent_for_head(tokens, child)
  begin = min(begin, child_begin)
  end = max(end, child_end)
 return (begin, end)

def phrase_extent_for_head ( tokens , head_index ) : begin = tokens [ head_index ] [ 'text' ] [ 'beginOffset' ] end = ( begin + len ( tokens [ head_index ] [ 'text' ] [ 'content' ] ) ) for child in dependents ( tokens , head_index ) : ( child_begin , child_end ) = phrase_extent_for_head ( tokens , child ) begin = min ( begin , child_begin ) end = max ( end , child_end ) return ( begin , end )
returns the begin and end offsets for the entire phrase containing the head token and its dependents .