pick_ngrams: add param how_many + type checks
also add a test string test_str
This commit is contained in:
parent
294c16c110
commit
b56662dd87
@ -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")
|
||||
|
Reference in New Issue
Block a user