Пример #1
0
def check_load_file(filename, files):
    if not os.path.exists(filename) or not os.path.isfile(filename): 
        print 'Error can not find the specified file'
        return

    filetype = filename.split('.')[1]
    
    if filetype == 'csv':
        csv_data = CSVData(filename)
        csv_data.parse_vectors()
        files.append(csv_data)
    elif filetype == 'txt':
        txt_data = TXTData(filename)
        txt_data.read_document()
        files.append(txt_data)
    else:
        print 'Error unrecognized file type ', filetype
        return

    print 'Parsed file: ', filename 
Пример #2
0
 def restore_state(self):
     if self.params_set == False:
         print "Error connection parameters not set"
         return None
     else:
         statment = "SELECT id, text, words FROM documents"
         self.cursor.execute(statment)
         rows = self.cursor.fetchall()
         ndict = {}
         
         data = JokerData("no.fn")
         for row in rows:
             txt = TXTData("no.fn")
             txt.set_text(row[1])
             txt.set_words(row[2].split(' ')) 
             txt.unique_word_frequency()
             ndict[row[0]] = txt 
         data.set_docs(ndict)
         return data