def _is_match(tagged_phrase, cfg):
 copy = list(tagged_phrase)
 merge = True
 while merge:
  merge = False
  for i in range((len(copy) - 1)):
   (first, second) = (copy[i], copy[(i + 1)])
   key = (first[1], second[1])
   value = cfg.get(key, None)
   if value:
    merge = True
    copy.pop(i)
    copy.pop(i)
    match = u'{0} {1}'.format(first[0], second[0])
    pos = value
    copy.insert(i, (match, pos))
    break
 match = any([(t[1] in (u'NNP', u'NNI')) for t in copy])
 return match

def _is_match ( tagged_phrase , cfg ) : copy = list ( tagged_phrase ) merge = True while merge : merge = False for i in range ( ( len ( copy ) - 1 ) ) : ( first , second ) = ( copy [ i ] , copy [ ( i + 1 ) ] ) key = ( first [ 1 ] , second [ 1 ] ) value = cfg . get ( key , None ) if value : merge = True copy . pop ( i ) copy . pop ( i ) match = u'{0} {1}' . format ( first [ 0 ] , second [ 0 ] ) pos = value copy . insert ( i , ( match , pos ) ) break match = any ( [ ( t [ 1 ] in ( u'NNP' , u'NNI' ) ) for t in copy ] ) return match
return whether or not a tagged phrases matches a context-free grammar .