def get_language_words(search, language): # Retourne la liste des mots candidat correspondant au langage # Les mots sont stockés dans un fichier de ce type : ./language_words/[language].words language_file = path.join(epp.getcwd(), "language_words", language + ".words") if path.exists(language_file): epp.log("language file Ok : %s" % language_file) candidates = Candidate.Candidates() r1 = get_regex(search) # Parcours du fichier du langage pour trouver les candidats with open(language_file, "r") as fileh: for match in [r1.findall(l) for l in fileh]: candidates.extend(match, is_language_word=True) return set(candidates.get_list()) else: return set()
def get_language(forced_language, filetype): if forced_language != None: epp.log("Use options.language: {0}".format(forced_language)) return forced_language else: epp.log("Scan filetypes for extensions {0}".format(filetype)) language = None config_file = path.join(epp.getcwd(), "language_words", "filetypes.txt") if filetype != '' and path.exists(config_file): r = re.compile(r"^(?:\w+;)*{0}\S*\t(?P<language>\w+)".format(filetype), re.IGNORECASE) with open(config_file, "r") as f: for l in f: match = r.search(l) if match: language = match.group("language") epp.log("language found: {0}".format(language)) break return language