Coverage for presidio_analyzer / remote_recognizer.py: 86%

14 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-03-29 09:03 +0000

1from abc import ABC, abstractmethod 

2from typing import TYPE_CHECKING, List, Optional 

3 

4from presidio_analyzer import EntityRecognizer 

5 

6if TYPE_CHECKING: 

7 from presidio_analyzer.nlp_engine import NlpArtifacts 

8 

9 

10class RemoteRecognizer(ABC, EntityRecognizer): 

11 """ 

12 A configuration for a recognizer that runs on a different process / remote machine. 

13 

14 :param supported_entities: A list of entities this recognizer can identify 

15 :param name: name of recognizer 

16 :param supported_language: The language this recognizer can detect entities in 

17 :param version: Version of this recognizer 

18 """ 

19 

20 def __init__( 

21 self, 

22 supported_entities: List[str], 

23 name: Optional[str], 

24 supported_language: str, 

25 version: str, 

26 context: Optional[List[str]] = None, 

27 ): 

28 super().__init__( 

29 supported_entities=supported_entities, 

30 name=name, 

31 supported_language=supported_language, 

32 version=version, 

33 context=context, 

34 ) 

35 

36 def load(self): # noqa: D102 

37 pass 

38 

39 @abstractmethod 

40 def analyze(self, text: str, entities: List[str], nlp_artifacts: "NlpArtifacts"): 

41 """ 

42 Call an external service for PII detection. 

43 

44 :param text: text to be analyzed 

45 :param entities: Entities that should be looked for 

46 :param nlp_artifacts: Additional metadata from the NLP engine 

47 :return: List of identified PII entities 

48 """ 

49 

50 # 1. Call the external service. 

51 # 2. Translate results into List[RecognizerResult] 

52 pass 

53 

54 @abstractmethod 

55 def get_supported_entities(self) -> List[str]: # noqa: D102 

56 pass