def testing_detection_lang(file_name): file = {} file['path'] = f'wordless_tests/files/langs/{file_name}' file['name'] = os.path.basename(file['path']) file['encoding'] = 'utf_8' lang_code, success = wordless_detection.detect_lang(main, file) assert lang_code == file_name.replace('.txt', '') assert success
def _new_file(self, file_path): new_file = {} detection_success_encoding = True detection_success_text_type = True detection_success_lang = True new_file['selected'] = True new_file['path'] = file_path new_file['name'], _ = os.path.splitext( os.path.basename(new_file['path'])) new_file['name_old'] = new_file['name'] # Detect encodings if self.main.settings_custom['files']['auto_detection_settings'][ 'detect_encodings']: (new_file['encoding'], detection_success_encoding) = wordless_detection.detect_encoding( self.main, new_file['path']) else: new_file['encoding'] = self.main.settings_custom['auto_detection'][ 'default_settings']['default_encoding'] # Detect text types if self.main.settings_custom['files']['auto_detection_settings'][ 'detect_text_types']: (new_file['text_type'], detection_success_text_type ) = wordless_detection.detect_text_type(self.main, new_file) else: new_file['text_type'] = self.main.settings_custom[ 'auto_detection']['default_settings']['default_text_type'] # Detect languages if self.main.settings_custom['files']['auto_detection_settings'][ 'detect_langs']: (new_file['lang'], detection_success_lang) = wordless_detection.detect_lang( self.main, new_file) else: new_file['lang'] = self.main.settings_custom['auto_detection'][ 'default_settings']['default_lang'] return (new_file, detection_success_encoding, detection_success_text_type, detection_success_lang)
def detect_lang(file): print(f'Detect the language of file "{file["name"]}": ', end='') lang_code, success = wordless_detection.detect_lang(main, file) print(f"{lang_code} ({'Success' if success else 'Fail'})")