def build_db(self) -> None: """Rebuilds the pickle database""" _("Build DB started") all = all_words() _(all) for key in all.keys(): for wrd in all[key]: self.word_signature(wrd) self.save_state()
def all_words(self, value) -> bool: self.sample = value try: self.__all_words() except NotFound: _("Sample was not a sentence") return False except Found as f: _("Found: ", f.value) return True
def bifid_key(letters): AB = letters.upper().replace("J", "I").replace(" ", "") + alphabet(True).replace("J", "") _(AB) ret = "" for l in AB: if l in ret: continue ret += l _(ret) return ret
def char_frequency(value, remove_whitespace=True, ignore_case=True) -> dict: """Calculates the char frequency of a word and returns a dict""" frequency_matrix = {} wurth = value if ignore_case: wurth = wurth.upper() if remove_whitespace: wurth = PAT_NON_ALPHANUMERIC.sub("", wurth) for n in wurth: keys = frequency_matrix.keys() if n in keys: frequency_matrix[n] += 1 else: frequency_matrix[n] = 1 _("created char_frequency for word {} : {}".format(value, frequency_matrix)) return frequency_matrix
def all_words(): woorden_ = { '2': met_lengte(2), '3': met_lengte(3), '4': met_lengte(4), '5': met_lengte(5), '6': met_lengte(6), '7': met_lengte(7), '8': met_lengte(8), '9': met_lengte(9), 'OpenTaal_1': open_taal_woorden_1(), 'OpenTaal_2': open_taal_woorden_2(), 'OpenTaal_flexie': open_taal_woorden_flexie(), 'mijn_woorden': mijn_woorden(), 'dutch': dutch(), 'wilhelmus_orig': wilhelmus_orig(), 'wilhelmus_modern': wilhelmus_modern(), 'straat_taal': txt_file_upper_lines("straat_taal_woorden.txt"), } _(woorden_) return woorden_
def by_len_and_containing_letters(self, length, containing, not_containing=None): """find all words of a length and containing all the letters provided. So there should be equal or less letters given then the length. if not_containing is provided it will also check that none of those letters are in the word """ if length < len(containing): _("The number of letters that have to exists are more then the length asked for." ) return [] def has_letters(word, letters): ret = word for letter in letters: if letter not in ret: return False else: ret = ret.replace(letter, "", 1) return True def not_has_letters(word, letters): for letter in word: if letter in letters: return False return True if not_containing: return [ x for x in self.by_len(length) if has_letters(x, containing.upper()) and not_has_letters(x, not_containing.upper()) ] return [ x for x in self.by_len(length) if has_letters(x, containing.upper()) ]
def __all_words(self, value=None): if value: ret = value else: ret = self.sample for idx in range(len(ret), 1, -1): wrd = ret[0:idx] if self.wb.is_word(wrd): _(wrd) new_wrd = ret[idx:] if len(new_wrd) == 0: _(self.sample) raise Found(self.sample) self.__all_words(new_wrd) else: _(idx, wrd) if idx == 2: raise NotFound()
"?": "..--..", "!": "-.-.--", "-": "-....-", "/": "-..-.", ":": "---...", "'": ".----.", ")": "-.--.-", ";": "-.-.-", "(": "-.--.", "=": "-...-", "@": ".--.-.", "&": ".–..." } alphabet_morse = reverse_dict(morse_alphabet) _(alphabet_morse) def text_2_morse(txt, delimiter=" ") -> str: """ # Text 2 Morse code This function will translate standard text to morse code. """ answer = "" for x in txt.upper(): answer += morse_alphabet[x] answer += delimiter return answer