#NEWLINE# def demo( ) : #NEWLINE# #INDENT# import nltk #NEWLINE# from nltk.corpus.util import LazyCorpusLoader #NEWLINE# root = nltk . data . find ( 'corpora/knbc/corpus1' ) #NEWLINE# fileids = [ f for f in find_corpus_fileids ( FileSystemPathPointer ( root ) , '.*' ) if re . search ( '\\d\\-\\d\\-[\\d]+\\-[\\d]+' , f ) ] #NEWLINE# def _knbc_fileids_sort( x ) : #NEWLINE# #INDENT# cells = x . split ( '-' ) #NEWLINE# return ( cells [ 0 ] , int ( cells [ 1 ] ) , int ( cells [ 2 ] ) , int ( cells [ 3 ] ) ) #NEWLINE# #UNINDENT# knbc = LazyCorpusLoader ( 'knbc/corpus1' , KNBCorpusReader , sorted ( fileids , key = _knbc_fileids_sort ) , encoding = 'euc-jp' ) #NEWLINE# print ( knbc . fileids ( ) [ : 10 ] ) #NEWLINE# print ( '' . join ( knbc . words ( ) [ : 100 ] ) ) #NEWLINE# print ( '\n\n' . join ( ( str ( tree ) for tree in knbc . parsed_sents ( ) [ : 2 ] ) ) ) #NEWLINE# knbc . morphs2str = ( lambda morphs : '/' . join ( ( ( '%s(%s)' % ( m [ 0 ] , m [ 1 ] . split ( ' ' ) [ 2 ] ) ) for m in morphs if ( m [ 0 ] != 'EOS' ) ) ) . encode ( 'utf-8' ) ) #NEWLINE# print ( '\n\n' . join ( ( ( '%s' % tree ) for tree in knbc . parsed_sents ( ) [ : 2 ] ) ) ) #NEWLINE# print ( '\n' . join ( ( ' ' . join ( ( ( '%s/%s' % ( w [ 0 ] , w [ 1 ] . split ( ' ' ) [ 2 ] ) ) for w in sent ) ) for sent in knbc . tagged_sents ( ) [ 0 : 2 ] ) ) )