def show_dialog(self): f_name = QFileDialog.getOpenFileName(self, 'Open file', "/home")[0] f_name = f_name.split("/")[-1] finds = find(f_name) self.textEdit.setText(finds) conn = QtSql.QSqlDatabase.addDatabase('QSQLITE') conn.setDatabaseName(finds) if conn.open(): query_table = QtWidgets.QTableView(self.horizontalLayoutWidget) query_table.setObjectName("tableView") self.horizontalLayout.addWidget(query_table) query_model = QtSql.QSqlQueryModel(parent=query_table) query_model.setQuery(f'select * from {self.global_word}') query_table.setModel(query_model) else: # Выводим текст ошибки print(conn.lastError().text())
def get_unique_char_count(inserted_text): char_arr = [0]*255 for char in inserted_text: char_arr[ord(char)] = 1 return sum(char_arr) if __name__ == "__main__" : values, T = initialize() with open('../../../../dataset/edits.csv', 'rb') as csvfile: reader = csv.DictReader(csvfile) for row in reader: oldrevisionid = row['oldrevisionid'] newrevisionid = row['newrevisionid'] old_revision_path = find(oldrevisionid+'.txt', '../../../../dataset/article-revisions/') new_revision_path = find(newrevisionid+'.txt', '../../../../dataset/article-revisions/') old_text = open(old_revision_path,'r').read() new_text = open(new_revision_path,'r').read() inserted_text = diff_inserted_text(old_text,new_text) length = len(inserted_text) if not inserted_text: diversity = 0 else: unique_char_count = get_unique_char_count(inserted_text) # not sure if needed if unique_char_count == 0: diversity = 0 else: diversity = round(pow(len(inserted_text),1.0/unique_char_count),2) values.append(diversity)