#NEWLINE# def demo( ) : #NEWLINE# #INDENT# 'This assumes the Python module bllipparser is installed.' #NEWLINE# from nltk.data import find #NEWLINE# model_dir = find ( 'models/bllip_wsj_no_aux' ) . path #NEWLINE# print ( 'Loading BLLIP Parsing models...' ) #NEWLINE# bllip = BllipParser . from_unified_model_dir ( model_dir ) #NEWLINE# print ( 'Done.' ) #NEWLINE# sentence1 = 'British left waffles on Falklands .' . split ( ) #NEWLINE# sentence2 = 'I saw the man with the telescope .' . split ( ) #NEWLINE# fail1 = '# ! ? : -' . split ( ) #NEWLINE# for sentence in ( sentence1 , sentence2 , fail1 ) : #NEWLINE# #INDENT# print ( ( 'Sentence: %r' % ' ' . join ( sentence ) ) ) #NEWLINE# try : #NEWLINE# #INDENT# tree = next ( bllip . parse ( sentence ) ) #NEWLINE# print ( sentence ) #NEWLINE# #UNINDENT# except StopIteration : #NEWLINE# #INDENT# print ( '(parse failed)' ) #NEWLINE# #UNINDENT# #UNINDENT# for ( i , parse ) in enumerate ( bllip . parse ( sentence1 ) ) : #NEWLINE# #INDENT# print ( ( 'parse %d:\n%s' % ( i , parse ) ) ) #NEWLINE# #UNINDENT# print ( "forcing 'tree' to be 'NN':" , next ( bllip . tagged_parse ( [ ( 'A' , None ) , ( 'tree' , 'NN' ) ] ) ) ) #NEWLINE# print ( "forcing 'A' to be 'DT' and 'tree' to be 'NNP':" , next ( bllip . tagged_parse ( [ ( 'A' , 'DT' ) , ( 'tree' , 'NNP' ) ] ) ) ) #NEWLINE# print ( "forcing 'A' to be 'NNP':" , next ( bllip . tagged_parse ( [ ( 'A' , 'NNP' ) , ( 'tree' , None ) ] ) ) )