Presidio Analyzer API Reference
Objects at the top of the presidio-analyzer package
presidio_analyzer.AnalyzerEngine
Entry point for Presidio Analyzer.
Orchestrating the detection of PII entities and all related logic.
| PARAMETER | DESCRIPTION |
|---|---|
registry
|
instance of type RecognizerRegistry
TYPE:
|
nlp_engine
|
instance of type NlpEngine (for example SpacyNlpEngine)
TYPE:
|
app_tracer
|
instance of type AppTracer, used to trace the logic used during each request for interpretability reasons.
TYPE:
|
log_decision_process
|
bool, defines whether the decision process within the analyzer should be logged or not.
TYPE:
|
default_score_threshold
|
Minimum confidence value for detected entities to be returned
TYPE:
|
supported_languages
|
List of possible languages this engine could be run on. Used for loading the right NLP models and recognizers for these languages.
TYPE:
|
context_aware_enhancer
|
instance of type ContextAwareEnhancer for enhancing confidence score based on context words, (LemmaContextAwareEnhancer will be created by default if None passed)
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
get_recognizers |
Return a list of PII recognizers currently loaded. |
get_supported_entities |
Return a list of the entities that can be detected. |
analyze |
Find PII entities in text using different PII recognizers for a given language. |
Source code in presidio_analyzer/analyzer_engine.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 | |
get_recognizers
get_recognizers(language: Optional[str] = None) -> List[EntityRecognizer]
Return a list of PII recognizers currently loaded.
| PARAMETER | DESCRIPTION |
|---|---|
language
|
Return the recognizers supporting a given language.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[EntityRecognizer]
|
List of [Recognizer] as a RecognizersAllResponse |
Source code in presidio_analyzer/analyzer_engine.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
get_supported_entities
get_supported_entities(language: Optional[str] = None) -> List[str]
Return a list of the entities that can be detected.
| PARAMETER | DESCRIPTION |
|---|---|
language
|
Return only entities supported in a specific language.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
List of entity names |
Source code in presidio_analyzer/analyzer_engine.py
136 137 138 139 140 141 142 143 144 145 146 147 148 | |
analyze
analyze(
text: str,
language: str,
entities: Optional[List[str]] = None,
correlation_id: Optional[str] = None,
score_threshold: Optional[float] = None,
return_decision_process: Optional[bool] = False,
ad_hoc_recognizers: Optional[List[EntityRecognizer]] = None,
context: Optional[List[str]] = None,
allow_list: Optional[List[str]] = None,
allow_list_match: Optional[str] = "exact",
regex_flags: Optional[int] = re.DOTALL | re.MULTILINE | re.IGNORECASE,
nlp_artifacts: Optional[NlpArtifacts] = None,
) -> List[RecognizerResult]
Find PII entities in text using different PII recognizers for a given language.
:Example:
from presidio_analyzer import AnalyzerEngine
# Set up the engine, loads the NLP module (spaCy model by default)
# and other PII recognizers
analyzer = AnalyzerEngine()
# Call analyzer to get results
results = analyzer.analyze(text='My phone number is 212-555-5555', entities=['PHONE_NUMBER'], language='en')
print(results)
| PARAMETER | DESCRIPTION |
|---|---|
text
|
the text to analyze
TYPE:
|
language
|
the language of the text
TYPE:
|
entities
|
List of PII entities that should be looked for in the text. If entities=None then all entities are looked for.
TYPE:
|
correlation_id
|
cross call ID for this request
TYPE:
|
score_threshold
|
A minimum value for which to return an identified entity
TYPE:
|
return_decision_process
|
Whether the analysis decision process steps returned in the response.
TYPE:
|
ad_hoc_recognizers
|
List of recognizers which will be used only for this specific request.
TYPE:
|
context
|
List of context words to enhance confidence score if matched with the recognized entity's recognizer context
TYPE:
|
allow_list
|
List of words that the user defines as being allowed to keep in the text
TYPE:
|
allow_list_match
|
How the allow_list should be interpreted; either as "exact" or as "regex".
- If
TYPE:
|
regex_flags
|
regex flags to be used for when allow_list_match is "regex"
TYPE:
|
nlp_artifacts
|
precomputed NlpArtifacts
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
an array of the found entities in the text |
Source code in presidio_analyzer/analyzer_engine.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | |
presidio_analyzer.analyzer_engine_provider.AnalyzerEngineProvider
Utility function for loading Presidio Analyzer.
Use this class to load presidio analyzer engine from a yaml file
| PARAMETER | DESCRIPTION |
|---|---|
analyzer_engine_conf_file
|
the path to the analyzer configuration file
TYPE:
|
nlp_engine_conf_file
|
the path to the nlp engine configuration file
TYPE:
|
recognizer_registry_conf_file
|
the path to the recognizer registry configuration file
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
get_configuration |
Retrieve analyzer engine configuration from the provided file. |
create_engine |
Load Presidio Analyzer from yaml configuration file. |
Source code in presidio_analyzer/analyzer_engine_provider.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
get_configuration
get_configuration(
conf_file: Optional[Union[Path, str]],
) -> Union[Dict[str, Any]]
Retrieve analyzer engine configuration from the provided file.
Source code in presidio_analyzer/analyzer_engine_provider.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
create_engine
create_engine() -> AnalyzerEngine
Load Presidio Analyzer from yaml configuration file.
| RETURNS | DESCRIPTION |
|---|---|
AnalyzerEngine
|
analyzer engine initialized with yaml configuration |
Source code in presidio_analyzer/analyzer_engine_provider.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | |
presidio_analyzer.analysis_explanation.AnalysisExplanation
Hold tracing information to explain why PII entities were identified as such.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer
|
name of recognizer that made the decision
TYPE:
|
original_score
|
recognizer's confidence in result
TYPE:
|
pattern_name
|
name of pattern (if decision was made by a PatternRecognizer)
TYPE:
|
pattern
|
regex pattern that was applied (if PatternRecognizer)
TYPE:
|
validation_result
|
result of a validation (e.g. checksum)
TYPE:
|
textual_explanation
|
Free text for describing a decision of a logic or model
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
set_improved_score |
Update the score and calculate the difference from the original score. |
set_supportive_context_word |
Set the context word which helped increase the score. |
append_textual_explanation_line |
Append a new line to textual_explanation field. |
to_dict |
Serialize self to dictionary. |
Source code in presidio_analyzer/analysis_explanation.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
set_improved_score
set_improved_score(score: float) -> None
Update the score and calculate the difference from the original score.
Source code in presidio_analyzer/analysis_explanation.py
43 44 45 46 | |
set_supportive_context_word
set_supportive_context_word(word: str) -> None
Set the context word which helped increase the score.
Source code in presidio_analyzer/analysis_explanation.py
48 49 50 | |
append_textual_explanation_line
append_textual_explanation_line(text: str) -> None
Append a new line to textual_explanation field.
Source code in presidio_analyzer/analysis_explanation.py
52 53 54 55 56 57 | |
to_dict
to_dict() -> Dict
Serialize self to dictionary.
| RETURNS | DESCRIPTION |
|---|---|
Dict
|
a dictionary |
Source code in presidio_analyzer/analysis_explanation.py
59 60 61 62 63 64 65 | |
presidio_analyzer.recognizer_result.RecognizerResult
Recognizer Result represents the findings of the detected entity.
Result of a recognizer analyzing the text.
| PARAMETER | DESCRIPTION |
|---|---|
entity_type
|
the type of the entity
TYPE:
|
start
|
the start location of the detected entity
TYPE:
|
end
|
the end location of the detected entity
TYPE:
|
score
|
the score of the detection
TYPE:
|
analysis_explanation
|
contains the explanation of why this entity was identified
TYPE:
|
recognition_metadata
|
a dictionary of metadata to be used in recognizer specific cases, for example specific recognized context words and recognizer name
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
append_analysis_explanation_text |
Add text to the analysis explanation. |
to_dict |
Serialize self to dictionary. |
from_json |
Create RecognizerResult from json. |
intersects |
Check if self intersects with a different RecognizerResult. |
contained_in |
Check if self is contained in a different RecognizerResult. |
contains |
Check if one result is contained or equal to another result. |
equal_indices |
Check if the indices are equal between two results. |
has_conflict |
Check if two recognizer results are conflicted or not. |
Source code in presidio_analyzer/recognizer_result.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
append_analysis_explanation_text
append_analysis_explanation_text(text: str) -> None
Add text to the analysis explanation.
Source code in presidio_analyzer/recognizer_result.py
57 58 59 60 | |
to_dict
to_dict() -> Dict
Serialize self to dictionary.
| RETURNS | DESCRIPTION |
|---|---|
Dict
|
a dictionary |
Source code in presidio_analyzer/recognizer_result.py
62 63 64 65 66 67 68 | |
from_json
classmethod
from_json(data: Dict) -> RecognizerResult
Create RecognizerResult from json.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
e.g. { "start": 24, "end": 32, "score": 0.8, "entity_type": "NAME" }
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RecognizerResult
|
RecognizerResult |
Source code in presidio_analyzer/recognizer_result.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
intersects
intersects(other: RecognizerResult) -> int
Check if self intersects with a different RecognizerResult.
| RETURNS | DESCRIPTION |
|---|---|
int
|
If intersecting, returns the number of intersecting characters. If not, returns 0 |
Source code in presidio_analyzer/recognizer_result.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
contained_in
contained_in(other: RecognizerResult) -> bool
Check if self is contained in a different RecognizerResult.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
true if contained |
Source code in presidio_analyzer/recognizer_result.py
108 109 110 111 112 113 114 | |
contains
contains(other: RecognizerResult) -> bool
Check if one result is contained or equal to another result.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
another RecognizerResult
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
bool |
Source code in presidio_analyzer/recognizer_result.py
116 117 118 119 120 121 122 123 | |
equal_indices
equal_indices(other: RecognizerResult) -> bool
Check if the indices are equal between two results.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
another RecognizerResult
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
|
Source code in presidio_analyzer/recognizer_result.py
125 126 127 128 129 130 131 132 | |
has_conflict
has_conflict(other: RecognizerResult) -> bool
Check if two recognizer results are conflicted or not.
I have a conflict if: 1. My indices are the same as the other and my score is lower. 2. If my indices are contained in another.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
RecognizerResult
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
|
Source code in presidio_analyzer/recognizer_result.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
Batch modules
presidio_analyzer.batch_analyzer_engine.BatchAnalyzerEngine
Batch analysis of documents (tables, lists, dicts).
Wrapper class to run Presidio Analyzer Engine on multiple values, either lists/iterators of strings, or dictionaries.
| PARAMETER | DESCRIPTION |
|---|---|
analyzer_engine
|
AnalyzerEngine instance to use for handling the values in those collections.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
analyze_iterator |
Analyze an iterable of strings. |
analyze_dict |
Analyze a dictionary of keys (strings) and values/iterable of values. |
Source code in presidio_analyzer/batch_analyzer_engine.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |
analyze_iterator
analyze_iterator(
texts: Iterable[Union[str, bool, float, int]],
language: str,
batch_size: int = 1,
n_process: int = 1,
**kwargs
) -> List[List[RecognizerResult]]
Analyze an iterable of strings.
| PARAMETER | DESCRIPTION |
|---|---|
texts
|
An list containing strings to be analyzed.
TYPE:
|
language
|
Input language
TYPE:
|
batch_size
|
Batch size to process in a single iteration
TYPE:
|
n_process
|
Number of processors to use. Defaults to
TYPE:
|
kwargs
|
Additional parameters for the
DEFAULT:
|
Source code in presidio_analyzer/batch_analyzer_engine.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
analyze_dict
analyze_dict(
input_dict: Dict[str, Union[Any, Iterable[Any]]],
language: str,
keys_to_skip: Optional[List[str]] = None,
batch_size: int = 1,
n_process: int = 1,
**kwargs
) -> Iterator[DictAnalyzerResult]
Analyze a dictionary of keys (strings) and values/iterable of values.
Non-string values are returned as is.
| PARAMETER | DESCRIPTION |
|---|---|
input_dict
|
The input dictionary for analysis
TYPE:
|
language
|
Input language
TYPE:
|
keys_to_skip
|
Keys to ignore during analysis
TYPE:
|
batch_size
|
Batch size to process in a single iteration
TYPE:
|
n_process
|
Number of processors to use. Defaults to
TYPE:
|
kwargs
|
Additional keyword arguments
for the
DEFAULT:
|
Source code in presidio_analyzer/batch_analyzer_engine.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
presidio_analyzer.dict_analyzer_result.DictAnalyzerResult
dataclass
Data class for holding the output of the Presidio Analyzer on dictionaries.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
key in dictionary
TYPE:
|
value
|
value to run analysis on (either string or list of strings)
TYPE:
|
recognizer_results
|
Analyzer output for one value. Could be either: - A list of recognizer results if the input is one string - A list of lists of recognizer results, if the input is a list of strings. - An iterator of a DictAnalyzerResult, if the input is a dictionary. In this case the recognizer_results would be the iterator of the DictAnalyzerResults next level in the dictionary.
TYPE:
|
Source code in presidio_analyzer/dict_analyzer_result.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |
Recognizers and patterns
presidio_analyzer.entity_recognizer.EntityRecognizer
A class representing an abstract PII entity recognizer.
EntityRecognizer is an abstract class to be inherited by Recognizers which hold the logic for recognizing specific PII entities.
EntityRecognizer exposes a method called enhance_using_context which can be overridden in case a custom context aware enhancement is needed in derived class of a recognizer.
| PARAMETER | DESCRIPTION |
|---|---|
supported_entities
|
the entities supported by this recognizer (for example, phone number, address, etc.)
TYPE:
|
supported_language
|
the language supported by this recognizer. The supported language code is iso6391Name
TYPE:
|
name
|
the name of this recognizer (optional)
TYPE:
|
version
|
the recognizer current version
TYPE:
|
context
|
a list of words which can help boost confidence score when they appear in context of the matched entity
TYPE:
|
country_code
|
Optional ISO 3166-1 alpha-2 country tag. Custom
recognizers may set it per instance; predefined recognizers should
prefer the class-level :attr:
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
load |
Initialize the recognizer assets if needed. |
analyze |
Analyze text to identify entities. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize self to dictionary. |
from_dict |
Create EntityRecognizer from a dict input. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
Source code in presidio_analyzer/entity_recognizer.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
load
abstractmethod
load() -> None
Initialize the recognizer assets if needed.
(e.g. machine learning models)
Source code in presidio_analyzer/entity_recognizer.py
157 158 159 160 161 162 163 | |
analyze
abstractmethod
analyze(
text: str, entities: List[str], nlp_artifacts: NlpArtifacts
) -> List[RecognizerResult]
Analyze text to identify entities.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The text to be analyzed
TYPE:
|
entities
|
The list of entities this recognizer is able to detect
TYPE:
|
nlp_artifacts
|
A group of attributes which are the result of an NLP process over the input text.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List of results detected by this recognizer. |
Source code in presidio_analyzer/entity_recognizer.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize self to dictionary.
| RETURNS | DESCRIPTION |
|---|---|
Dict
|
a dictionary |
Source code in presidio_analyzer/entity_recognizer.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> EntityRecognizer
Create EntityRecognizer from a dict input.
| PARAMETER | DESCRIPTION |
|---|---|
entity_recognizer_dict
|
Dict containing keys and values for instantiation
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
249 250 251 252 253 254 255 256 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
presidio_analyzer.local_recognizer.LocalRecognizer
Bases: ABC, EntityRecognizer
PII entity recognizer which runs on the same process as the AnalyzerEngine.
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
load |
Initialize the recognizer assets if needed. |
analyze |
Analyze text to identify entities. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize self to dictionary. |
from_dict |
Create EntityRecognizer from a dict input. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
Source code in presidio_analyzer/local_recognizer.py
6 7 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
load
abstractmethod
load() -> None
Initialize the recognizer assets if needed.
(e.g. machine learning models)
Source code in presidio_analyzer/entity_recognizer.py
157 158 159 160 161 162 163 | |
analyze
abstractmethod
analyze(
text: str, entities: List[str], nlp_artifacts: NlpArtifacts
) -> List[RecognizerResult]
Analyze text to identify entities.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The text to be analyzed
TYPE:
|
entities
|
The list of entities this recognizer is able to detect
TYPE:
|
nlp_artifacts
|
A group of attributes which are the result of an NLP process over the input text.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List of results detected by this recognizer. |
Source code in presidio_analyzer/entity_recognizer.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize self to dictionary.
| RETURNS | DESCRIPTION |
|---|---|
Dict
|
a dictionary |
Source code in presidio_analyzer/entity_recognizer.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> EntityRecognizer
Create EntityRecognizer from a dict input.
| PARAMETER | DESCRIPTION |
|---|---|
entity_recognizer_dict
|
Dict containing keys and values for instantiation
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
249 250 251 252 253 254 255 256 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
presidio_analyzer.pattern.Pattern
A class that represents a regex pattern.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
the name of the pattern
TYPE:
|
regex
|
the regex pattern to detect
TYPE:
|
score
|
the pattern's strength (values varies 0-1)
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
to_dict |
Turn this instance into a dictionary. |
from_dict |
Load an instance from a dictionary. |
Source code in presidio_analyzer/pattern.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
to_dict
to_dict() -> Dict
Turn this instance into a dictionary.
| RETURNS | DESCRIPTION |
|---|---|
Dict
|
a dictionary |
Source code in presidio_analyzer/pattern.py
41 42 43 44 45 46 47 48 | |
from_dict
classmethod
from_dict(pattern_dict: Dict) -> Pattern
Load an instance from a dictionary.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_dict
|
a dictionary holding the pattern's parameters
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Pattern
|
a Pattern instance |
Source code in presidio_analyzer/pattern.py
50 51 52 53 54 55 56 57 58 | |
presidio_analyzer.pattern_recognizer.PatternRecognizer
Bases: LocalRecognizer
PII entity recognizer using regular expressions or deny-lists.
:attr:EntityRecognizer.COUNTRY_CODE (the canonical path for
predefined recognizers) or per-instance via the country_code
constructor kwarg; see :class:EntityRecognizer for the full
reconciliation rules.
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
A list of patterns to detect
TYPE:
|
deny_list
|
A list of words to detect, in case our recognizer uses a predefined list of words (deny list)
TYPE:
|
context
|
list of context words
TYPE:
|
deny_list_score
|
confidence score for a term identified using a deny-list
TYPE:
|
global_regex_flags
|
regex flags to be used in regex matching, including deny-lists.
TYPE:
|
country_code
|
Optional ISO 3166-1 alpha-2 country tag, forwarded
to :class: Country tagging may be declared at the class level via
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
Source code in presidio_analyzer/pattern_recognizer.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the pattern logic e.g., by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the validation was successful. |
Source code in presidio_analyzer/pattern_recognizer.py
136 137 138 139 140 141 142 143 144 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
presidio_analyzer.remote_recognizer.RemoteRecognizer
Bases: ABC, EntityRecognizer
A configuration for a recognizer that runs on a different process / remote machine.
| PARAMETER | DESCRIPTION |
|---|---|
supported_entities
|
A list of entities this recognizer can identify
TYPE:
|
name
|
name of recognizer
TYPE:
|
supported_language
|
The language this recognizer can detect entities in
TYPE:
|
version
|
Version of this recognizer
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
analyze |
Call an external service for PII detection. |
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize self to dictionary. |
from_dict |
Create EntityRecognizer from a dict input. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
Source code in presidio_analyzer/remote_recognizer.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
analyze
abstractmethod
analyze(text: str, entities: List[str], nlp_artifacts: NlpArtifacts)
Call an external service for PII detection.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
text to be analyzed
TYPE:
|
entities
|
Entities that should be looked for
TYPE:
|
nlp_artifacts
|
Additional metadata from the NLP engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
List of identified PII entities |
Source code in presidio_analyzer/remote_recognizer.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize self to dictionary.
| RETURNS | DESCRIPTION |
|---|---|
Dict
|
a dictionary |
Source code in presidio_analyzer/entity_recognizer.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> EntityRecognizer
Create EntityRecognizer from a dict input.
| PARAMETER | DESCRIPTION |
|---|---|
entity_recognizer_dict
|
Dict containing keys and values for instantiation
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
249 250 251 252 253 254 255 256 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
Recognizer registry modules
presidio_analyzer.recognizer_registry.RecognizerRegistry
Detect, register and hold all recognizers to be used by the analyzer.
| PARAMETER | DESCRIPTION |
|---|---|
recognizers
|
An optional list of recognizers, that will be available instead of the predefined recognizers
TYPE:
|
global_regex_flags
|
regex flags to be used in regex matching, including deny-lists
TYPE:
|
supported_languages
|
List of languages supported by this registry.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
add_nlp_recognizer |
Adding NLP recognizer in accordance with the nlp engine. |
load_predefined_recognizers |
Load the existing recognizers into memory. |
get_nlp_recognizer |
Return the recognizer leveraging the selected NLP Engine. |
get_recognizers |
Return a list of recognizers which supports the specified name and language. |
get_country_codes |
Return the set of country codes currently represented in the registry. |
add_recognizer |
Add a new recognizer to the list of recognizers. |
remove_recognizer |
Remove a recognizer based on its name. |
add_pattern_recognizer_from_dict |
Load a pattern recognizer from a Dict into the recognizer registry. |
add_recognizers_from_yaml |
Read YAML file and load recognizers into the recognizer registry. |
get_supported_entities |
Return the supported entities by the set of recognizers loaded. |
Source code in presidio_analyzer/recognizer_registry/recognizer_registry.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | |
add_nlp_recognizer
add_nlp_recognizer(nlp_engine: NlpEngine) -> None
Adding NLP recognizer in accordance with the nlp engine.
| PARAMETER | DESCRIPTION |
|---|---|
nlp_engine
|
The NLP engine.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
None |
Source code in presidio_analyzer/recognizer_registry/recognizer_registry.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
load_predefined_recognizers
load_predefined_recognizers(
languages: Optional[List[str]] = None,
nlp_engine: NlpEngine = None,
countries: Optional[List[str]] = None,
) -> None
Load the existing recognizers into memory.
| PARAMETER | DESCRIPTION |
|---|---|
languages
|
List of languages for which to load recognizers
TYPE:
|
nlp_engine
|
The NLP engine to use.
TYPE:
|
countries
|
Optional list of country codes (case-insensitive,
ISO 3166-1 alpha-2 — e.g.
Passing an empty list (
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
None |
Source code in presidio_analyzer/recognizer_registry/recognizer_registry.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
get_nlp_recognizer
staticmethod
get_nlp_recognizer(nlp_engine: NlpEngine) -> Type[SpacyRecognizer]
Return the recognizer leveraging the selected NLP Engine.
Source code in presidio_analyzer/recognizer_registry/recognizer_registry.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |
get_recognizers
get_recognizers(
language: str,
entities: Optional[List[str]] = None,
all_fields: bool = False,
ad_hoc_recognizers: Optional[List[EntityRecognizer]] = None,
) -> List[EntityRecognizer]
Return a list of recognizers which supports the specified name and language.
| PARAMETER | DESCRIPTION |
|---|---|
entities
|
the requested entities
TYPE:
|
language
|
the requested language
TYPE:
|
all_fields
|
a flag to return all fields of a requested language.
TYPE:
|
ad_hoc_recognizers
|
Additional recognizers provided by the user as part of the request
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[EntityRecognizer]
|
A list of the recognizers which supports the supplied entities and language |
Source code in presidio_analyzer/recognizer_registry/recognizer_registry.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |
get_country_codes
get_country_codes() -> List[str]
Return the set of country codes currently represented in the registry.
Aggregates the resolved country tag (via
:meth:EntityRecognizer.country_code) across all loaded
recognizers — including both class-level COUNTRY_CODE and
per-instance country_code= constructor kwargs — and excludes
generic / locale-agnostic ones. Useful for debugging country-
filter behavior:
registry = RecognizerRegistry() registry.load_predefined_recognizers() sorted(registry.get_country_codes()) # doctest: +SKIP ['au', 'ca', 'de', 'es', 'fi', 'in', 'it', 'kr', 'ng', 'pl', 'se', 'sg', 'th', 'tr', 'uk', 'us']
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A sorted list of unique country codes (lowercased) seen on the loaded recognizers. |
Source code in presidio_analyzer/recognizer_registry/recognizer_registry.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | |
add_recognizer
add_recognizer(recognizer: EntityRecognizer) -> None
Add a new recognizer to the list of recognizers.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer
|
Recognizer to add
TYPE:
|
Source code in presidio_analyzer/recognizer_registry/recognizer_registry.py
255 256 257 258 259 260 261 262 263 264 | |
remove_recognizer
remove_recognizer(recognizer_name: str, language: Optional[str] = None) -> None
Remove a recognizer based on its name.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer to remove
TYPE:
|
language
|
The supported language of the recognizer to be removed, in case multiple recognizers with the same name are present, and only one should be removed.
TYPE:
|
Source code in presidio_analyzer/recognizer_registry/recognizer_registry.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | |
add_pattern_recognizer_from_dict
add_pattern_recognizer_from_dict(recognizer_dict: Dict) -> None
Load a pattern recognizer from a Dict into the recognizer registry.
:example:
registry = RecognizerRegistry() recognizer = { "name": "Titles Recognizer", "supported_language": "en","supported_entity": "TITLE", "deny_list": ["Mr.","Mrs."]} registry.add_pattern_recognizer_from_dict(recognizer)
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_dict
|
Dict holding a serialization of an PatternRecognizer
TYPE:
|
Source code in presidio_analyzer/recognizer_registry/recognizer_registry.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 | |
add_recognizers_from_yaml
add_recognizers_from_yaml(yml_path: Union[str, Path]) -> None
Read YAML file and load recognizers into the recognizer registry.
See example yaml file here: https://github.com/data-privacy-stack/presidio/blob/main/presidio-analyzer/presidio_analyzer/conf/example_recognizers.yaml
:example:
yaml_file = "recognizers.yaml" registry = RecognizerRegistry() registry.add_recognizers_from_yaml(yaml_file)
Source code in presidio_analyzer/recognizer_registry/recognizer_registry.py
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 | |
get_supported_entities
get_supported_entities(languages: Optional[List[str]] = None) -> List[str]
Return the supported entities by the set of recognizers loaded.
| PARAMETER | DESCRIPTION |
|---|---|
languages
|
The languages to get the supported entities for. If languages=None, returns all entities for all languages.
TYPE:
|
Source code in presidio_analyzer/recognizer_registry/recognizer_registry.py
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | |
presidio_analyzer.recognizer_registry.RecognizerRegistryProvider
Utility class for loading Recognizer Registry.
Use this class to load recognizer registry from a yaml file
:example: { "supported_languages": ["de", "es"], "recognizers": [ { "name": "Zip code Recognizer", "supported_language": "en", "patterns": [ { "name": "zip code (weak)", "regex": "(\b\d{5}(?:\-\d{4})?\b)", "score": 0.01, } ], "context": ["zip", "code"], "supported_entity": "ZIP", } ] }
| PARAMETER | DESCRIPTION |
|---|---|
conf_file
|
Path to yaml file containing registry configuration
TYPE:
|
registry_configuration
|
Dict containing registry configuration
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
create_recognizer_registry |
Create a recognizer registry according to configuration loaded previously. |
Source code in presidio_analyzer/recognizer_registry/recognizer_registry_provider.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
create_recognizer_registry
create_recognizer_registry() -> RecognizerRegistry
Create a recognizer registry according to configuration loaded previously.
Source code in presidio_analyzer/recognizer_registry/recognizer_registry_provider.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
Context awareness modules
presidio_analyzer.context_aware_enhancers
Context awareness modules.
ContextAwareEnhancer
A class representing an abstract context aware enhancer.
Context words might enhance confidence score of a recognized entity, ContextAwareEnhancer is an abstract class to be inherited by a context aware enhancer logic.
| PARAMETER | DESCRIPTION |
|---|---|
context_similarity_factor
|
How much to enhance confidence of match entity
TYPE:
|
min_score_with_context_similarity
|
Minimum confidence score
TYPE:
|
context_prefix_count
|
how many words before the entity to match context
TYPE:
|
context_suffix_count
|
how many words after the entity to match context
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
enhance_using_context |
Update results in case surrounding words are relevant to the context words. |
Source code in presidio_analyzer/context_aware_enhancers/context_aware_enhancer.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
enhance_using_context
abstractmethod
enhance_using_context(
text: str,
raw_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
recognizers: List[EntityRecognizer],
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Update results in case surrounding words are relevant to the context words.
Using the surrounding words of the actual word matches, look for specific strings that if found contribute to the score of the result, improving the confidence that the match is indeed of that PII entity type
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_results
|
Recognizer results which didn't take context into consideration
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
recognizers
|
the list of recognizers
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/context_aware_enhancers/context_aware_enhancer.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
LemmaContextAwareEnhancer
Bases: ContextAwareEnhancer
A class representing a lemma based context aware enhancer logic.
Context words might enhance confidence score of a recognized entity, LemmaContextAwareEnhancer is an implementation of Lemma based context aware logic, it compares spacy lemmas of each word in context of the matched entity to given context and the recognizer context words, if matched it enhance the recognized entity confidence score by a given factor.
| PARAMETER | DESCRIPTION |
|---|---|
context_similarity_factor
|
How much to enhance confidence of match entity
TYPE:
|
min_score_with_context_similarity
|
Minimum confidence score
TYPE:
|
context_prefix_count
|
how many words before the entity to match context
TYPE:
|
context_suffix_count
|
how many words after the entity to match context
TYPE:
|
context_matching_mode
|
Matching mode for context words. Options: - "substring" (default): Match context words as substrings (e.g., 'card' matches 'creditcard', 'lic' matches 'duplicate'). Maintains backward compatibility. - "whole_word": Match context words only as whole words (e.g., 'lic' matches 'lic' but not 'duplicate'). Prevents false positives.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
enhance_using_context |
Update results in case the lemmas of surrounding words or input context |
Source code in presidio_analyzer/context_aware_enhancers/lemma_context_aware_enhancer.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 | |
enhance_using_context
enhance_using_context(
text: str,
raw_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
recognizers: List[EntityRecognizer],
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Update results in case the lemmas of surrounding words or input context words are identical to the context words.
Using the surrounding words of the actual word matches, look for specific strings that if found contribute to the score of the result, improving the confidence that the match is indeed of that PII entity type
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_results
|
Recognizer results which didn't take context into consideration
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
recognizers
|
the list of recognizers
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/context_aware_enhancers/lemma_context_aware_enhancer.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
NLP Engine modules
presidio_analyzer.nlp_engine
NLP engine package. Performs text pre-processing.
NerModelConfiguration
Bases: BaseModel
NER model configuration using Pydantic validation.
| PARAMETER | DESCRIPTION |
|---|---|
labels_to_ignore
|
List of labels to not return predictions for.
|
aggregation_strategy
|
See https://huggingface.co/docs/transformers/main_classes/pipelines#transformers.TokenClassificationPipeline.aggregation_strategy
|
stride
|
See https://huggingface.co/docs/transformers/main_classes/pipelines#transformers.TokenClassificationPipeline.stride
|
alignment_mode
|
See https://spacy.io/api/doc#char_span
|
default_score
|
Default confidence score if the model does not provide one.
|
model_to_presidio_entity_mapping
|
Mapping between the NER model entities and Presidio entities.
|
low_score_entity_names
|
Set of entity names that are likely to have low detection accuracy that should be adjusted.
|
low_confidence_score_multiplier
|
A multiplier for the score given for low_score_entity_names. Multiplier to the score given for low_score_entity_names.
|
| METHOD | DESCRIPTION |
|---|---|
validate_aggregation_strategy |
Validate aggregation strategy. |
validate_stride |
Validate stride and handle None values. |
validate_alignment_mode |
Validate alignment mode and handle None values. |
from_dict |
Create NerModelConfiguration from a dictionary with Pydantic validation. |
to_dict |
Convert to dictionary representation. |
Source code in presidio_analyzer/nlp_engine/ner_model_configuration.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
validate_aggregation_strategy
classmethod
validate_aggregation_strategy(agg_strategy: str) -> str
Validate aggregation strategy.
Source code in presidio_analyzer/nlp_engine/ner_model_configuration.py
80 81 82 83 84 85 86 87 88 89 90 | |
validate_stride
classmethod
validate_stride(stride: Optional[int]) -> int
Validate stride and handle None values.
Source code in presidio_analyzer/nlp_engine/ner_model_configuration.py
92 93 94 95 96 97 98 99 | |
validate_alignment_mode
classmethod
validate_alignment_mode(alignment: Optional[str]) -> str
Validate alignment mode and handle None values.
Source code in presidio_analyzer/nlp_engine/ner_model_configuration.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
from_dict
classmethod
from_dict(ner_model_configuration_dict: Dict) -> NerModelConfiguration
Create NerModelConfiguration from a dictionary with Pydantic validation.
| PARAMETER | DESCRIPTION |
|---|---|
ner_model_configuration_dict
|
Dictionary containing configuration
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NerModelConfiguration
|
NerModelConfiguration instance |
Source code in presidio_analyzer/nlp_engine/ner_model_configuration.py
116 117 118 119 120 121 122 123 124 | |
to_dict
to_dict() -> Dict
Convert to dictionary representation.
Source code in presidio_analyzer/nlp_engine/ner_model_configuration.py
126 127 128 | |
NlpArtifacts
NlpArtifacts is an abstraction layer over the results of an NLP pipeline.
processing over a given text, it holds attributes such as entities, tokens and lemmas which can be used by any recognizer
| PARAMETER | DESCRIPTION |
|---|---|
entities
|
Identified entities
TYPE:
|
tokens
|
Tokenized text
TYPE:
|
tokens_indices
|
Indices of tokens
TYPE:
|
lemmas
|
List of lemmas in text
TYPE:
|
nlp_engine
|
NlpEngine object
TYPE:
|
language
|
Text language
TYPE:
|
scores
|
Entity confidence scores
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
set_keywords |
Return keywords fpr text. |
to_json |
Convert nlp artifacts to json. |
Source code in presidio_analyzer/nlp_engine/nlp_artifacts.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
set_keywords
staticmethod
set_keywords(nlp_engine, lemmas: List[str], language: str) -> List[str]
Return keywords fpr text.
Extracts lemmas with certain conditions as keywords.
Source code in presidio_analyzer/nlp_engine/nlp_artifacts.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
to_json
to_json() -> str
Convert nlp artifacts to json.
Source code in presidio_analyzer/nlp_engine/nlp_artifacts.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
NlpEngine
Bases: ABC
NlpEngine is an abstraction layer over the nlp module.
It provides NLP preprocessing functionality as well as other queries on tokens.
| METHOD | DESCRIPTION |
|---|---|
load |
Load the NLP model. |
is_loaded |
Return True if the model is already loaded. |
process_text |
Execute the NLP pipeline on the given text and language. |
process_batch |
Execute the NLP pipeline on a batch of texts. |
is_stopword |
Return true if the given word is a stop word. |
is_punct |
Return true if the given word is a punctuation word. |
get_supported_entities |
Return the supported entities for this NLP engine. |
get_supported_languages |
Return the supported languages for this NLP engine. |
Source code in presidio_analyzer/nlp_engine/nlp_engine.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
load
abstractmethod
load() -> None
Load the NLP model.
Source code in presidio_analyzer/nlp_engine/nlp_engine.py
15 16 17 | |
is_loaded
abstractmethod
is_loaded() -> bool
Return True if the model is already loaded.
Source code in presidio_analyzer/nlp_engine/nlp_engine.py
19 20 21 | |
process_text
abstractmethod
process_text(text: str, language: str) -> NlpArtifacts
Execute the NLP pipeline on the given text and language.
Source code in presidio_analyzer/nlp_engine/nlp_engine.py
23 24 25 | |
process_batch
abstractmethod
process_batch(
texts: Iterable[str],
language: str,
batch_size: int = 1,
n_process: int = 1,
**kwargs
) -> Iterator[Tuple[str, NlpArtifacts]]
Execute the NLP pipeline on a batch of texts.
Returns a tuple of (text, NlpArtifacts)
Source code in presidio_analyzer/nlp_engine/nlp_engine.py
27 28 29 30 31 32 33 34 35 36 37 38 39 | |
is_stopword
abstractmethod
is_stopword(word: str, language: str) -> bool
Return true if the given word is a stop word.
(within the given language)
Source code in presidio_analyzer/nlp_engine/nlp_engine.py
41 42 43 44 45 46 47 | |
is_punct
abstractmethod
is_punct(word: str, language: str) -> bool
Return true if the given word is a punctuation word.
(within the given language)
Source code in presidio_analyzer/nlp_engine/nlp_engine.py
49 50 51 52 53 54 55 | |
get_supported_entities
abstractmethod
get_supported_entities() -> List[str]
Return the supported entities for this NLP engine.
Source code in presidio_analyzer/nlp_engine/nlp_engine.py
57 58 59 60 | |
get_supported_languages
abstractmethod
get_supported_languages() -> List[str]
Return the supported languages for this NLP engine.
Source code in presidio_analyzer/nlp_engine/nlp_engine.py
62 63 64 65 | |
SlimSpacyNlpEngine
Bases: NlpEngine
A slim NLP engine that provides only tokenization and lemmatization.
This engine loads spaCy models with the NER pipeline component disabled, reducing memory usage and load time. It is intended for use in Presidio v3 where entity extraction is handled by self-contained recognizers rather than the shared NLP engine.
The slim engine: - Provides tokenization, lemmatization, stopword and punctuation checks. - Does NOT extract named entities (returns empty entity lists). - Uses small spaCy models by default for fast loading and low memory. - Supports auto-downloading spaCy models when they are missing. - Falls back to a generic tokenizer for unsupported languages.
| PARAMETER | DESCRIPTION |
|---|---|
models
|
List of model configurations per language. Example: [{"lang_code": "en", "model_name": "en_core_web_sm"}] If not provided, uses default small models for the given languages.
TYPE:
|
supported_languages
|
List of language codes to support. Used only when models is not provided, to select default models.
TYPE:
|
auto_download
|
Whether to automatically download missing spaCy models.
TYPE:
|
generic_tokenizer
|
Model name to use as a fallback for languages without a default model. Set to "blank" to use spacy.blank(lang) (basic tokenization, no lemmatization). Set to a spaCy model name (e.g. "xx_ent_wiki_sm") to use that model for all fallback languages. If None, a ValueError is raised for unsupported languages.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
load |
Load spaCy models with NER disabled. |
is_loaded |
Return True if the model is already loaded. |
process_text |
Execute the slim NLP pipeline on the given text. |
process_batch |
Execute the slim NLP pipeline on a batch of texts. |
is_stopword |
Return true if the given word is a stop word. |
is_punct |
Return true if the given word is a punctuation word. |
get_supported_entities |
Return an empty list — the slim engine does not extract entities. |
get_supported_languages |
Return the supported languages for this NLP engine. |
Source code in presidio_analyzer/nlp_engine/slim_spacy_nlp_engine.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | |
load
load() -> None
Load spaCy models with NER disabled.
Source code in presidio_analyzer/nlp_engine/slim_spacy_nlp_engine.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
is_loaded
is_loaded() -> bool
Return True if the model is already loaded.
Source code in presidio_analyzer/nlp_engine/slim_spacy_nlp_engine.py
175 176 177 | |
process_text
process_text(text: str, language: str) -> NlpArtifacts
Execute the slim NLP pipeline on the given text.
Performs tokenization and lemmatization only. No named entities are extracted.
Source code in presidio_analyzer/nlp_engine/slim_spacy_nlp_engine.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
process_batch
process_batch(
texts: Union[List[str], List[Tuple[str, object]]],
language: str,
batch_size: int = 1,
n_process: int = 1,
as_tuples: bool = False,
) -> Generator[
Union[Tuple[Any, NlpArtifacts, Any], Tuple[Any, NlpArtifacts]], Any, None
]
Execute the slim NLP pipeline on a batch of texts.
Source code in presidio_analyzer/nlp_engine/slim_spacy_nlp_engine.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
is_stopword
is_stopword(word: str, language: str) -> bool
Return true if the given word is a stop word.
Source code in presidio_analyzer/nlp_engine/slim_spacy_nlp_engine.py
238 239 240 | |
is_punct
is_punct(word: str, language: str) -> bool
Return true if the given word is a punctuation word.
Source code in presidio_analyzer/nlp_engine/slim_spacy_nlp_engine.py
242 243 244 | |
get_supported_entities
get_supported_entities() -> List[str]
Return an empty list — the slim engine does not extract entities.
Source code in presidio_analyzer/nlp_engine/slim_spacy_nlp_engine.py
246 247 248 | |
get_supported_languages
get_supported_languages() -> List[str]
Return the supported languages for this NLP engine.
Source code in presidio_analyzer/nlp_engine/slim_spacy_nlp_engine.py
250 251 252 253 254 | |
SpacyNlpEngine
Bases: NlpEngine
SpacyNlpEngine is an abstraction layer over the nlp module.
It provides processing functionality as well as other queries on tokens. The SpacyNlpEngine uses SpaCy as its NLP module
| METHOD | DESCRIPTION |
|---|---|
load |
Load the spaCy NLP model. |
get_supported_entities |
Return the supported entities for this NLP engine. |
get_supported_languages |
Return the supported languages for this NLP engine. |
is_loaded |
Return True if the model is already loaded. |
process_text |
Execute the SpaCy NLP pipeline on the given text and language. |
process_batch |
Execute the NLP pipeline on a batch of texts using spacy pipe. |
is_stopword |
Return true if the given word is a stop word. |
is_punct |
Return true if the given word is a punctuation word. |
get_nlp |
Return the language model loaded for a language. |
Source code in presidio_analyzer/nlp_engine/spacy_nlp_engine.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
load
load() -> None
Load the spaCy NLP model.
Source code in presidio_analyzer/nlp_engine/spacy_nlp_engine.py
65 66 67 68 69 70 71 72 73 74 75 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the supported entities for this NLP engine.
Source code in presidio_analyzer/nlp_engine/spacy_nlp_engine.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
get_supported_languages
get_supported_languages() -> List[str]
Return the supported languages for this NLP engine.
Source code in presidio_analyzer/nlp_engine/spacy_nlp_engine.py
109 110 111 112 113 | |
is_loaded
is_loaded() -> bool
Return True if the model is already loaded.
Source code in presidio_analyzer/nlp_engine/spacy_nlp_engine.py
115 116 117 | |
process_text
process_text(text: str, language: str) -> NlpArtifacts
Execute the SpaCy NLP pipeline on the given text and language.
Source code in presidio_analyzer/nlp_engine/spacy_nlp_engine.py
119 120 121 122 123 124 125 | |
process_batch
process_batch(
texts: Union[List[str], List[Tuple[str, object]]],
language: str,
batch_size: int = 1,
n_process: int = 1,
as_tuples: bool = False,
) -> Generator[
Union[Tuple[Any, NlpArtifacts, Any], Tuple[Any, NlpArtifacts]], Any, None
]
Execute the NLP pipeline on a batch of texts using spacy pipe.
| PARAMETER | DESCRIPTION |
|---|---|
texts
|
A list of texts to process. if as_tuples is set to True, texts should be a list of tuples (text, context).
TYPE:
|
language
|
The language of the texts.
TYPE:
|
batch_size
|
Default batch size for pipe and evaluate.
TYPE:
|
n_process
|
Number of processors to process texts.
TYPE:
|
as_tuples
|
If set to True, inputs should be a sequence of (text, context) tuples. Output will then be a sequence of (doc, context) tuples. Defaults to False.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Generator[Union[Tuple[Any, NlpArtifacts, Any], Tuple[Any, NlpArtifacts]], Any, None]
|
A generator of tuples (text, NlpArtifacts, context) or (text, NlpArtifacts) depending on the value of as_tuples. |
Source code in presidio_analyzer/nlp_engine/spacy_nlp_engine.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
is_stopword
is_stopword(word: str, language: str) -> bool
Return true if the given word is a stop word.
(within the given language)
Source code in presidio_analyzer/nlp_engine/spacy_nlp_engine.py
175 176 177 178 179 180 181 | |
is_punct
is_punct(word: str, language: str) -> bool
Return true if the given word is a punctuation word.
(within the given language).
Source code in presidio_analyzer/nlp_engine/spacy_nlp_engine.py
183 184 185 186 187 188 189 | |
get_nlp
get_nlp(language: str) -> Language
Return the language model loaded for a language.
| PARAMETER | DESCRIPTION |
|---|---|
language
|
Language
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Language
|
Model from spaCy |
Source code in presidio_analyzer/nlp_engine/spacy_nlp_engine.py
191 192 193 194 195 196 197 198 | |
StanzaNlpEngine
Bases: SpacyNlpEngine
StanzaNlpEngine is an abstraction layer over the nlp module.
It provides processing functionality as well as other queries on tokens. The StanzaNlpEngine uses spacy-stanza and stanza as its NLP module
| PARAMETER | DESCRIPTION |
|---|---|
models
|
Dictionary with the name of the spaCy model per language. For example: models = [{"lang_code": "en", "model_name": "en"}]
TYPE:
|
ner_model_configuration
|
Parameters for the NER model. See conf/stanza.yaml for an example
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
is_loaded |
Return True if the model is already loaded. |
process_text |
Execute the SpaCy NLP pipeline on the given text and language. |
is_stopword |
Return true if the given word is a stop word. |
is_punct |
Return true if the given word is a punctuation word. |
get_supported_entities |
Return the supported entities for this NLP engine. |
get_supported_languages |
Return the supported languages for this NLP engine. |
get_nlp |
Return the language model loaded for a language. |
load |
Load the NLP model. |
process_batch |
Execute the NLP pipeline on a batch of texts using Stanza's bulk processing. |
Source code in presidio_analyzer/nlp_engine/stanza_nlp_engine.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
is_loaded
is_loaded() -> bool
Return True if the model is already loaded.
Source code in presidio_analyzer/nlp_engine/spacy_nlp_engine.py
115 116 117 | |
process_text
process_text(text: str, language: str) -> NlpArtifacts
Execute the SpaCy NLP pipeline on the given text and language.
Source code in presidio_analyzer/nlp_engine/spacy_nlp_engine.py
119 120 121 122 123 124 125 | |
is_stopword
is_stopword(word: str, language: str) -> bool
Return true if the given word is a stop word.
(within the given language)
Source code in presidio_analyzer/nlp_engine/spacy_nlp_engine.py
175 176 177 178 179 180 181 | |
is_punct
is_punct(word: str, language: str) -> bool
Return true if the given word is a punctuation word.
(within the given language).
Source code in presidio_analyzer/nlp_engine/spacy_nlp_engine.py
183 184 185 186 187 188 189 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the supported entities for this NLP engine.
Source code in presidio_analyzer/nlp_engine/spacy_nlp_engine.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
get_supported_languages
get_supported_languages() -> List[str]
Return the supported languages for this NLP engine.
Source code in presidio_analyzer/nlp_engine/spacy_nlp_engine.py
109 110 111 112 113 | |
get_nlp
get_nlp(language: str) -> Language
Return the language model loaded for a language.
| PARAMETER | DESCRIPTION |
|---|---|
language
|
Language
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Language
|
Model from spaCy |
Source code in presidio_analyzer/nlp_engine/spacy_nlp_engine.py
191 192 193 194 195 196 197 198 | |
load
load() -> None
Load the NLP model.
Source code in presidio_analyzer/nlp_engine/stanza_nlp_engine.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
process_batch
process_batch(
texts: Union[List[str], List[Tuple[str, object]]],
language: str,
batch_size: int = 1,
n_process: int = 1,
as_tuples: bool = False,
) -> Generator[
Union[Tuple[Any, NlpArtifacts, Any], Tuple[Any, NlpArtifacts]], Any, None
]
Execute the NLP pipeline on a batch of texts using Stanza's bulk processing.
This method overrides SpacyNlpEngine.process_batch to leverage Stanza's efficient bulk_process method, which processes multiple documents together for better GPU utilization.
Note: Stanza batches internally at the sentence/token level, not docs. For optimal GPU performance, use larger batch sizes (e.g., 16-32 docs). GPU utilization depends on total sentences/tokens across all docs in batch.
| PARAMETER | DESCRIPTION |
|---|---|
texts
|
A list of texts to process. if as_tuples is set to True, texts should be a list of tuples (text, context).
TYPE:
|
language
|
The language of the texts.
TYPE:
|
batch_size
|
Number of documents per bulk_process call. Recommended: 16-32+ for GPU, lower values acceptable for CPU.
TYPE:
|
n_process
|
Not used for Stanza (kept for API compatibility).
TYPE:
|
as_tuples
|
If set to True, inputs should be a sequence of (text, context) tuples. Output will then be a sequence of (text, NlpArtifacts, context) tuples. Defaults to False.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Generator[Union[Tuple[Any, NlpArtifacts, Any], Tuple[Any, NlpArtifacts]], Any, None]
|
A generator of tuples (text, NlpArtifacts, context) or (text, NlpArtifacts) depending on the value of as_tuples. |
Source code in presidio_analyzer/nlp_engine/stanza_nlp_engine.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
TransformersNlpEngine
Bases: SpacyNlpEngine
TransformersNlpEngine is a transformers based NlpEngine.
It comprises a spacy pipeline used for tokenization, lemmatization, pos, and a transformers component for NER.
Both the underlying spacy pipeline and the transformers engine could be configured by the user. :example: [{"lang_code": "en", "model_name": { "spacy": "en_core_web_sm", "transformers": "dslim/bert-base-NER" } }]
| PARAMETER | DESCRIPTION |
|---|---|
models
|
A dict holding the model's configuration.
TYPE:
|
ner_model_configuration
|
Parameters for the NER model. See conf/transformers.yaml for an example Note that since the spaCy model is not used for NER, we recommend using a simple model, such as en_core_web_sm for English. For potential Transformers models, see a list of models here: https://huggingface.co/models?pipeline_tag=token-classification It is further recommended to fine-tune these models to the specific scenario in hand.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
is_loaded |
Return True if the model is already loaded. |
process_text |
Execute the SpaCy NLP pipeline on the given text and language. |
process_batch |
Execute the NLP pipeline on a batch of texts using spacy pipe. |
is_stopword |
Return true if the given word is a stop word. |
is_punct |
Return true if the given word is a punctuation word. |
get_supported_entities |
Return the supported entities for this NLP engine. |
get_supported_languages |
Return the supported languages for this NLP engine. |
get_nlp |
Return the language model loaded for a language. |
load |
Load the spaCy and transformers models. |
Source code in presidio_analyzer/nlp_engine/transformers_nlp_engine.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |
is_loaded
is_loaded() -> bool
Return True if the model is already loaded.
Source code in presidio_analyzer/nlp_engine/spacy_nlp_engine.py
115 116 117 | |
process_text
process_text(text: str, language: str) -> NlpArtifacts
Execute the SpaCy NLP pipeline on the given text and language.
Source code in presidio_analyzer/nlp_engine/spacy_nlp_engine.py
119 120 121 122 123 124 125 | |
process_batch
process_batch(
texts: Union[List[str], List[Tuple[str, object]]],
language: str,
batch_size: int = 1,
n_process: int = 1,
as_tuples: bool = False,
) -> Generator[
Union[Tuple[Any, NlpArtifacts, Any], Tuple[Any, NlpArtifacts]], Any, None
]
Execute the NLP pipeline on a batch of texts using spacy pipe.
| PARAMETER | DESCRIPTION |
|---|---|
texts
|
A list of texts to process. if as_tuples is set to True, texts should be a list of tuples (text, context).
TYPE:
|
language
|
The language of the texts.
TYPE:
|
batch_size
|
Default batch size for pipe and evaluate.
TYPE:
|
n_process
|
Number of processors to process texts.
TYPE:
|
as_tuples
|
If set to True, inputs should be a sequence of (text, context) tuples. Output will then be a sequence of (doc, context) tuples. Defaults to False.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Generator[Union[Tuple[Any, NlpArtifacts, Any], Tuple[Any, NlpArtifacts]], Any, None]
|
A generator of tuples (text, NlpArtifacts, context) or (text, NlpArtifacts) depending on the value of as_tuples. |
Source code in presidio_analyzer/nlp_engine/spacy_nlp_engine.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
is_stopword
is_stopword(word: str, language: str) -> bool
Return true if the given word is a stop word.
(within the given language)
Source code in presidio_analyzer/nlp_engine/spacy_nlp_engine.py
175 176 177 178 179 180 181 | |
is_punct
is_punct(word: str, language: str) -> bool
Return true if the given word is a punctuation word.
(within the given language).
Source code in presidio_analyzer/nlp_engine/spacy_nlp_engine.py
183 184 185 186 187 188 189 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the supported entities for this NLP engine.
Source code in presidio_analyzer/nlp_engine/spacy_nlp_engine.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
get_supported_languages
get_supported_languages() -> List[str]
Return the supported languages for this NLP engine.
Source code in presidio_analyzer/nlp_engine/spacy_nlp_engine.py
109 110 111 112 113 | |
get_nlp
get_nlp(language: str) -> Language
Return the language model loaded for a language.
| PARAMETER | DESCRIPTION |
|---|---|
language
|
Language
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Language
|
Model from spaCy |
Source code in presidio_analyzer/nlp_engine/spacy_nlp_engine.py
191 192 193 194 195 196 197 198 | |
load
load() -> None
Load the spaCy and transformers models.
Source code in presidio_analyzer/nlp_engine/transformers_nlp_engine.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
NlpEngineProvider
Create different NLP engines from configuration.
:example: configuration: { "nlp_engine_name": "spacy", "models": [{"lang_code": "en", "model_name": "en_core_web_lg" }] } Nlp engine names available by default: spacy, stanza.
| PARAMETER | DESCRIPTION |
|---|---|
nlp_engines
|
List of available NLP engines Default: (SpacyNlpEngine, StanzaNlpEngine)
TYPE:
|
nlp_configuration
|
Dict containing nlp configuration
TYPE:
|
conf_file
|
Path to yaml file containing nlp engine configuration.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
create_engine |
Create an NLP engine instance. |
Source code in presidio_analyzer/nlp_engine/nlp_engine_provider.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
create_engine
create_engine() -> NlpEngine
Create an NLP engine instance.
Source code in presidio_analyzer/nlp_engine/nlp_engine_provider.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
Predefined Recognizers
presidio_analyzer.predefined_recognizers
Predefined recognizers package. Holds all the default recognizers.
TransformersRecognizer
Bases: SpacyRecognizer
Recognize entities using the spacy-huggingface-pipeline package.
The recognizer doesn't run transformers models, but loads the output from the NlpArtifacts See: - https://huggingface.co/docs/transformers/main/en/index for transformer models - https://github.com/explosion/spacy-huggingface-pipelines on the spaCy wrapper to transformers
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize self to dictionary. |
from_dict |
Create EntityRecognizer from a dict input. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
build_explanation |
Create explanation for why this result was detected. |
Source code in presidio_analyzer/predefined_recognizers/nlp_engine_recognizers/transformers_recognizer.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize self to dictionary.
| RETURNS | DESCRIPTION |
|---|---|
Dict
|
a dictionary |
Source code in presidio_analyzer/entity_recognizer.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> EntityRecognizer
Create EntityRecognizer from a dict input.
| PARAMETER | DESCRIPTION |
|---|---|
entity_recognizer_dict
|
Dict containing keys and values for instantiation
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
249 250 251 252 253 254 255 256 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
build_explanation
build_explanation(
original_score: float, explanation: str
) -> AnalysisExplanation
Create explanation for why this result was detected.
| PARAMETER | DESCRIPTION |
|---|---|
original_score
|
Score given by this recognizer
TYPE:
|
explanation
|
Explanation string
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
|
Source code in presidio_analyzer/predefined_recognizers/nlp_engine_recognizers/spacy_recognizer.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
AuAbnRecognizer
Bases: PatternRecognizer
Recognizes Australian Business Number ("ABN").
The Australian Business Number (ABN) is a unique 11 digit identifier issued to all entities registered in the Australian Business Register (ABR). The 11 digit ABN is structured as a 9 digit identifier with two leading check digits. The leading check digits are derived using a modulus 89 calculation. This recognizer identifies ABN using regex, context words and checksum. Reference: https://abr.business.gov.au/Help/AbnFormat
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
replacement_pairs
|
List of tuples with potential replacement values for different strings to be used during pattern matching. This can allow a greater variety in input, for example by removing dashes or spaces.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/australia/au_abn_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
validate_result
validate_result(pattern_text: str) -> bool
Validate the pattern logic e.g., by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
A bool indicating whether the validation was successful. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/australia/au_abn_recognizer.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
AuAcnRecognizer
Bases: PatternRecognizer
Recognizes Australian Company Number ("ACN").
The Australian Company Number (ACN) is a nine digit number with the last digit being a check digit calculated using a modified modulus 10 calculation. This recognizer identifies ACN using regex, context words, and checksum. Reference: https://asic.gov.au/
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
replacement_pairs
|
List of tuples with potential replacement values for different strings to be used during pattern matching. This can allow a greater variety in input, for example by removing dashes or spaces.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/australia/au_acn_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
validate_result
validate_result(pattern_text: str) -> bool
Validate the pattern logic e.g., by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
A bool indicating whether the validation was successful. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/australia/au_acn_recognizer.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
AuMedicareRecognizer
Bases: PatternRecognizer
Recognizes Australian Medicare number using regex, context words, and checksum.
Medicare number is a unique identifier issued by Australian Government that enables the cardholder to receive a rebates of medical expenses under Australia's Medicare system. It uses a modulus 10 checksum scheme to validate the number. Reference: https://en.wikipedia.org/wiki/Medicare_card_(Australia)
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
replacement_pairs
|
List of tuples with potential replacement values for different strings to be used during pattern matching. This can allow a greater variety in input, for example by removing dashes or spaces.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/australia/au_medicare_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
validate_result
validate_result(pattern_text: str) -> bool
Validate the pattern logic e.g., by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
A bool indicating whether the validation was successful. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/australia/au_medicare_recognizer.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
AuTfnRecognizer
Bases: PatternRecognizer
Recognizes Australian Tax File Numbers ("TFN").
The tax file number (TFN) is a unique identifier issued by the Australian Taxation Office to each taxpaying entity — an individual, company, superannuation fund, partnership, or trust. The TFN consists of a nine digit number, usually presented in the format NNN NNN NNN. TFN includes a check digit for detecting erroneous number based on simple modulo 11. This recognizer uses regex, context words, and checksum to identify TFN. Reference: https://www.ato.gov.au/individuals/tax-file-number/
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
replacement_pairs
|
List of tuples with potential replacement values for different strings to be used during pattern matching. This can allow a greater variety in input, for example by removing dashes or spaces.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/australia/au_tfn_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
validate_result
validate_result(pattern_text: str) -> bool
Validate the pattern logic e.g., by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
A bool indicating whether the validation was successful. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/australia/au_tfn_recognizer.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
CaSinRecognizer
Bases: PatternRecognizer
Recognize Canadian Social Insurance Number (SIN) using regex + Luhn checksum.
A SIN is a 9-digit number issued by Employment and Social Development Canada (ESDC) to administer various government programs. The last digit is a Luhn check digit computed over the first 8 digits. SINs beginning with 0 or 8 are reserved and not currently issued to individuals.
Format: DDD DDD DDD or DDD-DDD-DDD or DDDDDDDDD First digit valid range: 1-7, 9
Reference: https://www.canada.ca/en/employment-social-development/services/sin.html
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
invalidate_result |
Check if the pattern text cannot be validated as a CA_SIN entity. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/canada/ca_sin_recognizer.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the pattern logic e.g., by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the validation was successful. |
Source code in presidio_analyzer/pattern_recognizer.py
136 137 138 139 140 141 142 143 144 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
invalidate_result
invalidate_result(pattern_text: str) -> bool
Check if the pattern text cannot be validated as a CA_SIN entity.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
Text detected as pattern by regex
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if invalidated |
Source code in presidio_analyzer/predefined_recognizers/country_specific/canada/ca_sin_recognizer.py
65 66 67 68 69 70 71 72 73 | |
FiPersonalIdentityCodeRecognizer
Bases: PatternRecognizer
Recognizes and validates Finnish Personal Identity Codes (Henkilötunnus).
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
validate_result |
Validate the pattern by using the control character. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/finland/fi_personal_identity_code_recognizer.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the pattern by using the control character.
Source code in presidio_analyzer/predefined_recognizers/country_specific/finland/fi_personal_identity_code_recognizer.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
DeBsnrRecognizer
Bases: PatternRecognizer
Recognizes German Betriebsstättennummer (BSNR).
The BSNR is a 9-digit practice / site-of-care number assigned by the regional Kassenärztliche Vereinigung (KV) to each approved practice location (Betriebsstätte) participating in the German statutory health insurance system. It appears in billing records, treatment documents, and statutory healthcare communications and reveals the treating facility, making it sensitive under DSGVO.
Legal basis: § 75 Abs. 7 SGB V (Sozialgesetzbuch Fünftes Buch). Standard: KBV-Richtlinie nach § 75 Abs. 7 SGB V zur Vergabe der Arzt-, Betriebsstätten-, Praxisnetz- sowie der Netzverbundnummern. Data protection: DSGVO Art. 9 (Gesundheitsdaten), BDSG § 22.
Format (9 digits): Pos 1–2: KV-Bereichskennzeichen (regional KV code, e.g. 02 Hamburg, 38 Nordrhein, 72 Berlin; see VALID_KV_CODES below for the full whitelist per KBV Arztnummern-Richtlinie Anlage 1) Pos 3–9: Laufende Nummer (sequential number assigned by KV)
Examples (fictitious): 021234568, 381789045, 721234567
Accuracy note: The BSNR has no public Prüfziffer algorithm, so
validate_result cannot give positive evidence of a real BSNR; it can
only drop clearly invalid inputs (wrong length, non-digit, all-zero).
All structurally-plausible 9-digit inputs therefore return None
from validate_result: the match keeps its base pattern score (0.2)
and the ContextAwareEnhancer drives final confidence via context
words ("Betriebsstättennummer", "BSNR", "Praxis", …).
VALID_KV_CODES below lists the 2-digit regional codes documented in
KBV Arztnummern-Richtlinie Anlage 1. It is retained for reference
and future opt-in strict validation but is intentionally NOT used
to upgrade whitelisted-prefix matches to MAX_SCORE — the \b\d{9}\b
pattern is too broad to justify that upgrade on a 2-digit-prefix
check alone.
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
validate_result |
Validate the BSNR structurally. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/germany/de_bsnr_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the BSNR structurally.
BSNR has no publicly documented Prüfziffer algorithm, so this
method can only drop clearly invalid inputs. It does NOT promote
structurally-valid matches to MAX_SCORE — the \b\d{9}\b
base pattern is too broad for that to be safe on a 2-digit
prefix check alone. Final confidence on valid-shaped BSNRs is
driven by context words via the ContextAwareEnhancer.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validate (9 digits)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
False if the input is malformed (wrong length, non-digit, or all-zero); None otherwise (keep pattern score, let context drive confidence). |
Source code in presidio_analyzer/predefined_recognizers/country_specific/germany/de_bsnr_recognizer.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
DeFuehrerscheinRecognizer
Bases: PatternRecognizer
Recognizes German Führerscheinnummern (driving license numbers).
The Führerscheinnummer is the document number printed in Field 5 of the German driving license card. Since the EU-harmonized credit-card format was introduced on 19 January 2013 (EU Directive 2006/126/EC, implemented via FeV reform), the number follows a fixed 11-character structure:
Pos 1–2: Behördenkürzel – 2 uppercase letters identifying the issuing
Fahrerlaubnisbehörde (derived from the Kfz-Zulassungskürzel of
the issuing Kreis/Stadt, e.g. "B0" Berlin, "MU" München,
"HH" Hamburg, "KO" Koblenz)
Pos 3–5: Behördennummer – 3-digit authority code within the Bundesland
(assigned by the Kraftfahrt-Bundesamt, KBA)
Pos 6–10: Laufende Nummer – 5-digit sequential issue number
Pos 11: Prüfzeichen – 1 check character (uppercase letter A–Z or
digit 0–9); the derivation algorithm is not published by KBA
Legal basis: FeV Anlage 8 (Fahrerlaubnis-Verordnung, Anlage 8 – Muster des Führerscheins), KBA Schlüsselverzeichnis der Fahrerlaubnisbehörden. EU standard: Annex I to Directive 2006/126/EC (Field 5). Data protection: DSGVO Art. 4 Nr. 1 (personenbezogene Daten), BDSG.
Examples (fictitious): B012345678A, MU12345678B, HH98765432C
Scope note: Pre-2013 German driving licenses (pink folded card, laminated card) used locally defined, non-standardized number formats and remain legally valid until 2033 under EU grandfathering rules. Their numbers do not reliably fit the 11-character pattern and are therefore out of scope for this recognizer. Context words (e.g. "Führerschein", "Fahrerlaubnis") remain the primary means of distinguishing true license numbers from other 11-character alphanumeric codes.
No checksum validation is implemented because the Prüfzeichen derivation formula is not published in FeV Anlage 8 or KBA administrative documents.
Accuracy note: The pattern [A-Z]{2}\\d{8}[A-Z0-9] (11 characters) is
fairly specific, but context words are required for high-confidence matches
because no computable checksum is available. The base confidence is set to
0.35. Formal accuracy evaluation has not been performed on a labelled dataset.
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/germany/de_fuehrerschein_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the pattern logic e.g., by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the validation was successful. |
Source code in presidio_analyzer/pattern_recognizer.py
136 137 138 139 140 141 142 143 144 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
DeHandelsregisterRecognizer
Bases: PatternRecognizer
Recognizes German commercial register numbers (Handelsregisternummer).
The Handelsregisternummer identifies legal entities and sole traders registered in the German Handelsregister (commercial register), maintained by local Amtsgerichte (district courts). It is divided into two sections:
- Abteilung A (HRA): Einzelkaufleute (sole traders) and Personengesellschaften
(partnerships: OHG, KG, GmbH & Co. KG, etc.). For Einzelkaufleute, the HRA
number directly identifies a natural person, making it personal data under
DSGVO Art. 4 Nr. 1.
- Abteilung B (HRB): Kapitalgesellschaften (corporations: GmbH, AG, KGaA,
UG (haftungsbeschränkt), etc.). Identifies legal entities; not personal data
unless the entity is a sole shareholder / sole director whose identity is
directly derivable.
Legal basis: § 9, § 14 HGB (Handelsgesetzbuch), Handelsregisterverordnung (HRV). Data protection: DSGVO Art. 4 Nr. 1 for HRA entries linked to natural persons; BDSG.
Format: HR[AB][optional space] [1–6 digits] Examples: HRA 12345, HRB 123456, HRA12345, HRB 1234 Köln
The HR[AB] prefix makes the pattern highly specific, resulting in low false
positive rates even without a checksum. No formal accuracy evaluation has been
performed on a labelled dataset.
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/germany/de_handelsregister_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the pattern logic e.g., by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the validation was successful. |
Source code in presidio_analyzer/pattern_recognizer.py
136 137 138 139 140 141 142 143 144 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
DeHealthInsuranceRecognizer
Bases: PatternRecognizer
Recognizes German statutory health insurance numbers (KVNR).
Also called Krankenversicherungsnummer, Krankenversichertennummer, or Versichertennummer.
The KVNR is assigned to every person insured under the German statutory health insurance system (gesetzliche Krankenversicherung, GKV). It is printed on the Gesundheitskarte (eGK – elektronische Gesundheitskarte).
Legal basis: § 290 SGB V (Sozialgesetzbuch Fünftes Buch – Gesetzliche Krankenversicherung). Data protection: DSGVO Art. 9 (besondere Kategorien personenbezogener Daten – Gesundheitsdaten), BDSG § 22.
Format (10 characters): Pos 1: Buchstabe (first letter of birth surname, A–Z) Pos 2–9: 8 digits (birth date encoded + serial) Pos 10: Prüfziffer (check digit, 0–9)
Example: A000500015 (from § 290 SGB V Anlage 1, Stand 02.01.2023)
Check digit algorithm (§ 290 SGB V Anlage 1, GKV-Spitzenverband): 1. Convert the letter at position 1 to its 2-digit ordinal value (A=01, B=02, …, Z=26). Concatenated with the 8 data digits at positions 2–9, this yields 10 effective digits. 2. Apply alternating factors [1, 2, 1, 2, 1, 2, 1, 2, 1, 2] to those 10 effective digits. 3. For each product ≥ 10, replace it with the cross-sum of its digits (Quersumme). 4. Sum the 10 values; compute sum mod 10. 5. The result must equal the check digit at position 10.
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
validate_result |
Validate the KVNR using the GKV-Spitzenverband checksum algorithm. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/germany/de_health_insurance_recognizer.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the KVNR using the GKV-Spitzenverband checksum algorithm.
Algorithm source: GKV-Spitzenverband technical specification (§ 290 SGB V).
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validate (10 characters: 1 letter + 9 digits)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
True if valid, False if invalid |
Source code in presidio_analyzer/predefined_recognizers/country_specific/germany/de_health_insurance_recognizer.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
DeIdCardRecognizer
Bases: PatternRecognizer
Recognizes German national ID card numbers (Personalausweisnummern) using regex.
The German Personalausweis (nPA – neuer Personalausweis) has been issued since November 2010. Its document number (Seriennummer/Dokumentennummer) is printed on the front of the card and encoded in the Machine Readable Zone (MRZ).
Legal basis: Personalausweisgesetz (PAuswG), Personalausweisverordnung (PAuswV). Data protection: DSGVO Art. 4 Nr. 1 (personenbezogene Daten), BDSG.
Format (nPA, since November 2010): - 9 characters: first 8 from the ICAO restricted uppercase charset (excludes A, B, D, E, I, O, Q, S, U) plus 1 digit at position 9 (the ICAO Doc 9303 check digit). - Example: L01X00T44 (verifies against ICAO)
Format (old Personalausweis, before November 2010): - Letter T followed by 8 digits (legacy 9-char format; no ICAO check digit — the trailing digit is part of the serial). - Example: T22000124
Check digit algorithm (ICAO Doc 9303, nPA only): Weights 7, 3, 1 repeating on positions 1–8 with letters mapped A=10 … Z=35; the sum modulo 10 must equal the digit at position 9.
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
validate_result |
Validate the nPA ICAO Doc 9303 check digit. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/germany/de_id_card_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the nPA ICAO Doc 9303 check digit.
Legacy "T + 8 digits" numbers (pre-2010) are accepted at pattern
confidence (return None) because they predate ICAO and do not
carry a check digit.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validate (9 characters)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
True if the ICAO check matches; False if the nPA-shaped value fails the check; None for the legacy T-format which cannot be structurally validated here. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/germany/de_id_card_recognizer.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
DeKfzRecognizer
Bases: PatternRecognizer
Recognizes German vehicle registration plates (KFZ-Kennzeichen).
German license plates are issued by local Zulassungsbehörden (vehicle registration authorities). While not exclusively personal (vehicles can be owned by companies), they can be linked to natural persons and are considered personally identifiable information in the context of data protection law.
Legal basis: Fahrzeug-Zulassungsverordnung (FZV) § 8, § 9. Data protection: DSGVO Art. 4 Nr. 1 (personenbezogene Daten) – license plates constitute personal data when they can be linked to an identifiable person (ECJ ruling C-582/14, Breyer v. Germany).
Format: [Unterscheidungszeichen][Erkennungszeichen] [Ziffern][Suffix]
Unterscheidungszeichen: 1–3 uppercase letters (district/city code)
Erkennungszeichen: 1–2 uppercase letters
Ziffern: 1–4 digits
Suffix (optional): E (electric vehicle) or H (Oldtimer/historic, ≥30 years)
Examples B AB 1234 (Berlin) M XY 999 (München) HH AB 1234 (Hamburg) KA EF 1H (Karlsruhe, historic) MIL E 1234E (Miltenberg, electric) S AB 12 (Stuttgart)
Note: Seasonal plates (Saison-Kennzeichen) also contain month ranges but are not covered by this pattern.
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/germany/de_kfz_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the pattern logic e.g., by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the validation was successful. |
Source code in presidio_analyzer/pattern_recognizer.py
136 137 138 139 140 141 142 143 144 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
DeLanrRecognizer
Bases: PatternRecognizer
Recognizes German Lebenslange Arztnummer (LANR).
The LANR is a 9-digit lifetime physician number assigned by the Kassenärztliche Vereinigung (KV) to every licensed physician participating in the German statutory health insurance system (Vertragsarzt). It appears on prescriptions (Rezepte), billing records, discharge letters, and other statutory healthcare documents.
Legal basis: § 75 Abs. 7 SGB V (Sozialgesetzbuch Fünftes Buch). Standard: KBV-Richtlinie nach § 75 Abs. 7 SGB V zur Vergabe der Arzt-, Betriebsstätten-, Praxisnetz- sowie der Netzverbundnummern. Data protection: DSGVO Art. 9 (Gesundheitsdaten), BDSG § 22.
Format (9 digits): Pos 1–6: Arztnummer (physician identifier, assigned by KV) Pos 7: Prüfziffer (check digit, derived from pos 1–6) Pos 8–9: Arztgruppe / Fachgruppe (specialty / physician group code)
Examples: 123456601, 234567701, 100000601
Check digit algorithm (KBV Arztnummern-Richtlinie): 1. Multiply digits at positions 1–6 alternately by 4 and 9 from the left: weights [4, 9, 4, 9, 4, 9]. 2. Sum the six products (no cross-sum step). 3. Check digit (pos 7) = (10 − sum mod 10) mod 10, i.e. the difference to 10; if the difference is 10, the check digit is 0.
Worked example for physician digits 123456: products = 4, 18, 12, 36, 20, 54 → sum = 144 144 mod 10 = 4, 10 − 4 = 6 → check digit 6, so LANR = 123456601
Accuracy note: The base pattern \\b\\d{9}\\b matches any 9-digit token.
Because LANRs share the same surface form as other 9-digit identifiers
(e.g. DE_BSNR), the checksum in validate_result() is the primary guard
against false positives; context words are required for high-confidence
results without a valid checksum. Formal accuracy evaluation has not been
performed on a labelled dataset.
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
validate_result |
Validate the LANR using the KBV Arztnummern-Richtlinie checksum. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/germany/de_lanr_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the LANR using the KBV Arztnummern-Richtlinie checksum.
Algorithm source: KBV Arztnummern-Richtlinie nach § 75 Abs. 7 SGB V.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validate (9 digits)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
True if check digit is valid, False otherwise |
Source code in presidio_analyzer/predefined_recognizers/country_specific/germany/de_lanr_recognizer.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
DePassportRecognizer
Bases: PatternRecognizer
Recognizes German passport numbers (Reisepassnummern) using regex.
German passports are issued by the Bundesdruckerei on behalf of the Bundesrepublik Deutschland. The document number consists of 9 alphanumeric characters and appears on the data page and in the Machine Readable Zone (MRZ).
Legal basis: Passgesetz (PassG) § 4, Passverordnung (PassV). Data protection: DSGVO Art. 4 Nr. 1 (personenbezogene Daten), BDSG.
Format (9 characters total): - 8 alphanumeric characters (uppercase letters from the limited set C, F, G, H, J, K, L, M, N, P, R, T, V, W, X, Y, Z and digits 0–9) followed by - 1 digit at position 9 — the ICAO Doc 9303 check digit over the first 8 characters. - Example: C01X00T41 (F20400481 verifies against ICAO)
Character set excludes visually ambiguous letters (A, B, D, E, I, O, Q, S, U) per ICAO Doc 9303 Machine Readable Travel Documents.
Check digit algorithm (ICAO Doc 9303): - Letters A=10, B=11, …, Z=35; digits keep their face value. - Apply weights 7, 3, 1 repeating to the first 8 characters. - Sum the products, take sum mod 10 — that is the 9th digit.
Worked example for C01X00T41: values = 12, 0, 1, 33, 0, 0, 29, 4 weights = 7, 3, 1, 7, 3, 1, 7, 3 products = 84, 0, 1, 231, 0, 0, 203, 12 → sum = 531 531 mod 10 = 1 → matches check digit '1'
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
validate_result |
Validate the ICAO Doc 9303 check digit at position 9. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/germany/de_passport_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the ICAO Doc 9303 check digit at position 9.
Algorithm source: ICAO Doc 9303 Part 3 — Machine Readable Travel Documents. Weights 7, 3, 1 repeating applied to positions 1–8 with letters mapped A=10 … Z=35; the sum modulo 10 must equal the digit at position 9.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validate (9 characters)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
True if check digit is valid, False otherwise |
Source code in presidio_analyzer/predefined_recognizers/country_specific/germany/de_passport_recognizer.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
DePlzRecognizer
Bases: PatternRecognizer
Recognizes German postal codes (Postleitzahl, PLZ).
German postal codes consist of exactly 5 digits in the range 01001–99998, assigned by Deutsche Post AG. A PLZ alone is generally not sufficient to identify a specific natural person and is therefore not directly personal data under DSGVO Art. 4 Nr. 1. However, in combination with other data (e.g., street address, name), it contributes to identifying an individual, and in very rural areas a single PLZ may cover only a handful of addresses.
Legal basis: DSGVO Art. 4 Nr. 1 in combination with other address data; BDSG.
Format: 5 digits, 01001–99998 (boundary values 01000 and 99999 are excluded). Examples: 10115 (Berlin Mitte), 80331 (München), 22085 (Hamburg)
!! ACCURACY WARNING !!
The pattern [0-9]{5} is extremely generic and will produce a very high number
of false positives when used without context (e.g., year numbers, prices, order
IDs, phone number fragments, reference numbers). The base confidence is
therefore set to 0.05 – the recognizer is only actionable when strong context
words such as "PLZ", "Postleitzahl" or "Postanschrift" are present nearby.
This recognizer should only be enabled in pipelines where German address data
is expected. Formal accuracy evaluation has not been performed on a labelled
dataset.
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/germany/de_plz_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the pattern logic e.g., by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the validation was successful. |
Source code in presidio_analyzer/pattern_recognizer.py
136 137 138 139 140 141 142 143 144 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
DeSocialSecurityRecognizer
Bases: PatternRecognizer
Recognizes German Rentenversicherungsnummer (RVNR / Sozialversicherungsnummer).
The Rentenversicherungsnummer (also called Versicherungsnummer or RVNR) is a unique 12-character identifier assigned to every person insured under the German statutory pension insurance scheme (gesetzliche Rentenversicherung). It encodes date of birth, gender information, and a serial number.
Legal basis: § 147 SGB VI (Sozialgesetzbuch Sechstes Buch – Gesetzliche Rentenversicherung), § 33a SGB I. Data protection: DSGVO Art. 4 Nr. 1 (personenbezogene Daten), BDSG.
Format (12 characters): Pos 1–2: Bereichsnummer (2 digits, issuing regional office code, 01–99) Pos 3–4: Geburtstag (birth day, 01–31; or 51–81 with +50 Ergänzungsmerkmal to disambiguate otherwise identical numbers — gender-agnostic) Pos 5–6: Geburtsmonat (birth month, 01–12) Pos 7–8: Geburtsjahr (last 2 digits of birth year) Pos 9: Buchstabenkennung (first letter of birth surname, A–Z) Pos 10–11: Seriennummer / Geschlechtskennung (00–49 male, 50–99 female) Pos 12: Prüfziffer (check digit)
Example: 15070649C103 (canonical example, DRV technical documentation)
Check digit algorithm (VKVV § 4 / Deutsche Rentenversicherung): 1. Replace the letter at position 9 with its 2-digit ordinal value (A=01, B=02, …, Z=26). This yields 12 data digits (positions 1–8 of the original, plus 2 letter-ordinal digits, plus positions 10–11) followed by the check digit at position 12. 2. Apply weights [2, 1, 2, 5, 7, 1, 2, 1, 2, 1, 2, 1] to the 12 data digits (the check digit itself is not part of the weighted sum). 3. For each product, take the cross-sum (Quersumme) of its digits (products < 10 remain unchanged; e.g. 35 → 3+5 = 8). 4. Sum all 12 cross-sums, compute sum mod 10. 5. The result must equal the check digit at position 12.
Worked example for 15070649C103: effective = '15070649' + '03' (C=03) + '10' = '150706490310' × weights = 2,5,0,35,0,6,8,9,0,3,2,0 cross-sums = 2,5,0, 8,0,6,8,9,0,3,2,0 = 43 43 mod 10 = 3 → matches check digit '3'
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
validate_result |
Validate the Rentenversicherungsnummer using the VKVV § 4 checksum. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/germany/de_social_security_recognizer.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the Rentenversicherungsnummer using the VKVV § 4 checksum.
Algorithm source: Verordnung über die Vergabe der Versicherungsnummer (VKVV) § 4, Deutsche Rentenversicherung technical specification.
Additionally enforces the birth-day (01–31 or 51–81 with +50 Ergänzungsmerkmal) and birth-month (01–12) ranges from the spec so that a relaxed-pattern match with an impossible date cannot be promoted to MAX_SCORE by a lucky checksum collision.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validate (12 characters)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
True if valid, False if invalid |
Source code in presidio_analyzer/predefined_recognizers/country_specific/germany/de_social_security_recognizer.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
DeTaxIdRecognizer
Bases: PatternRecognizer
Recognizes German Steueridentifikationsnummer (Steuer-IdNr.).
The Steueridentifikationsnummer is a unique 11-digit personal tax identification number issued by the Bundeszentralamt für Steuern to every person registered in Germany. It does not change over a person's lifetime.
Legal basis: §§ 139a–139e Abgabenordnung (AO), in force since 2007. Data protection: DSGVO Art. 4 Nr. 1 (personenbezogene Daten), BDSG.
Format: - 11 digits - First digit: 1–9 (never 0) - Digits 1–10: each digit may appear at most three times (BZSt rule in force since the 2016 format revision; previously exactly one digit repeated twice or three times and all others appeared exactly once). - Digit 11: check digit (ISO 7064 Mod 11, 10 variant)
Examples (fictitious): 86095742719, 12345678903
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
validate_result |
Validate the Steueridentifikationsnummer using the official checksum algorithm. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/germany/de_tax_id_recognizer.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the Steueridentifikationsnummer using the official checksum algorithm.
Algorithm: ISO 7064 Mod 11, 10 variant as specified by the Bundeszentralamt für Steuern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validate (11 digits)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
True if valid, False if invalid |
Source code in presidio_analyzer/predefined_recognizers/country_specific/germany/de_tax_id_recognizer.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
DeTaxNumberRecognizer
Bases: PatternRecognizer
Recognizes German Steuernummer using regex.
The Steuernummer is a tax number assigned by the local Finanzamt (tax office) to individuals and businesses. Unlike the Steueridentifikationsnummer, it can change (e.g., upon moving to a different Finanzamt district).
Legal basis: § 139a Abgabenordnung (AO). Data protection: DSGVO Art. 4 Nr. 1 (personenbezogene Daten), BDSG.
Formats: - ELSTER unified (bundeseinheitlich, 13 digits): BB FFF UUUUU P → 2-digit Bundesland code (01–16) + 11 digits Example: 2181508150X → normalised as 02181508150X - State-specific human-readable (with slashes/spaces): NW: 123/4567/8901 (3/4/4 digits) BY: 123/456/78901 (3/3/5 digits) BE: 12/345/67890 (2/3/5 digits) HH: 12/345/67890 (2/3/5 digits)
Bundesland codes (ELSTER): 01=SH, 02=HH, 03=NI, 04=HB, 05=NW, 06=HE, 07=RP, 08=BW, 09=BY, 10=SL, 11=BE, 12=BB, 13=MV, 14=SN, 15=ST, 16=TH
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/germany/de_tax_number_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the pattern logic e.g., by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the validation was successful. |
Source code in presidio_analyzer/pattern_recognizer.py
136 137 138 139 140 141 142 143 144 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
DeVatIdRecognizer
Bases: PatternRecognizer
Recognizes German Umsatzsteuer-Identifikationsnummer (USt-IdNr.).
The USt-IdNr. is issued by the Bundeszentralamt für Steuern (BZSt) to VAT-registered businesses and self-employed persons in Germany. It is used on invoices and cross-border EU transactions. While primarily a business identifier, it can identify sole traders and freelancers (natural persons) and may therefore constitute personal data under DSGVO Art. 4 Nr. 1 when linked to an individual.
Legal basis: § 27a UStG (Umsatzsteuergesetz). Format documentation: BZSt (Bundeszentralamt für Steuern). Data protection: DSGVO Art. 4 Nr. 1 (if linked to a natural person), BDSG.
Format (11 characters after normalisation): "DE" + 9 digits, where the 9th digit is conventionally a check digit.
Real-world formatting on invoices and Impressum pages varies: DE123456789, DE 123456789, DE-123-456-789, DE 123 456 789, de123456789, DE.123.456.789. The recognizer matches all of these via a lenient pattern and normalises them (uppercase, strip whitespace/dashes/dots) before applying the structural check.
Check-digit policy (IMPORTANT — heuristic, not normative):
The BZSt does NOT publish the USt-IdNr. Prüfziffer algorithm in any
Merkblatt or normative document. The ISO 7064 Mod 11,10 implemented
here is the de-facto community consensus (python-stdnum, VIES-
adjacent validators) and matches every officially-publicised test
vector the authors are aware of. It is empirically reliable for the
modern digit ranges used by BZSt but has no normative status.
Rejection policy therefore deliberately errs on the side of keeping
matches rather than dropping them:
- Structural failure (wrong prefix, wrong length after
normalisation, non-digit body) → return False (match dropped).
This is safe — no spec ambiguity.
- Checksum PASS → return True (max_score, high confidence).
- Checksum FAIL → depends on ``strict_checksum`` parameter:
* default (strict_checksum=False): return None. Match keeps
its base pattern score. A real USt-IdNr that happens to
fail the heuristic is NEVER silently dropped.
* strict (strict_checksum=True): return False (match
dropped). Use when false-positive reduction matters more
than false-negative prevention.
The default is the enterprise-safe choice: preserves recall on an
identifier whose authoritative validation path is BZSt/VIES, not
a locally-implemented checksum.
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
strict_checksum
|
When True, treat the ISO 7064 Mod 11,10 check as authoritative and drop matches that fail it. Default False (heuristic mode — see policy above).
TYPE:
|
name
|
Optional recognizer instance name
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
validate_result |
Validate the USt-IdNr. after real-world-tolerant normalisation. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/germany/de_vat_id_recognizer.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the USt-IdNr. after real-world-tolerant normalisation.
Returns are tri-state to reflect spec uncertainty (see class docstring):
True — structural check + ISO 7064 Mod 11,10 checksum pass. False — structural check failed, OR checksum failed in strict mode. None — structural check passed but checksum failed in the default (non-strict) mode: the match keeps its pattern score rather than being silently dropped.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the raw matched text (possibly with spaces, dashes, dots and mixed case).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
True / False / None per the semantics above. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/germany/de_vat_id_recognizer.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
InVehicleRegistrationRecognizer
Bases: PatternRecognizer
Recognizes Indian Vehicle Registration Number issued by RTO.
Reference(s): https://en.wikipedia.org/wiki/Vehicle_registration_plates_of_India https://en.wikipedia.org/wiki/Regional_Transport_Office https://en.wikipedia.org/wiki/List_of_Regional_Transport_Office_districts_in_India
The registration scheme changed over time with multiple formats in play over the years India has multiple active patterns for registration plates issued to different vehicle categories
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
replacement_pairs
|
List of tuples with potential replacement values for different strings to be used during pattern matching. This can allow a greater variety in input e.g. by removing dashes or spaces
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
validate_result |
Determine absolute value based on calculation. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/india/in_vehicle_registration_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
validate_result
validate_result(pattern_text: str) -> bool
Determine absolute value based on calculation.
Source code in presidio_analyzer/predefined_recognizers/country_specific/india/in_vehicle_registration_recognizer.py
353 354 355 356 357 358 | |
InAadhaarRecognizer
Bases: PatternRecognizer
Recognizes Indian UIDAI Person Identification Number ("AADHAAR").
Reference: https://en.wikipedia.org/wiki/Aadhaar A 12 digit unique number that is issued to each individual by Government of India
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
replacement_pairs
|
List of tuples with potential replacement values for different strings to be used during pattern matching. This can allow a greater variety in input, for example by removing dashes or spaces.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
validate_result |
Determine absolute value based on calculation. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/india/in_aadhaar_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
validate_result
validate_result(pattern_text: str) -> bool
Determine absolute value based on calculation.
Source code in presidio_analyzer/predefined_recognizers/country_specific/india/in_aadhaar_recognizer.py
63 64 65 66 67 68 | |
InGstinRecognizer
Bases: PatternRecognizer
Recognizes Indian Goods and Services Tax Identification Number ("GSTIN").
The GSTIN is a 15-character identifier with the following structure: - First 2 digits: State code (01-37) - Next 10 digits: PAN of the entity - 13th digit: Registration number for same PAN in the state - 14th digit: 'Z' - 15th digit: Checksum
Reference: https://www.gst.gov.in/ This recognizer identifies GSTIN using regex and context words.
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
replacement_pairs
|
List of tuples with potential replacement values for different strings to be used during pattern matching. This can allow a greater variety in input, for example by removing dashes or spaces.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
validate_result |
Validate the GSTIN format and structure. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/india/in_gstin_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
validate_result
validate_result(pattern_text: str) -> bool
Validate the GSTIN format and structure.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
The text pattern to validate
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if the GSTIN is valid, False otherwise |
Source code in presidio_analyzer/predefined_recognizers/country_specific/india/in_gstin_recognizer.py
81 82 83 84 85 86 87 88 89 | |
InPanRecognizer
Bases: PatternRecognizer
Recognizes Indian Permanent Account Number ("PAN").
The Permanent Account Number (PAN) is a ten digit alpha-numeric code with the last digit being a check digit calculated using a modified modulus 10 calculation. This recognizer identifies PAN using regex and context words. Reference: https://en.wikipedia.org/wiki/Permanent_account_number, https://incometaxindia.gov.in/Forms/tps/1.Permanent%20Account%20Number%20(PAN).pdf
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
replacement_pairs
|
List of tuples with potential replacement values for different strings to be used during pattern matching. This can allow a greater variety in input, for example by removing dashes or spaces.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/india/in_pan_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the pattern logic e.g., by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the validation was successful. |
Source code in presidio_analyzer/pattern_recognizer.py
136 137 138 139 140 141 142 143 144 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
InPassportRecognizer
Bases: PatternRecognizer
Recognizes Indian Passport Number.
Indian Passport Number is a eight digit alphanumeric number.
Reference: https://www.bajajallianz.com/blog/travel-insurance-articles/where-is-passport-number-in-indian-passport.html
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/india/in_passport_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the pattern logic e.g., by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the validation was successful. |
Source code in presidio_analyzer/pattern_recognizer.py
136 137 138 139 140 141 142 143 144 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
InVoterRecognizer
Bases: PatternRecognizer
Recognize Indian Voter/Election Id(EPIC).
The Elector's Photo Identity Card or Voter id is a ten digit alpha-numeric code issued by Election Commission of India to adult domiciles who have reached the age of 18 Ref: https://en.wikipedia.org/wiki/Voter_ID_(India)
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/india/in_voter_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the pattern logic e.g., by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the validation was successful. |
Source code in presidio_analyzer/pattern_recognizer.py
136 137 138 139 140 141 142 143 144 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
ItDriverLicenseRecognizer
Bases: PatternRecognizer
Recognizes IT Driver License using regex.
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/italy/it_driver_license_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the pattern logic e.g., by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the validation was successful. |
Source code in presidio_analyzer/pattern_recognizer.py
136 137 138 139 140 141 142 143 144 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
ItFiscalCodeRecognizer
Bases: PatternRecognizer
Recognizes IT Fiscal Code using regex.
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/italy/it_fiscal_code_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the pattern logic e.g., by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the validation was successful. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/italy/it_fiscal_code_recognizer.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
ItIdentityCardRecognizer
Bases: PatternRecognizer
Recognizes Italian Identity Card number using case-insensitive regex.
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/italy/it_identity_card_recognizer.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the pattern logic e.g., by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the validation was successful. |
Source code in presidio_analyzer/pattern_recognizer.py
136 137 138 139 140 141 142 143 144 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
ItPassportRecognizer
Bases: PatternRecognizer
Recognizes IT Passport number using case-insensitive regex.
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/italy/it_passport_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the pattern logic e.g., by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the validation was successful. |
Source code in presidio_analyzer/pattern_recognizer.py
136 137 138 139 140 141 142 143 144 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
ItVatCodeRecognizer
Bases: PatternRecognizer
Recognizes Italian VAT code using regex and checksum.
For more information about italian VAT code: https://en.wikipedia.org/wiki/VAT_identification_number#:~:text=%5B2%5D)-,Italy,-Partita%20IVA
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
replacement_pairs
|
List of tuples with potential replacement values for different strings to be used during pattern matching. This can allow a greater variety in input, for example by removing dashes or spaces.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/italy/it_vat_code.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
validate_result
validate_result(pattern_text: str) -> bool
Validate the pattern logic e.g., by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
A bool indicating whether the validation was successful. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/italy/it_vat_code.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
KrBrnRecognizer
Bases: PatternRecognizer
Recognize Korean Business Registration Number (BRN).
The Korean Business Registration Number (BRN) is a 10-digit number assigned to businesses in South Korea for taxation purposes.
The format is AAA-BB-CCCCC where: - AAA: District office code - BB: Type of business code - CCCCC: Serial number and check digit
Reference: https://org-id.guide/list/KR-BRN
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
replacement_pairs
|
List of tuples with potential replacement values to be used during pattern matching (e.g., removing dashes).
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
validate_result |
Validate the pattern logic by running a checksum on a detected BRN. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/korea/kr_brn_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
validate_result
validate_result(pattern_text: str) -> Union[bool, None]
Validate the pattern logic by running a checksum on a detected BRN.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
The text detected by the regex engine.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Union[bool, None]
|
True if validation is successful, False otherwise. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/korea/kr_brn_recognizer.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
KrDriverLicenseRecognizer
Bases: PatternRecognizer
Recognize Korean Driver's License Number.
The Korean Driver's License Number consists of 12 digits, typically formatted as AA-BB-CCCCCC-DD.
Format Breakdown: - AA: Regional code - BB: Year of issuance (last two digits of the year) - CCCCCC: Serial number - DD: Check digit (Verification number; not publicly disclosed)
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
replacement_pairs
|
List of tuples with potential replacement values for different strings to be used during pattern matching. This can allow a greater variety in input, for example by removing dashes.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
validate_result |
Validate length, region code. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/korea/kr_driver_license_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
validate_result
validate_result(pattern_text: str) -> bool
Validate length, region code.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
A bool or None, indicating whether the validation was successful. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/korea/kr_driver_license_recognizer.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
KrFrnRecognizer
Bases: KrRrnRecognizer
Recognize Korean Foreigner Registration Number (FRN).
The Korean FRN is a 13-digit number issued to registered foreigners in Korea. The format is YYMMDD-GHIJKLX where: - YYMMDD represents the birth date. - G determines gender and century (5-8). - 5: Male, 1900-1999 birth - 6: Female, 1900-1999 birth - 7: Male, 2000-2099 birth - 8: Female, 2000-2099 birth - (Note: 9 and 0 are sometimes used for 1800s birth, but rare)
For FRNs issued before October 2020: - HIJKL is a serial number assigned by district - X is a check digit calculated using the preceding 12 digits
For FRNs issued after October 2020: - HIJKLX is a random number
Reference: https://en.wikipedia.org/wiki/Resident_registration_number
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
replacement_pairs
|
List of tuples with potential replacement values for different strings to be used during pattern matching. This can allow a greater variety in input, for example by removing dashes.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/korea/kr_frn_recognizer.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the pattern logic e.g., by running checksum on a detected pattern.
This validation is only for RRNs issued before October 2020. Therefore, it returns None, not False, at the end of the method.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool or None, indicating whether the validation was successful. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/korea/kr_rrn_recognizer.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
KrPassportRecognizer
Bases: PatternRecognizer
Recognize Korean Passport Number.
https://learn.microsoft.com/en-us/purview/sit-defn-south-korea-passport-number
the current passport number format: - one letter 'M' or 'm' or 'S' or 's' or 'R' or 'r' or 'O' or 'o' or 'D' or 'd' - three digits - one letter (A-Z, a-z) - four digits
the previous passport number format: - one letter 'M' or 'm' or 'S' or 's' or 'R' or 'r' or 'O' or 'o' or 'D' or 'd' - eight digits
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/korea/kr_passport_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the pattern logic e.g., by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the validation was successful. |
Source code in presidio_analyzer/pattern_recognizer.py
136 137 138 139 140 141 142 143 144 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
KrRrnRecognizer
Bases: PatternRecognizer
Recognize Korean Resident Registration Number (RRN).
The Korean Resident Registration Number (RRN) is a 13-digit number issued to all Korean residents.
The format is YYMMDD-GHIJKLX where: - YYMMDD represents the birth date - G determines gender and century of birth
For RRNs issued before October 2020: - HIJKL is a serial number assigned by district - X is a check digit calculated using the preceding 12 digits
For RRNs issued after October 2020: - HIJKLX is a random number
Reference: https://en.wikipedia.org/wiki/Resident_registration_number
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
replacement_pairs
|
List of tuples with potential replacement values for different strings to be used during pattern matching. This can allow a greater variety in input, for example by removing dashes.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/korea/kr_rrn_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the pattern logic e.g., by running checksum on a detected pattern.
This validation is only for RRNs issued before October 2020. Therefore, it returns None, not False, at the end of the method.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool or None, indicating whether the validation was successful. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/korea/kr_rrn_recognizer.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
NgNinRecognizer
Bases: PatternRecognizer
Recognizes Nigerian National Identification Number (NIN).
The NIN is an 11-digit number issued by the National Identity Management Commission (NIMC). The last digit is a Verhoeff checksum.
Reference: https://nimc.gov.ng/
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
validate_result |
Validate the NIN by checking length, digits, and Verhoeff checksum. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/nigeria/ng_nin_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
validate_result
validate_result(pattern_text: str) -> bool
Validate the NIN by checking length, digits, and Verhoeff checksum.
Source code in presidio_analyzer/predefined_recognizers/country_specific/nigeria/ng_nin_recognizer.py
59 60 61 | |
NgVehicleRegistrationRecognizer
Bases: PatternRecognizer
Recognizes Nigerian vehicle registration plate numbers (current format, 2011+).
The current format is: ABC-123DE - 3 letters: LGA (Local Government Area) code - Hyphen separator (may be omitted or replaced with space) - 3 digits: serial number (001-999) - 2 letters: year code + batch code
Reference: https://en.wikipedia.org/wiki/Vehicle_registration_plates_of_Nigeria
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/nigeria/ng_vehicle_registration_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the pattern logic e.g., by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the validation was successful. |
Source code in presidio_analyzer/pattern_recognizer.py
136 137 138 139 140 141 142 143 144 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
PhTinRecognizer
Bases: PatternRecognizer
Recognizes Philippines Taxpayer Identification Number (TIN).
The TIN is a 9 or 12-digit number issued by the Bureau of Internal Revenue (BIR). The 9th digit is a check digit calculated using a weighted modulo 11 algorithm. The last 3 digits (in the 12-digit version) represent the branch code (default 000).
Formats: XXXXXXXXX, XXXXXXXXXXXX, XXX-XXX-XXX, or XXX-XXX-XXX-XXX Reference: https://www.bir.gov.ph/
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
replacement_pairs
|
List of tuples with potential replacement values
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
invalidate_result |
Check if the Philippines TIN fails weighted modulo 11 validation. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/philippines/ph_tin_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the pattern logic e.g., by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the validation was successful. |
Source code in presidio_analyzer/pattern_recognizer.py
136 137 138 139 140 141 142 143 144 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
invalidate_result
invalidate_result(pattern_text: str) -> bool
Check if the Philippines TIN fails weighted modulo 11 validation.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
The text to validate
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if invalid, False otherwise |
Source code in presidio_analyzer/predefined_recognizers/country_specific/philippines/ph_tin_recognizer.py
69 70 71 72 73 74 75 76 | |
PlPeselRecognizer
Bases: PatternRecognizer
Recognize PESEL number using regex and checksum.
For more information about PESEL: https://en.wikipedia.org/wiki/PESEL
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/poland/pl_pesel_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
SgFinRecognizer
Bases: PatternRecognizer
Recognize SG FIN/NRIC number using regex.
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/singapore/sg_fin_recognizer.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the pattern logic e.g., by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the validation was successful. |
Source code in presidio_analyzer/pattern_recognizer.py
136 137 138 139 140 141 142 143 144 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
SgUenRecognizer
Bases: PatternRecognizer
Recognize Singapore UEN (Unique Entity Number) using regex.
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
validate_uen_format_a |
Validate the UEN format A using checksum. |
validate_uen_format_b |
Validate the UEN format B using checksum. |
validate_uen_format_c |
Validate the UEN format C using checksum. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/singapore/sg_uen_recognizer.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the pattern logic e.g., by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the validation was successful. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/singapore/sg_uen_recognizer.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
validate_uen_format_a
staticmethod
validate_uen_format_a(uen: str) -> bool
Validate the UEN format A using checksum.
| PARAMETER | DESCRIPTION |
|---|---|
uen
|
The UEN to validate.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if the UEN is valid according to its respective format, False otherwise. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/singapore/sg_uen_recognizer.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
validate_uen_format_b
staticmethod
validate_uen_format_b(uen: str) -> bool
Validate the UEN format B using checksum.
| PARAMETER | DESCRIPTION |
|---|---|
uen
|
The UEN to validate.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if the UEN is valid according to its respective format, False otherwise. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/singapore/sg_uen_recognizer.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
validate_uen_format_c
staticmethod
validate_uen_format_c(uen: str) -> bool
Validate the UEN format C using checksum.
| PARAMETER | DESCRIPTION |
|---|---|
uen
|
The UEN to validate.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if the UEN is valid according to its respective format, False otherwise. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/singapore/sg_uen_recognizer.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
ZaIdNumberRecognizer
Bases: PatternRecognizer
Recognize South African ID numbers using regex and structural validation.
South African identity numbers are 13 digits in the YYMMDDSSSSCAZ
layout:
- YYMMDD: date of birth (two-digit year mapped to a full year using a
rolling pivot: if YY is greater than the last two digits of the
current calendar year, the year is interpreted as 19YY; otherwise 20YY.
The resulting date must be valid and cannot be in the future.)
- SSSS: sequence number
- C: citizenship / status — 0 = SA citizen, 1 = permanent resident,
2 = refugee
- A: obsolete race-classification digit (typically 8 or 9)
- Z: check digit using the Luhn algorithm
Reference: https://en.wikipedia.org/wiki/South_African_identity_card#Identity_Number https://www.irb-cisr.gc.ca/en/country-information/rir/Pages/index.aspx?doc=454798
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/south_africa/za_id_number_recognizer.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
EsNieRecognizer
Bases: PatternRecognizer
Recognize NIE number using regex and checksum.
Reference(s): https://es.wikipedia.org/wiki/N%C3%BAmero_de_identidad_de_extranjero https://www.interior.gob.es/opencms/ca/servicios-al-ciudadano/tramites-y-gestiones/dni/calculo-del-digito-de-control-del-nif-nie/
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
replacement_pairs
|
List of tuples with potential replacement values for different strings to be used during pattern matching. This can allow a greater variety in input, for example by removing dashes or spaces.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
validate_result |
Validate the pattern by using the control character. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/spain/es_nie_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
validate_result
validate_result(pattern_text: str) -> bool
Validate the pattern by using the control character.
Source code in presidio_analyzer/predefined_recognizers/country_specific/spain/es_nie_recognizer.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
EsNifRecognizer
Bases: PatternRecognizer
Recognize NIF number using regex and checksum.
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
replacement_pairs
|
List of tuples with potential replacement values for different strings to be used during pattern matching. This can allow a greater variety in input, for example by removing dashes or spaces.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/spain/es_nif_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
EsPassportRecognizer
Bases: PatternRecognizer
Recognize Spanish passport numbers using regex.
Follows the format: 3 letters followed by 6 digits (e.g. AAA123456).
Reference(s): https://en.wikipedia.org/wiki/Spanish_passport
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/spain/es_passport_recognizer.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the pattern logic e.g., by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the validation was successful. |
Source code in presidio_analyzer/pattern_recognizer.py
136 137 138 139 140 141 142 143 144 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
SeOrganisationsnummerRecognizer
Bases: PatternRecognizer
Recognizes and validates Swedish Organisationsnummer.
Rules: * 10 digits: NNNNNNXXXX (optional hyphen) * Third digit >= 2 * Luhn checksum validation
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
validate_result |
Validate Organisationsnummer. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/sweden/se_organisationsnummer_recognizer.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate Organisationsnummer.
Source code in presidio_analyzer/predefined_recognizers/country_specific/sweden/se_organisationsnummer_recognizer.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
SePersonnummerRecognizer
Bases: PatternRecognizer
Recognizes and validates Swedish Personal Identity Numbers.
The recogniser follows the full guard‑rail logic:
* Regex covers YYMMDD[-+]XXXX and YYYYMMDD[-+]XXXX.
* Date validation accommodates samordningsnummer (day ≥ 61).
* Luhn checksum is applied to the last 10 digits.
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
validate_result |
Validate a candidate Personnummer. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/sweden/se_personnummer_recognizer.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate a candidate Personnummer.
The validation pipeline: 1 Normalise to the last 10 digits. 2 Verify the date component (including samordningsnummer handling). 3 Apply the Luhn checksum.
Source code in presidio_analyzer/predefined_recognizers/country_specific/sweden/se_personnummer_recognizer.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
ThTninRecognizer
Bases: PatternRecognizer
Recognize Thai National ID Number (TNIN).
The Thai National ID Number (TNIN) is a unique 13-digit number issued to all Thai residents.
The format is N1N2N3N4N5N6N7N8N9N10N11N12N13 where: - N1-N12 are the main digits - N13 is a check digit calculated using the preceding 12 digits
Validation rules: - Must be exactly 13 digits - First digit (N1) cannot be 0 - Second digit (N2) cannot be 0 - Second and third digits (N2N3) cannot be: 28, 29, 59, 68, 69, 78, 79, 87, 88, 89, 97, 98, 99 These second and third digits in Thai ID number correspond to Thai provinces, so we exclude non-existent or unassigned combinations in Thailand's administrative division system. See ISO 3166-2:TH for reference. - The 13th digit is a checksum computed modulo 11 from the first 12 digits
Checksum algorithm: - Label first 12 digits N1…N12 (left to right) - Compute S = 13·N1 + 12·N2 + … + 2·N12 - Let x = S mod 11 - Then check digit N13 = (11 − x) mod 10 - Equivalently: if x ≤ 1 then N13 = 1 − x; otherwise N13 = 11 − x
Reference: https://th.wikipedia.org/wiki/เลขประจำตัวประชาชนไทย https://th.wikipedia.org/wiki/ISO_3166-2:TH
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
replacement_pairs
|
List of tuples with potential replacement values for different strings to be used during pattern matching.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/thai/th_tnin_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
validate_result
validate_result(pattern_text: str) -> Union[bool, None]
Validate the pattern logic e.g., by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Union[bool, None]
|
A bool or None, indicating whether the validation was successful. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/thai/th_tnin_recognizer.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
TrLicensePlateRecognizer
Bases: PatternRecognizer
Recognize Turkish vehicle license plates (plaka).
Standard civilian format: [province_code 01-81][1-3 letters] [2-4 digits]. Province codes: 01-81 (81 Turkish provinces). Letters: A-Z excluding Q, W, X (not in Turkish alphabet).
Examples: 34 ABC 1234 (Istanbul), 06 A 123 (Ankara), 35 JK 12 (Izmir).
Legal basis: Karayolları Trafik Kanunu (KTK) Madde 23. Data protection: KVKK (Kişisel Verilerin Korunması Kanunu) — license plates constitute personal data when linked to an identifiable vehicle owner.
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
replacement_pairs
|
List of tuples with potential replacement values for different strings to be used during pattern matching.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
validate_result |
Validate the matched pattern by checking province code is 01-81. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/turkey/tr_license_plate_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
validate_result
validate_result(pattern_text: str) -> Union[bool, None]
Validate the matched pattern by checking province code is 01-81.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
The matched text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Union[bool, None]
|
True if province code valid, False if invalid, None if not a plate |
Source code in presidio_analyzer/predefined_recognizers/country_specific/turkey/tr_license_plate_recognizer.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
TrNationalIdRecognizer
Bases: PatternRecognizer
Recognize Turkish National Identification Number (TC Kimlik No / TCKN).
The Turkish National ID is an 11-digit number where: - First digit cannot be 0 - 10th digit = (sum_of_odd_positions * 7 - sum_of_even_positions) % 10 - 11th digit = (sum of first 10 digits) % 10
Checksum validation based on the official Nüfus ve Vatandaşlık İşleri Genel Müdürlüğü (NVI) algorithm, referenced in KVKK compliance guidelines. See: https://tckimlik.nvi.gov.tr/ (NVİ official service portal)
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
replacement_pairs
|
List of tuples with potential replacement values for different strings to be used during pattern matching.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
validate_result |
Validate the pattern logic by running checksum on a detected pattern. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/turkey/tr_national_id_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
validate_result
validate_result(pattern_text: str) -> Union[bool, None]
Validate the pattern logic by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Union[bool, None]
|
A bool or None, indicating whether the validation was successful. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/turkey/tr_national_id_recognizer.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
UkDrivingLicenceRecognizer
Bases: PatternRecognizer
Recognizes UK driving licence numbers issued by the DVLA.
The licence number is a 16-character alphanumeric string encoding the holder's surname, date of birth, and initials.
Format: SSSSS NMMDD NIIXA A - Positions 1-5: Surname (A-Z, padded with trailing 9s) - Position 6: Decade digit of birth year - Positions 7-8: Month of birth (01-12, or 51-62 for female) - Positions 9-10: Day of birth (01-31) - Position 11: Last digit of birth year - Positions 12-13: Initials (A-Z or 9 if none) - Position 14: Arbitrary/check digit - Positions 15-16: Computer check digits
Reference: https://en.wikipedia.org/wiki/Driver%27s_license_in_the_United_Kingdom
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
validate_result |
Validate the pattern logic for a UK driving licence number. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/uk/uk_driving_licence_recognizer.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the pattern logic for a UK driving licence number.
Since the DVLA check digit algorithm is not public, this method cannot confirm a valid licence (returns None). It can however reject clearly invalid patterns (returns False).
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validate.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
None if the pattern is plausible, False if clearly invalid. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/uk/uk_driving_licence_recognizer.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
NhsRecognizer
Bases: PatternRecognizer
Recognizes NHS number using regex and checksum.
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
replacement_pairs
|
List of tuples with potential replacement values for different strings to be used during pattern matching. This can allow a greater variety in input, for example by removing dashes or spaces.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/uk/uk_nhs_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
validate_result
validate_result(pattern_text: str) -> bool
Validate the pattern logic e.g., by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
A bool indicating whether the validation was successful. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/uk/uk_nhs_recognizer.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
UkNinoRecognizer
Bases: PatternRecognizer
Recognizes UK National Insurance Number using regex.
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/uk/uk_nino_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the pattern logic e.g., by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the validation was successful. |
Source code in presidio_analyzer/pattern_recognizer.py
136 137 138 139 140 141 142 143 144 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
UkPassportRecognizer
Bases: PatternRecognizer
Recognizes UK passport numbers using regex.
UK passports issued from 2015 onwards use a 2-letter prefix followed by 7 digits (e.g., AB1234567).
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/uk/uk_passport_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the pattern logic e.g., by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the validation was successful. |
Source code in presidio_analyzer/pattern_recognizer.py
136 137 138 139 140 141 142 143 144 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
UkPostcodeRecognizer
Bases: PatternRecognizer
Recognizes UK postcodes using regex.
UK postcodes follow strict position-specific letter rules across six formats (A9 9AA, A99 9AA, A9A 9AA, AA9 9AA, AA99 9AA, AA9A 9AA) plus the special GIR 0AA code.
Reference: https://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/uk/uk_postcode_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the pattern logic e.g., by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the validation was successful. |
Source code in presidio_analyzer/pattern_recognizer.py
136 137 138 139 140 141 142 143 144 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
UkVehicleRegistrationRecognizer
Bases: PatternRecognizer
Recognizes UK vehicle registration numbers using regex.
Supports three formats still commonly seen on the road:
- Current (2001+): 2 area letters + 2-digit age id + 3 random letters e.g. AB51 ABC
- Prefix (1983-2001): year letter + 1-3 digits + 3 letters e.g. A123 BCD
- Suffix (1963-1983): 3 letters + 1-3 digits + year letter e.g. ABC 123D
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
replacement_pairs
|
List of tuples for replacing characters in the pattern text for validation
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
validate_result |
Validate the matched pattern. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/uk/uk_vehicle_registration_recognizer.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the matched pattern.
Only the current format (2001+) is validated further by checking that the two-digit age identifier falls in a valid range: 02-29 (March registrations) or 51-79 (September registrations).
Prefix and suffix formats return None (keep base score).
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
The matched text to validate
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
True if valid current format, False if invalid current format, None for prefix/suffix formats |
Source code in presidio_analyzer/predefined_recognizers/country_specific/uk/uk_vehicle_registration_recognizer.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
AbaRoutingRecognizer
Bases: PatternRecognizer
Recognize American Banking Association (ABA) routing number.
Also known as routing transit number (RTN) and used to identify financial institutions and process transactions.
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
replacement_pairs
|
List of tuples with potential replacement values for different strings to be used during pattern matching. This can allow a greater variety in input, for example by removing dashes or spaces.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/us/aba_routing_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
MedicalLicenseRecognizer
Bases: PatternRecognizer
Recognize common Medical license numbers using regex + checksum.
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
replacement_pairs
|
List of tuples with potential replacement values for different strings to be used during pattern matching. This can allow a greater variety in input, for example by removing dashes or spaces.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/us/medical_license_recognizer.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
UsBankRecognizer
Bases: PatternRecognizer
Recognizes US bank number using regex.
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/us/us_bank_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the pattern logic e.g., by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the validation was successful. |
Source code in presidio_analyzer/pattern_recognizer.py
136 137 138 139 140 141 142 143 144 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
UsLicenseRecognizer
Bases: PatternRecognizer
Recognizes US driver license using regex.
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/us/us_driver_license_recognizer.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the pattern logic e.g., by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the validation was successful. |
Source code in presidio_analyzer/pattern_recognizer.py
136 137 138 139 140 141 142 143 144 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
UsItinRecognizer
Bases: PatternRecognizer
Recognizes US ITIN (Individual Taxpayer Identification Number) using regex.
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/us/us_itin_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the pattern logic e.g., by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the validation was successful. |
Source code in presidio_analyzer/pattern_recognizer.py
136 137 138 139 140 141 142 143 144 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
UsMbiRecognizer
Bases: PatternRecognizer
Recognize US Medicare Beneficiary Identifier (MBI) using regex.
The MBI is an 11-character identifier used by Medicare. The format follows specific rules defined by CMS (Centers for Medicare & Medicaid Services): https://www.cms.gov/medicare/new-medicare-card/understanding-new-medicare-beneficiary-identifier-mbi
Format: C A AN N A AN N A A N N Where: - C = numeric character (0-9) - A = alphabetic character (excluding S, L, O, I, B, Z) - AN = alphanumeric character (numeric or alphabetic, excluding S, L, O, I, B, Z)
Position rules: - Positions 1, 4, 7, 10, 11: numeric (0-9) - Positions 2, 5, 8, 9: alphabetic - Positions 3, 6: alphanumeric
Example: 1EG4-TE5-MK73 (dashes are for display only)
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/us/us_mbi_recognizer.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the pattern logic e.g., by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the validation was successful. |
Source code in presidio_analyzer/pattern_recognizer.py
136 137 138 139 140 141 142 143 144 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
UsNpiRecognizer
Bases: PatternRecognizer
Recognize US National Provider Identifier (NPI) using regex + checksum.
The NPI is a unique 10-digit number assigned to healthcare providers in the United States by CMS (Centers for Medicare & Medicaid Services). It is a HIPAA-mandated identifier that appears on insurance claims, prescriptions, and provider directories.
Format: - Exactly 10 digits - Starts with 1 (Type 1, individual) or 2 (Type 2, organization) - Last digit is a Luhn check digit (using "80840" prefix per CMS spec)
Reference: https://www.cms.gov/Regulations-and-Guidance/Administrative-Simplification/NationalProvIdentStand
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
replacement_pairs
|
List of tuples with potential replacement values for different strings to be used during pattern matching. This can allow a greater variety in input, for example by removing dashes or spaces.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/us/us_npi_recognizer.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
UsPassportRecognizer
Bases: PatternRecognizer
Recognizes US Passport number using regex.
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/us/us_passport_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the pattern logic e.g., by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the validation was successful. |
Source code in presidio_analyzer/pattern_recognizer.py
136 137 138 139 140 141 142 143 144 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
UsSsnRecognizer
Bases: PatternRecognizer
Recognize US Social Security Number (SSN) using regex.
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
invalidate_result |
Check if the pattern text cannot be validated as a US_SSN entity. |
Source code in presidio_analyzer/predefined_recognizers/country_specific/us/us_ssn_recognizer.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the pattern logic e.g., by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the validation was successful. |
Source code in presidio_analyzer/pattern_recognizer.py
136 137 138 139 140 141 142 143 144 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
invalidate_result
invalidate_result(pattern_text: str) -> bool
Check if the pattern text cannot be validated as a US_SSN entity.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
Text detected as pattern by regex
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if invalidated |
Source code in presidio_analyzer/predefined_recognizers/country_specific/us/us_ssn_recognizer.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
CreditCardRecognizer
Bases: PatternRecognizer
Recognize common credit card numbers using regex + checksum.
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
replacement_pairs
|
List of tuples with potential replacement values for different strings to be used during pattern matching. This can allow a greater variety in input, for example by removing dashes or spaces.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
Source code in presidio_analyzer/predefined_recognizers/generic/credit_card_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
CryptoRecognizer
Bases: PatternRecognizer
Recognize common crypto account numbers using regex + checksum.
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
validate_result |
Validate the Bitcoin address using checksum. |
bech32_polymod |
Compute the Bech32 checksum. |
bech32_hrp_expand |
Expand the HRP into values for checksum computation. |
bech32_verify_checksum |
Verify a checksum given HRP and converted data characters. |
bech32_decode |
Validate a Bech32/Bech32m string, and determine HRP and data. |
validate_bech32_address |
Validate a Bech32 or Bech32m address. |
Source code in presidio_analyzer/predefined_recognizers/generic/crypto_recognizer.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
validate_result
validate_result(pattern_text: str) -> bool
Validate the Bitcoin address using checksum.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
The cryptocurrency address to validate.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if the address is valid according to its respective format, False otherwise. |
Source code in presidio_analyzer/predefined_recognizers/generic/crypto_recognizer.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
bech32_polymod
staticmethod
bech32_polymod(values)
Compute the Bech32 checksum.
Source code in presidio_analyzer/predefined_recognizers/generic/crypto_recognizer.py
86 87 88 89 90 91 92 93 94 95 96 | |
bech32_hrp_expand
staticmethod
bech32_hrp_expand(hrp)
Expand the HRP into values for checksum computation.
Source code in presidio_analyzer/predefined_recognizers/generic/crypto_recognizer.py
98 99 100 101 | |
bech32_verify_checksum
staticmethod
bech32_verify_checksum(hrp, data)
Verify a checksum given HRP and converted data characters.
Source code in presidio_analyzer/predefined_recognizers/generic/crypto_recognizer.py
103 104 105 106 107 108 109 110 111 112 113 | |
bech32_decode
staticmethod
bech32_decode(bech)
Validate a Bech32/Bech32m string, and determine HRP and data.
Source code in presidio_analyzer/predefined_recognizers/generic/crypto_recognizer.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |
validate_bech32_address
staticmethod
validate_bech32_address(address)
Validate a Bech32 or Bech32m address.
Source code in presidio_analyzer/predefined_recognizers/generic/crypto_recognizer.py
135 136 137 138 139 140 141 | |
DateRecognizer
Bases: PatternRecognizer
Recognize date using regex.
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
Source code in presidio_analyzer/predefined_recognizers/generic/date_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the pattern logic e.g., by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the validation was successful. |
Source code in presidio_analyzer/pattern_recognizer.py
136 137 138 139 140 141 142 143 144 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
EmailRecognizer
Bases: PatternRecognizer
Recognize email addresses using regex.
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
Source code in presidio_analyzer/predefined_recognizers/generic/email_recognizer.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
IbanRecognizer
Bases: PatternRecognizer
Recognize IBAN code using regex and checksum.
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
exact_match
|
Whether patterns should be exactly matched or not
TYPE:
|
bos_eos
|
Tuple of strings for beginning of string (BOS) and end of string (EOS)
TYPE:
|
regex_flags
|
Regex flags options
TYPE:
|
replacement_pairs
|
List of tuples with potential replacement values for different strings to be used during pattern matching. This can allow a greater variety in input, for example by removing dashes or spaces.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
analyze |
Analyze IBAN. |
Source code in presidio_analyzer/predefined_recognizers/generic/iban_recognizer.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: NlpArtifacts = None,
regex_flags: int = None,
) -> List[RecognizerResult]
Analyze IBAN.
Source code in presidio_analyzer/predefined_recognizers/generic/iban_recognizer.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
IpRecognizer
Bases: PatternRecognizer
Recognize IP address using regex.
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
invalidate_result |
Check if the pattern text cannot be validated as an IP address. |
Source code in presidio_analyzer/predefined_recognizers/generic/ip_recognizer.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the pattern logic e.g., by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the validation was successful. |
Source code in presidio_analyzer/pattern_recognizer.py
136 137 138 139 140 141 142 143 144 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
invalidate_result
invalidate_result(pattern_text: str) -> bool
Check if the pattern text cannot be validated as an IP address.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
Text detected as pattern by regex
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if invalidated |
Source code in presidio_analyzer/predefined_recognizers/generic/ip_recognizer.py
65 66 67 68 69 70 71 72 73 74 75 | |
MacAddressRecognizer
Bases: PatternRecognizer
Recognize MAC (Media Access Control) address using regex.
Supports three common MAC address formats: - Colon-separated: 00:1A:2B:3C:4D:5E - Hyphen-separated: 00-1A-2B-3C-4D-5E - Cisco format (dot-separated groups of 4): 0012.3456.789A
ref : - https://en.wikipedia.org/wiki/MAC_address#Notational_conventions - https://www.ieee802.org/1/files/public/docs2020/yangsters-smansfield-mac-address-format-0420-v01.pdf
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
invalidate_result |
Check if the pattern text is a valid MAC address format. |
Source code in presidio_analyzer/predefined_recognizers/generic/mac_recognizer.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the pattern logic e.g., by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the validation was successful. |
Source code in presidio_analyzer/pattern_recognizer.py
136 137 138 139 140 141 142 143 144 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
invalidate_result
invalidate_result(pattern_text: str) -> bool
Check if the pattern text is a valid MAC address format.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
Text detected as pattern by regex
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if invalidated (invalid MAC address) |
Source code in presidio_analyzer/predefined_recognizers/generic/mac_recognizer.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
PhoneRecognizer
Bases: LocalRecognizer
Recognize multi-regional phone numbers.
Using python-phonenumbers, along with fixed and regional context words.
| PARAMETER | DESCRIPTION |
|---|---|
context
|
Base context words for enhancing the assurance scores.
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
supported_regions
|
The regions for phone number matching and validation
DEFAULT:
|
leniency
|
The strictness level of phone number formats. Accepts values from 0 to 3, where 0 is the lenient and 3 is the most strictest.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize self to dictionary. |
from_dict |
Create EntityRecognizer from a dict input. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
analyze |
Analyzes text to detect phone numbers using python-phonenumbers. |
Source code in presidio_analyzer/predefined_recognizers/generic/phone_recognizer.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize self to dictionary.
| RETURNS | DESCRIPTION |
|---|---|
Dict
|
a dictionary |
Source code in presidio_analyzer/entity_recognizer.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> EntityRecognizer
Create EntityRecognizer from a dict input.
| PARAMETER | DESCRIPTION |
|---|---|
entity_recognizer_dict
|
Dict containing keys and values for instantiation
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
249 250 251 252 253 254 255 256 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
analyze
analyze(
text: str, entities: List[str], nlp_artifacts: NlpArtifacts = None
) -> List[RecognizerResult]
Analyzes text to detect phone numbers using python-phonenumbers.
Iterates over entities, fetching regions, then matching regional phone number patterns against the text.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Additional metadata from the NLP engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List of phone numbers RecognizerResults |
Source code in presidio_analyzer/predefined_recognizers/generic/phone_recognizer.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
UrlRecognizer
Bases: PatternRecognizer
Recognize urls using regex.
This application uses Open Source components: Project: CommonRegex https://github.com/madisonmay/CommonRegex Copyright (c) 2014 Madison May License (MIT) https://github.com/madisonmay/CommonRegex/blob/master/LICENSE
| PARAMETER | DESCRIPTION |
|---|---|
patterns
|
List of patterns to be used by this recognizer
TYPE:
|
context
|
List of context words to increase confidence in detection
TYPE:
|
supported_language
|
Language this recognizer supports
TYPE:
|
supported_entity
|
The entity this recognizer can detect
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyzes text to detect PII using regular expressions or deny-lists. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize instance into a dictionary. |
from_dict |
Create instance from a serialized dict. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
validate_result |
Validate the pattern logic e.g., by running checksum on a detected pattern. |
invalidate_result |
Logic to check for result invalidation by running pruning logic. |
build_regex_explanation |
Construct an explanation for why this entity was detected. |
Source code in presidio_analyzer/predefined_recognizers/generic/url_recognizer.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: List[str],
nlp_artifacts: Optional[NlpArtifacts] = None,
regex_flags: Optional[int] = None,
) -> List[RecognizerResult]
Analyzes text to detect PII using regular expressions or deny-lists.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to be analyzed
TYPE:
|
entities
|
Entities this recognizer can detect
TYPE:
|
nlp_artifacts
|
Output values from the NLP engine
TYPE:
|
regex_flags
|
regex flags to be used in regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
|
Source code in presidio_analyzer/pattern_recognizer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize instance into a dictionary.
Source code in presidio_analyzer/pattern_recognizer.py
283 284 285 286 287 288 289 290 291 292 293 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> PatternRecognizer
Create instance from a serialized dict.
Source code in presidio_analyzer/pattern_recognizer.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
validate_result
validate_result(pattern_text: str) -> Optional[bool]
Validate the pattern logic e.g., by running checksum on a detected pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the validation was successful. |
Source code in presidio_analyzer/pattern_recognizer.py
136 137 138 139 140 141 142 143 144 | |
invalidate_result
invalidate_result(pattern_text: str) -> Optional[bool]
Logic to check for result invalidation by running pruning logic.
For example, each SSN number group should not consist of all the same digits.
| PARAMETER | DESCRIPTION |
|---|---|
pattern_text
|
the text to validated. Only the part in text that was detected by the regex engine
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool]
|
A bool indicating whether the result is invalidated |
Source code in presidio_analyzer/pattern_recognizer.py
146 147 148 149 150 151 152 153 154 155 156 | |
build_regex_explanation
staticmethod
build_regex_explanation(
recognizer_name: str,
pattern_name: str,
pattern: str,
original_score: float,
validation_result: bool,
regex_flags: int,
) -> AnalysisExplanation
Construct an explanation for why this entity was detected.
| PARAMETER | DESCRIPTION |
|---|---|
recognizer_name
|
Name of recognizer detecting the entity
TYPE:
|
pattern_name
|
Regex pattern name which detected the entity
TYPE:
|
pattern
|
Regex pattern logic
TYPE:
|
original_score
|
Score given by the recognizer
TYPE:
|
validation_result
|
Whether validation was used and its result
TYPE:
|
regex_flags
|
Regex flags used in the regex matching
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
Analysis explanation |
Source code in presidio_analyzer/pattern_recognizer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
GLiNERRecognizer
Bases: LocalRecognizer
GLiNER model based entity recognizer.
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize self to dictionary. |
from_dict |
Create EntityRecognizer from a dict input. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
load |
Load the GLiNER model. |
analyze |
Analyze text to identify entities using a GLiNER model. |
Source code in presidio_analyzer/predefined_recognizers/ner/gliner_recognizer.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize self to dictionary.
| RETURNS | DESCRIPTION |
|---|---|
Dict
|
a dictionary |
Source code in presidio_analyzer/entity_recognizer.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> EntityRecognizer
Create EntityRecognizer from a dict input.
| PARAMETER | DESCRIPTION |
|---|---|
entity_recognizer_dict
|
Dict containing keys and values for instantiation
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
249 250 251 252 253 254 255 256 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
load
load() -> None
Load the GLiNER model.
Source code in presidio_analyzer/predefined_recognizers/ner/gliner_recognizer.py
144 145 146 147 148 149 150 151 152 153 154 155 | |
analyze
analyze(
text: str, entities: List[str], nlp_artifacts: Optional[NlpArtifacts] = None
) -> List[RecognizerResult]
Analyze text to identify entities using a GLiNER model.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The text to be analyzed
TYPE:
|
entities
|
The list of entities this recognizer is requested to return
TYPE:
|
nlp_artifacts
|
N/A for this recognizer
TYPE:
|
Source code in presidio_analyzer/predefined_recognizers/ner/gliner_recognizer.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |
HuggingFaceNerRecognizer
Bases: LocalRecognizer
HuggingFace Transformers based NER Recognizer.
This recognizer uses HuggingFace pipeline directly for NER, bypassing spaCy tokenizer alignment issues. It's particularly useful for agglutinative languages (Korean, Japanese, Turkish, etc.) where particles attach to nouns.
Unlike the standard TransformersNlpEngine approach, this recognizer: - Uses HuggingFace pipeline directly (not through spaCy) - Returns NER results without char_span alignment - Supports any HuggingFace token-classification model - Works with any language that has a HuggingFace NER model
Example: >>> from presidio_analyzer import AnalyzerEngine >>> from presidio_analyzer.predefined_recognizers.ner import ( ... HuggingFaceNerRecognizer ... ) >>> >>> # For Korean >>> recognizer = HuggingFaceNerRecognizer( ... model_name="test-owner/test-model", ... supported_language="ko" ... ) >>> >>> # For English >>> recognizer = HuggingFaceNerRecognizer( ... model_name="dslim/bert-base-NER", ... supported_language="en" ... ) >>> >>> analyzer = AnalyzerEngine() >>> analyzer.registry.add_recognizer(recognizer)
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize self to dictionary. |
from_dict |
Create EntityRecognizer from a dict input. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
load |
Load the HuggingFace NER pipeline. |
analyze |
Analyze text for NER entities using HuggingFace model. |
Source code in presidio_analyzer/predefined_recognizers/ner/huggingface_ner_recognizer.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize self to dictionary.
| RETURNS | DESCRIPTION |
|---|---|
Dict
|
a dictionary |
Source code in presidio_analyzer/entity_recognizer.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> EntityRecognizer
Create EntityRecognizer from a dict input.
| PARAMETER | DESCRIPTION |
|---|---|
entity_recognizer_dict
|
Dict containing keys and values for instantiation
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
249 250 251 252 253 254 255 256 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
load
load() -> None
Load the HuggingFace NER pipeline.
This method handles: 1. Hardware acceleration setup (CUDA validation and fallback) 2. Lazy-loading of the heavyweight ML pipeline.
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If model_name is not set |
Source code in presidio_analyzer/predefined_recognizers/ner/huggingface_ner_recognizer.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | |
analyze
analyze(
text: str, entities: List[str], nlp_artifacts: Optional[NlpArtifacts] = None
) -> List[RecognizerResult]
Analyze text for NER entities using HuggingFace model.
This method uses the CharacterBasedTextChunker to handle long texts and ignores nlp_artifacts (spaCy results) to bypass tokenizer alignment issues.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The text to analyze
TYPE:
|
entities
|
List of entity types to detect
TYPE:
|
nlp_artifacts
|
Ignored (spaCy artifacts not used)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List of RecognizerResult with detected entities |
Source code in presidio_analyzer/predefined_recognizers/ner/huggingface_ner_recognizer.py
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 | |
MedicalNERRecognizer
Bases: HuggingFaceNerRecognizer
Recognize medical/clinical entities using blaze999/Medical-NER.
Thin subclass of :class:HuggingFaceNerRecognizer that sets
medical-specific defaults. Uses HuggingFace transformers.pipeline
directly (no spaCy dependency).
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
load |
Load the HuggingFace NER pipeline. |
analyze |
Analyze text for NER entities using HuggingFace model. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize self to dictionary. |
from_dict |
Create EntityRecognizer from a dict input. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
Source code in presidio_analyzer/predefined_recognizers/ner/medical_ner_recognizer.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
load
load() -> None
Load the HuggingFace NER pipeline.
This method handles: 1. Hardware acceleration setup (CUDA validation and fallback) 2. Lazy-loading of the heavyweight ML pipeline.
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If model_name is not set |
Source code in presidio_analyzer/predefined_recognizers/ner/huggingface_ner_recognizer.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | |
analyze
analyze(
text: str, entities: List[str], nlp_artifacts: Optional[NlpArtifacts] = None
) -> List[RecognizerResult]
Analyze text for NER entities using HuggingFace model.
This method uses the CharacterBasedTextChunker to handle long texts and ignores nlp_artifacts (spaCy results) to bypass tokenizer alignment issues.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The text to analyze
TYPE:
|
entities
|
List of entity types to detect
TYPE:
|
nlp_artifacts
|
Ignored (spaCy artifacts not used)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List of RecognizerResult with detected entities |
Source code in presidio_analyzer/predefined_recognizers/ner/huggingface_ner_recognizer.py
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize self to dictionary.
| RETURNS | DESCRIPTION |
|---|---|
Dict
|
a dictionary |
Source code in presidio_analyzer/entity_recognizer.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> EntityRecognizer
Create EntityRecognizer from a dict input.
| PARAMETER | DESCRIPTION |
|---|---|
entity_recognizer_dict
|
Dict containing keys and values for instantiation
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
249 250 251 252 253 254 255 256 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
SpacyRecognizer
Bases: LocalRecognizer
Recognize PII entities using a spaCy NLP model.
Since the spaCy pipeline is ran by the AnalyzerEngine/SpacyNlpEngine,
this recognizer only extracts the entities from the NlpArtifacts
and returns them.
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize self to dictionary. |
from_dict |
Create EntityRecognizer from a dict input. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
build_explanation |
Create explanation for why this result was detected. |
Source code in presidio_analyzer/predefined_recognizers/nlp_engine_recognizers/spacy_recognizer.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize self to dictionary.
| RETURNS | DESCRIPTION |
|---|---|
Dict
|
a dictionary |
Source code in presidio_analyzer/entity_recognizer.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> EntityRecognizer
Create EntityRecognizer from a dict input.
| PARAMETER | DESCRIPTION |
|---|---|
entity_recognizer_dict
|
Dict containing keys and values for instantiation
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
249 250 251 252 253 254 255 256 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
build_explanation
build_explanation(
original_score: float, explanation: str
) -> AnalysisExplanation
Create explanation for why this result was detected.
| PARAMETER | DESCRIPTION |
|---|---|
original_score
|
Score given by this recognizer
TYPE:
|
explanation
|
Explanation string
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
|
Source code in presidio_analyzer/predefined_recognizers/nlp_engine_recognizers/spacy_recognizer.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
StanzaRecognizer
Bases: SpacyRecognizer
Recognize entities using the Stanza NLP package.
See https://stanfordnlp.github.io/stanza/. Uses the spaCy-Stanza package (https://github.com/explosion/spacy-stanza) to align Stanza's interface with spaCy's
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize self to dictionary. |
from_dict |
Create EntityRecognizer from a dict input. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
build_explanation |
Create explanation for why this result was detected. |
Source code in presidio_analyzer/predefined_recognizers/nlp_engine_recognizers/stanza_recognizer.py
8 9 10 11 12 13 14 15 16 17 18 19 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
209 210 211 212 213 214 215 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize self to dictionary.
| RETURNS | DESCRIPTION |
|---|---|
Dict
|
a dictionary |
Source code in presidio_analyzer/entity_recognizer.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> EntityRecognizer
Create EntityRecognizer from a dict input.
| PARAMETER | DESCRIPTION |
|---|---|
entity_recognizer_dict
|
Dict containing keys and values for instantiation
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
249 250 251 252 253 254 255 256 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
build_explanation
build_explanation(
original_score: float, explanation: str
) -> AnalysisExplanation
Create explanation for why this result was detected.
| PARAMETER | DESCRIPTION |
|---|---|
original_score
|
Score given by this recognizer
TYPE:
|
explanation
|
Explanation string
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AnalysisExplanation
|
|
Source code in presidio_analyzer/predefined_recognizers/nlp_engine_recognizers/spacy_recognizer.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
AzureHealthDeidRecognizer
Bases: RemoteRecognizer
Wrapper for PHI detection using Azure Health Data Services de-identification.
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize self to dictionary. |
from_dict |
Create EntityRecognizer from a dict input. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
get_supported_entities |
Return the list of entities supported by this recognizer. |
analyze |
Analyze text using Azure Health Data Services Deidentification (TAG operation). |
Source code in presidio_analyzer/predefined_recognizers/third_party/ahds_recognizer.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize self to dictionary.
| RETURNS | DESCRIPTION |
|---|---|
Dict
|
a dictionary |
Source code in presidio_analyzer/entity_recognizer.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> EntityRecognizer
Create EntityRecognizer from a dict input.
| PARAMETER | DESCRIPTION |
|---|---|
entity_recognizer_dict
|
Dict containing keys and values for instantiation
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
249 250 251 252 253 254 255 256 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities supported by this recognizer.
Returns List[str]: A list of supported entity names as strings.
Source code in presidio_analyzer/predefined_recognizers/third_party/ahds_recognizer.py
90 91 92 93 94 95 96 97 | |
analyze
analyze(
text: str, entities: List[str] = None, nlp_artifacts: NlpArtifacts = None
) -> List[RecognizerResult]
Analyze text using Azure Health Data Services Deidentification (TAG operation).
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to analyze
TYPE:
|
entities
|
List of entities to return (optional)
TYPE:
|
nlp_artifacts
|
Not used
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List of RecognizerResult for each PHI entity found |
Source code in presidio_analyzer/predefined_recognizers/third_party/ahds_recognizer.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |
AzureAILanguageRecognizer
Bases: RemoteRecognizer
Wrapper for PII detection using Azure AI Language.
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize self to dictionary. |
from_dict |
Create EntityRecognizer from a dict input. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
get_supported_entities |
Return the list of entities this recognizer can identify. |
analyze |
Analyze text using Azure AI Language. |
Source code in presidio_analyzer/predefined_recognizers/third_party/azure_ai_language.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize self to dictionary.
| RETURNS | DESCRIPTION |
|---|---|
Dict
|
a dictionary |
Source code in presidio_analyzer/entity_recognizer.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> EntityRecognizer
Create EntityRecognizer from a dict input.
| PARAMETER | DESCRIPTION |
|---|---|
entity_recognizer_dict
|
Dict containing keys and values for instantiation
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
249 250 251 252 253 254 255 256 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
get_supported_entities
get_supported_entities() -> List[str]
Return the list of entities this recognizer can identify.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
A list of the supported entities by this recognizer |
Source code in presidio_analyzer/predefined_recognizers/third_party/azure_ai_language.py
66 67 68 69 70 71 72 | |
analyze
analyze(
text: str, entities: List[str] = None, nlp_artifacts: NlpArtifacts = None
) -> List[RecognizerResult]
Analyze text using Azure AI Language.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Text to analyze
TYPE:
|
entities
|
List of entities to return
TYPE:
|
nlp_artifacts
|
Object of type NlpArtifacts, not used in this recognizer.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
A list of RecognizerResult, one per each entity found in the text. |
Source code in presidio_analyzer/predefined_recognizers/third_party/azure_ai_language.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
AzureOpenAILangExtractRecognizer
Bases: LangExtractRecognizer
Concrete implementation of LangExtract recognizer using Azure OpenAI backend.
Provides Azure OpenAI-specific functionality including: - Azure OpenAI endpoint and API key configuration - Deployment name management - API version control - Integration with custom Azure OpenAI provider via LangExtract registry
Source code in presidio_analyzer/predefined_recognizers/third_party/azure_openai_langextract_recognizer.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |
BasicLangExtractRecognizer
Bases: LangExtractRecognizer
Basic LangExtract recognizer using configurable backend.
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyze text for PII/PHI using LLM. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return list of supported PII entity types. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize self to dictionary. |
from_dict |
Create EntityRecognizer from a dict input. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
Source code in presidio_analyzer/predefined_recognizers/third_party/basic_langextract_recognizer.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: Optional[List[str]] = None,
nlp_artifacts: Optional[NlpArtifacts] = None,
) -> List[RecognizerResult]
Analyze text for PII/PHI using LLM.
Source code in presidio_analyzer/lm_recognizer.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return list of supported PII entity types.
Source code in presidio_analyzer/lm_recognizer.py
159 160 161 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize self to dictionary.
| RETURNS | DESCRIPTION |
|---|---|
Dict
|
a dictionary |
Source code in presidio_analyzer/entity_recognizer.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> EntityRecognizer
Create EntityRecognizer from a dict input.
| PARAMETER | DESCRIPTION |
|---|---|
entity_recognizer_dict
|
Dict containing keys and values for instantiation
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
249 250 251 252 253 254 255 256 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
LangExtractRecognizer
Bases: LMRecognizer, ABC
Base class for LangExtract-based PII recognizers.
Subclasses implement _call_langextract() for specific LLM providers.
| METHOD | DESCRIPTION |
|---|---|
country_code |
Return the country tag for this recognizer, or |
is_country_specific |
Return |
analyze |
Analyze text for PII/PHI using LLM. |
enhance_using_context |
Enhance confidence score using context of the entity. |
get_supported_entities |
Return list of supported PII entity types. |
get_supported_language |
Return the language this recognizer can support. |
get_version |
Return the version of this recognizer. |
to_dict |
Serialize self to dictionary. |
from_dict |
Create EntityRecognizer from a dict input. |
remove_duplicates |
Remove duplicate results. |
sanitize_value |
Cleanse the input string of the replacement pairs specified as argument. |
Source code in presidio_analyzer/predefined_recognizers/third_party/langextract_recognizer.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
country_code
country_code() -> Optional[str]
Return the country tag for this recognizer, or None if generic.
Resolved at construction time from the class-level
:attr:COUNTRY_CODE attribute and the optional country_code
constructor kwarg; the two are reconciled by
:meth:_resolve_country_code so this method always returns a
single, lower-cased value (or None). Note this is an instance
method — to introspect a class without instantiating, read
cls.COUNTRY_CODE directly.
Source code in presidio_analyzer/entity_recognizer.py
128 129 130 131 132 133 134 135 136 137 138 139 | |
is_country_specific
is_country_specific() -> bool
Return True iff this recognizer is tagged with a country.
Equivalent to self.country_code() is not None. Provided as a
named predicate because filter / registry / discoverability code
reads more naturally with an explicit "is this country-specific?"
question than with a None-check.
Source code in presidio_analyzer/entity_recognizer.py
141 142 143 144 145 146 147 148 149 | |
id
property
id
Return a unique identifier of this recognizer.
analyze
analyze(
text: str,
entities: Optional[List[str]] = None,
nlp_artifacts: Optional[NlpArtifacts] = None,
) -> List[RecognizerResult]
Analyze text for PII/PHI using LLM.
Source code in presidio_analyzer/lm_recognizer.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
enhance_using_context
enhance_using_context(
text: str,
raw_recognizer_results: List[RecognizerResult],
other_raw_recognizer_results: List[RecognizerResult],
nlp_artifacts: NlpArtifacts,
context: Optional[List[str]] = None,
) -> List[RecognizerResult]
Enhance confidence score using context of the entity.
Override this method in derived class in case a custom logic is needed, otherwise return value will be equal to raw_results.
in case a result score is boosted, derived class need to update result.recognition_metadata[RecognizerResult.IS_SCORE_ENHANCED_BY_CONTEXT_KEY]
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The actual text that was analyzed
TYPE:
|
raw_recognizer_results
|
This recognizer's results, to be updated based on recognizer specific context.
TYPE:
|
other_raw_recognizer_results
|
Other recognizer results matched in the given text to allow related entity context enhancement
TYPE:
|
nlp_artifacts
|
The nlp artifacts contains elements such as lemmatized tokens for better accuracy of the context enhancement process
TYPE:
|
context
|
list of context words
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_supported_entities
get_supported_entities() -> List[str]
Return list of supported PII entity types.
Source code in presidio_analyzer/lm_recognizer.py
159 160 161 | |
get_supported_language
get_supported_language() -> str
Return the language this recognizer can support.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A list of the supported language by this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
217 218 219 220 221 222 223 | |
get_version
get_version() -> str
Return the version of this recognizer.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current version of this recognizer |
Source code in presidio_analyzer/entity_recognizer.py
225 226 227 228 229 230 231 | |
to_dict
to_dict() -> Dict
Serialize self to dictionary.
| RETURNS | DESCRIPTION |
|---|---|
Dict
|
a dictionary |
Source code in presidio_analyzer/entity_recognizer.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
from_dict
classmethod
from_dict(entity_recognizer_dict: Dict) -> EntityRecognizer
Create EntityRecognizer from a dict input.
| PARAMETER | DESCRIPTION |
|---|---|
entity_recognizer_dict
|
Dict containing keys and values for instantiation
TYPE:
|
Source code in presidio_analyzer/entity_recognizer.py
249 250 251 252 253 254 255 256 | |
remove_duplicates
staticmethod
remove_duplicates(results: List[RecognizerResult]) -> List[RecognizerResult]
Remove duplicate results.
Remove duplicates in case the two results have identical start and ends and types.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
List[RecognizerResult]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[RecognizerResult]
|
List[RecognizerResult] |
Source code in presidio_analyzer/entity_recognizer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sanitize_value
staticmethod
sanitize_value(text: str, replacement_pairs: List[Tuple[str, str]]) -> str
Cleanse the input string of the replacement pairs specified as argument.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
input string
TYPE:
|
replacement_pairs
|
pairs of what has to be replaced with which value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
cleansed string |
Source code in presidio_analyzer/entity_recognizer.py
292 293 294 295 296 297 298 299 300 301 302 303 | |
Misc
presidio_analyzer.analyzer_request.AnalyzerRequest
Analyzer request data.
| PARAMETER | DESCRIPTION |
|---|---|
req_data
|
A request dictionary with the following fields: text: the text to analyze language: the language of the text entities: List of PII entities that should be looked for in the text. If entities=None then all entities are looked for. correlation_id: cross call ID for this request score_threshold: A minimum value for which to return an identified entity log_decision_process: Should the decision points within the analysis be logged return_decision_process: Should the decision points within the analysis returned as part of the response
TYPE:
|
Source code in presidio_analyzer/analyzer_request.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |