in presidio-analyzer/presidio_analyzer/nlp_engine/nlp_engine_provider.py [0:0]
def create_engine(self) -> NlpEngine:
"""Create an NLP engine instance."""
if (
not self.nlp_configuration
or not self.nlp_configuration.get("models")
or not self.nlp_configuration.get("nlp_engine_name")
):
raise ValueError(
"Illegal nlp configuration. "
"Configuration should include nlp_engine_name and models "
"(list of model_name for each lang_code)."
)
try:
nlp_engine_name = self.nlp_configuration["nlp_engine_name"]
nlp_engine_class = self.nlp_engines[nlp_engine_name]
nlp_engine_opts = {
m["lang_code"]: m["model_name"]
for m in self.nlp_configuration["models"]
}
engine = nlp_engine_class(nlp_engine_opts)
logger.info(
f"Created NLP engine: {engine.engine_name}. "
f"Loaded models: {list(engine.nlp.keys())}"
)
return engine
except KeyError:
raise ValueError("Wrong NLP engine configuration")