add attempt_detection method

This commit is contained in:
surtur 2021-12-20 04:32:45 +01:00
parent 96bca80d1a
commit 695e700e35
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D

@ -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"