def find_prepositions(chunked):
 for ch in chunked:
  ch.append(u'O')
 for (i, chunk) in enumerate(chunked):
  if (chunk[2].endswith(u'PP') and (chunk[(-1)] == u'O')):
   if ((i < (len(chunked) - 1)) and (chunked[(i + 1)][2].endswith((u'NP', u'PP')) or (chunked[(i + 1)][1] in (u'VBG', u'VBN')))):
    chunk[(-1)] = u'B-PNP'
    pp = True
    for ch in chunked[(i + 1):]:
     if (not (ch[2].endswith((u'NP', u'PP')) or (ch[1] in (u'VBG', u'VBN')))):
      break
     if (ch[2].endswith(u'PP') and pp):
      ch[(-1)] = u'I-PNP'
     if (not ch[2].endswith(u'PP')):
      ch[(-1)] = u'I-PNP'
      pp = False
 return chunked

def find_prepositions ( chunked ) : for ch in chunked : ch . append ( u'O' ) for ( i , chunk ) in enumerate ( chunked ) : if ( chunk [ 2 ] . endswith ( u'PP' ) and ( chunk [ ( - 1 ) ] == u'O' ) ) : if ( ( i < ( len ( chunked ) - 1 ) ) and ( chunked [ ( i + 1 ) ] [ 2 ] . endswith ( ( u'NP' , u'PP' ) ) or ( chunked [ ( i + 1 ) ] [ 1 ] in ( u'VBG' , u'VBN' ) ) ) ) : chunk [ ( - 1 ) ] = u'B-PNP' pp = True for ch in chunked [ ( i + 1 ) : ] : if ( not ( ch [ 2 ] . endswith ( ( u'NP' , u'PP' ) ) or ( ch [ 1 ] in ( u'VBG' , u'VBN' ) ) ) ) : break if ( ch [ 2 ] . endswith ( u'PP' ) and pp ) : ch [ ( - 1 ) ] = u'I-PNP' if ( not ch [ 2 ] . endswith ( u'PP' ) ) : ch [ ( - 1 ) ] = u'I-PNP' pp = False return chunked
the input is a list of [token .