Skip to content
Snippets Groups Projects
Commit ebfa99fc authored by Paweł Walkowiak's avatar Paweł Walkowiak
Browse files

Add checks

parent 0af138c0
1 merge request!13Fix anonymizer errors
Pipeline #15187 passed with stages
in 1 minute and 38 seconds
......@@ -191,11 +191,19 @@ class NERFileMorphosyntacticDictionary(MorphosyntacticDictionary):
original_entries
)
possible_lemmas = set(self._dictionary[detection_type][required_tags[0]].keys())
possible_lemmas = set(
self._dictionary[detection_type][required_tags[0]].keys()
) \
if detection_type in self._dictionary \
and required_tags[0] in self._dictionary[detection_type] \
else set()
for tag in required_tags[1:]:
possible_lemmas.intersection_update(
self._dictionary[detection_type][tag].keys()
)
keys = self._dictionary[detection_type][tag].keys() \
if detection_type in self._dictionary \
and tag in self._dictionary[detection_type] \
else set()
if keys:
possible_lemmas.intersection_update(keys)
if len(possible_lemmas) == 0:
return [self.get_random_replacement(original_entries[0])] * len(
......@@ -208,7 +216,13 @@ class NERFileMorphosyntacticDictionary(MorphosyntacticDictionary):
for entry in original_entries:
if isinstance(entry, MorphosyntacticInfoMixin):
morpho_tag = entry.morpho_tag
word = self._dictionary[detection_type][morpho_tag][lemma]
if detection_type in self._dictionary \
and morpho_tag in self._dictionary[detection_type] \
and lemma in \
self._dictionary[detection_type][morpho_tag]:
word = self._dictionary[detection_type][morpho_tag][lemma]
else:
word = lemma
else:
word = lemma
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment