-
I'm trying to create a basic zip code recognition for spanish language, from presidio_analyzer import AnalyzerEngine, PatternRecognizer, EntityRecognizer, Pattern, RecognizerResult from presidio_anonymizer import AnonymizerEngine Create configuration containing engine name and modelsconfiguration = { Create NLP engine based on configurationprovider = NlpEngineProvider(nlp_configuration=configuration) Pass the created NLP engine and supported_languages to the AnalyzerEngineanalyzer = AnalyzerEngine( Define the regex patternregex = r"(\b\d{5}(?:-\d{4})?\b)" # very weak regex pattern Define the recognizer with the defined patterncp_recognizer = PatternRecognizer(supported_entity="ES_ZIP_CODE", registry = RecognizerRegistry() Testcp_result = analyzer.analyze(text="Mi CP es 28001.", entities=["ES_ZIP_CODE"], language='es') KeyError Traceback (most recent call last) ~\anaconda3\envs\Presidio\lib\site-packages\presidio_analyzer\analyzer_engine.py in analyze(self, text, language, entities, correlation_id, score_threshold, return_decision_process, ad_hoc_recognizers) ~\anaconda3\envs\Presidio\lib\site-packages\presidio_analyzer\nlp_engine\spacy_nlp_engine.py in process_text(self, text, language) KeyError: 'es' |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @Idomingog, from a first glance it appears like you create the AnalyzerEngine object twice. Once with the nlp engine and then with the registry. Try this : registry = RecognizerRegistry()
registry.add_recognizer(cp_recognizer)
analyzer = AnalyzerEngine(
nlp_engine=nlp_engine_with_spanish,
registry=registry,
supported_languages=["en", "es"]
) |
Beta Was this translation helpful? Give feedback.
Hi @Idomingog, from a first glance it appears like you create the AnalyzerEngine object twice. Once with the nlp engine and then with the registry.
Try this :