pick_ngrams: add param how_many + type checks

also add a test string test_str
This commit is contained in:
surtur 2021-12-17 17:24:04 +01:00
parent 294c16c110
commit b56662dd87
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D

@ -45,23 +45,31 @@ class da_detector:
raise e raise e
return obj 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): if not isinstance(what_grams, int):
raise TypeError("what_grams has to be an int") raise TypeError("what_grams has to be an int")
if not isinstance(how_many, int):
self.what_grams = what_grams 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): if (what_grams <= 0):
raise ValueError("this is bogus, give me a number from ") raise ValueError("this is bogus, give me a number from ")
elif (what_grams > 5): elif (what_grams > 5):
raise ValueError("not doing larger-grams than 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 # TODO(me): complete n-gram picking method implementation
freqs_folder = "./freqs/" freqs_folder = "./freqs/"
test_str = "what freaking ever, nobody cares one bit of a heck"
detector = da_detector() detector = da_detector()
detector.pick_ngrams(3, "") detector.pick_ngrams(3, 10, test_str)
sk_json = detector.parse_freqs("sk.json") sk_json = detector.parse_freqs("sk.json")
cz_json = detector.parse_freqs("cz.json") cz_json = detector.parse_freqs("cz.json")