#NEWLINE# def plaintext( ) : #NEWLINE# #INDENT# def ImportPlaintext( dataset_id , plaintext_filename ) : #NEWLINE# #INDENT# dataset_path = '{}/data/{}' . format ( request . folder , dataset_id ) #NEWLINE# if ( not os . path . exists ( dataset_path ) ) : #NEWLINE# #INDENT# os . makedirs ( dataset_path ) #NEWLINE# #UNINDENT# with Corpus_DB ( path = dataset_path , isImport = True ) as corpus_db : #NEWLINE# #INDENT# corpus_db . ImportFromFile ( plaintext_filename ) #NEWLINE# #UNINDENT# #UNINDENT# form = FORM ( 'Corpus name: ' , INPUT ( _name = 'name' , _type = 'textarea' , requires = IS_NOT_EMPTY ( ) ) , 'Corpus (one document per line):' , BR ( ) , TEXTAREA ( _name = 'corpus' , value = '' , requires = IS_NOT_EMPTY ( ) ) , INPUT ( _type = 'submit' ) ) #NEWLINE# def process_upload( form ) : #NEWLINE# #INDENT# upload = form . vars . corpus #NEWLINE# ptext = [ ] #NEWLINE# ssheet = [ [ 'doc_id' , 'doc_content' ] ] #NEWLINE# for ( n , line ) in enumerate ( upload . split ( '\n' ) ) : #NEWLINE# #INDENT# ptext . append ( ( ( str ( n ) + ' ' ) + line . strip ( ) ) ) #NEWLINE# ssheet . append ( { #NEWLINE# #INDENT# 'doc_id' : str ( n ) , #NEWLINE# 'doc_content' : line . strip ( ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# return ( ssheet , '\n' . join ( ptext ) ) #NEWLINE# #UNINDENT# return generic_input ( request , form , form )