add what_this method that interfaces with the user
This commit is contained in:
parent
bd1755d745
commit
94dc7cf46f
@ -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
|
||||
|
Reference in New Issue
Block a user