From b56662dd8760bd62228d92b172716663ea4bb77a Mon Sep 17 00:00:00 2001 From: surtur Date: Fri, 17 Dec 2021 17:24:04 +0100 Subject: [PATCH] pick_ngrams: add param how_many + type checks also add a test string test_str --- da_detector.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/da_detector.py b/da_detector.py index 2e9860c..0cd1eea 100755 --- a/da_detector.py +++ b/da_detector.py @@ -45,23 +45,31 @@ class da_detector: raise e return obj - def pick_ngrams(self, what_grams: int, text: str): + def pick_ngrams(self, what_grams: int, how_many: int, text: str): if not isinstance(what_grams, int): raise TypeError("what_grams has to be an int") - - self.what_grams = what_grams + if not isinstance(how_many, int): + raise TypeError("how_many has to be an int") + if not isinstance(text, str): + raise TypeError("text has to be a str") if (what_grams <= 0): raise ValueError("this is bogus, give me a number from ℕ") elif (what_grams > 5): raise ValueError("not doing larger-grams than 5") + if (how_many <= 0): + raise ValueError("how_many ought to be larger than 0") + if (len(text) <= 10): + raise ValueError("not doing anything with text shorter than 10 characters") # TODO(me): complete n-gram picking method implementation freqs_folder = "./freqs/" +test_str = "what freaking ever, nobody cares one bit of a heck" + detector = da_detector() -detector.pick_ngrams(3, "") +detector.pick_ngrams(3, 10, test_str) sk_json = detector.parse_freqs("sk.json") cz_json = detector.parse_freqs("cz.json")