Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -170,23 +170,25 @@ def get_recognizers(
if language == rec.supported_language
]
else:
all_entity_recognizers = dict()
for rec in all_possible_recognizers:
if language == rec.supported_language:
if type(rec.supported_entities) == list and len(rec.supported_entities) > 0:
for supported_entity in rec.supported_entities:
self.add_recognizer_map(all_entity_recognizers, supported_entity, rec)
elif type(rec.supported_entities) == str:
self.add_recognizer_map(all_entity_recognizers, rec.supported_entities, rec)

for entity in entities:
subset = [
rec
for rec in all_possible_recognizers
if entity in rec.supported_entities
and language == rec.supported_language
]

if not subset:
if entity not in all_entity_recognizers:
logger.warning(
"Entity %s doesn't have the corresponding"
" recognizer in language : %s",
entity,
language,
)
else:
to_return.update(set(subset))
to_return.update(all_entity_recognizers[entity])

logger.debug(
"Returning a total of %s recognizers",
Expand All @@ -198,6 +200,12 @@ def get_recognizers(

return list(to_return)

def add_recognizer_map(self, all_entity_recognizers, supported_entity, rec):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please make this private + add type hints?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if supported_entity in all_entity_recognizers:
all_entity_recognizers[supported_entity].add(rec)
else:
all_entity_recognizers[supported_entity] = {rec}

def add_recognizer(self, recognizer: EntityRecognizer) -> None:
"""
Add a new recognizer to the list of recognizers.
Expand Down
Loading