add a "try" wrapper for when getting probabs

This commit is contained in:
surtur 2021-12-20 01:36:44 +01:00
parent 789ccd5856
commit f09d4177c7
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D

@ -104,9 +104,13 @@ class da_detector:
# may contain None values if not found, hence uncleansed # may contain None values if not found, hence uncleansed
uncleansed_probabilities = [] uncleansed_probabilities = []
for ngram in ngrams: try:
uncleansed_probabilities.append(lang_probs.get(ngram)) for ngram in ngrams:
return self.replace_nones(uncleansed_probabilities) uncleansed_probabilities.append(lang_probs.get(ngram))
cleansed_probabs = self.replace_nones(uncleansed_probabilities)
except Exception as e:
raise e
return cleansed_probabs
def replace_nones(self, probabilities: list): def replace_nones(self, probabilities: list):
if not isinstance(probabilities, list): if not isinstance(probabilities, list):