add attempt_detection method
This commit is contained in:
parent
96bca80d1a
commit
695e700e35
@ -150,6 +150,50 @@ class da_detector:
|
||||
raise e
|
||||
return probabs
|
||||
|
||||
def attempt_detection(self, probabs: list, lang_list: list):
|
||||
import numpy as np
|
||||
|
||||
if not isinstance(probabs, list) or not isinstance(lang_list, list):
|
||||
raise TypeError("not a list, bailing")
|
||||
elif len(probabs) == 0 or len(lang_list) == 0:
|
||||
raise ValueError("empty list, bailing")
|
||||
|
||||
sums = []
|
||||
absolute_sums = []
|
||||
what_we_came_up_with = []
|
||||
|
||||
try:
|
||||
for probab in probabs:
|
||||
sums.append(np.sum(np.log(probab)))
|
||||
|
||||
for da_sum in sums:
|
||||
absolute_sums.append(1 / abs(da_sum))
|
||||
|
||||
for da_abs_sum in absolute_sums:
|
||||
what_we_came_up_with.append(da_abs_sum / sum(absolute_sums))
|
||||
except Exception as e:
|
||||
raise e
|
||||
|
||||
print("[*] languages considered: ", end="")
|
||||
print(lang_list)
|
||||
print("[*] probabilities: ", end="")
|
||||
print(what_we_came_up_with)
|
||||
max_prob = max(what_we_came_up_with)
|
||||
|
||||
try:
|
||||
final_results = {}
|
||||
for i in range(len(lang_list)):
|
||||
final_results.__setitem__(
|
||||
lang_list[i],
|
||||
what_we_came_up_with[i]
|
||||
)
|
||||
da_winner = max(final_results, key=final_results.get)
|
||||
except Exception as e:
|
||||
raise e
|
||||
print("[*] the winner is: " + da_winner + " with probability ", end="")
|
||||
print(max_prob)
|
||||
return final_results
|
||||
|
||||
|
||||
freqs_folder = "./freqs/"
|
||||
test_str = "what freaking ever, nobody cares one bit of a heck"
|
||||
|
Reference in New Issue
Block a user