From 94dc7cf46f59f1f3219de0cdc521bc9c52f4f614 Mon Sep 17 00:00:00 2001 From: surtur Date: Mon, 20 Dec 2021 04:53:07 +0100 Subject: [PATCH] add what_this method that interfaces with the user --- da_detector.py | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/da_detector.py b/da_detector.py index d2b69b5..5ca86e1 100755 --- a/da_detector.py +++ b/da_detector.py @@ -195,9 +195,51 @@ class da_detector: print(max_prob) return final_results + # this is the method that pulls it all together + def what_this(self, unknown_text: str, langs_to_check: list): + if not isinstance(unknown_text, str): + raise TypeError("not a string, bailing") + if not isinstance(langs_to_check, list): + raise TypeError("not a list, bailing") -test_str = "what freaking ever, nobody cares one bit of a heck" + if (len(unknown_text) <= 10): + raise ValueError("not doing anything with text shorter than 10 characters") + if len(langs_to_check) == 0: + print("[i] since no lang preference was provided we are falling " + + "back to picking from ", end="") + print(self.langs_to_check) + print() + langs_to_check = self.langs_to_check + elif (langs_to_check == 1): + raise ValueError("at least two languages are needed") -detector = da_detector() + print("[*] unknown text about to be checked:") + print(unknown_text) + print() + + the_real_langs_to_check = [] + try: + # a naïve approach, works for this project + for lang in langs_to_check: + the_real_langs_to_check.append( + self.parse_freqs(lang + ".json") + ) + except Exception as e: + raise e + + try: + multi_lang_probabs = self.gimme_probabs_multi_lang( + the_real_langs_to_check, + unknown_text, self.what_grams, self.how_many + ) + + res = self.attempt_detection(multi_lang_probabs, langs_to_check) + print("[*] recap: ", end="") + print(res) + print() + except Exception as e: + raise e + + return # vim: ff=unix noexpandtab