You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Ad-hoc recognizers are not asked for their own entities when entities is omitted #2425
Describe the bug
When AnalyzerEngine.analyze is called without entities, it builds the entity list from the registry only (self.get_supported_entities(language)) and passes that list to every recognizer, including the ad-hoc ones. An ad-hoc recognizer that filters its output by the entities argument never sees its own entity names, so it returns nothing.
PatternRecognizer ignores the entities argument, so ad-hoc pattern and deny-list recognizers are not affected. Recognizers that honor the argument are, for example GLiNERRecognizer (if entities and presidio_entity not in entities: continue), LMRecognizer subclasses (requested_entities = [e for e in entities if e in self.supported_entities]) and custom EntityRecognizer subclasses that follow the analyze(text, entities, nlp_artifacts) contract.
Passing the same recognizer with entities=["AD_HOC_ENTITY"] works, so the result depends on whether the caller lists entities explicitly.
To reproduce
fromtypingimportListfrompresidio_analyzerimportAnalyzerEngine, EntityRecognizer, RecognizerResultclassAdHocRecognizer(EntityRecognizer):
def__init__(self):
super().__init__(supported_entities=["AD_HOC_ENTITY"])
defload(self):
passdefanalyze(self, text: str, entities: List[str], nlp_artifacts=None):
if"AD_HOC_ENTITY"notinentities:
return []
return [RecognizerResult("AD_HOC_ENTITY", 0, 4, 0.8)]
analyzer=AnalyzerEngine()
print(analyzer.analyze("John lives here", language="en",
ad_hoc_recognizers=[AdHocRecognizer()]))
# AD_HOC_ENTITY is missing from the resultsprint(analyzer.analyze("John lives here", language="en",
ad_hoc_recognizers=[AdHocRecognizer()],
entities=["AD_HOC_ENTITY"]))
# AD_HOC_ENTITY is returned
Expected behavior
With entities omitted, every recognizer is asked for all entities supported by the recognizers used in the request, ad-hoc ones included, so the first call also returns AD_HOC_ENTITY.
Activity