From bda5b336ed15d1660d86cdd99e4bdb2badf43cf9 Mon Sep 17 00:00:00 2001 From: surtur Date: Mon, 20 Dec 2021 01:48:05 +0100 Subject: [PATCH] add gimme_probabs_multi_lang this method operates on a list of language probability dictionaries, passes most of the parameters to other instance methods defined earlier --- da_detector.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/da_detector.py b/da_detector.py index 4b4013e..945f749 100755 --- a/da_detector.py +++ b/da_detector.py @@ -120,6 +120,31 @@ class da_detector: # a pretty good bogus probability is a one closeâ„¢ reasonably to zero return [0.000000123 if n is None else n for n in probabilities] + # return proper probabilities for multiple languages + def gimme_probabs_multi_lang( + self, + langs: list, + txt: str, + what_grams: int, + how_many: int + ): + if len(langs) == 0: + # fallback + langs = self.langs_to_check + + probabs = [] + try: + for lang in langs: + probabs.append( + self.gimme_probabilities( + lang, + self.pick_ngrams(what_grams, how_many, txt) + ) + ) + except Exception as e: + raise e + return probabs + freqs_folder = "./freqs/" test_str = "what freaking ever, nobody cares one bit of a heck"