Strategies Module
anonipy.anonymize.strategies
Module containing the strategies.
The strategies module provides a set of strategies used to anonymize the identified vulnerable data.
Classes:
| Name | Description |
|---|---|
RedactionStrategy | The class representing the redaction strategy. |
MaskingStrategy | The class representing the masking strategy. |
PseudonymizationStrategy | The class representing the pseudonymization strategy. |
anonipy.anonymize.strategies.RedactionStrategy
Bases: StrategyInterface
The class representing the redaction strategy.
Examples:
>>> from anonipy.anonymize.strategies import RedactionStrategy
>>> strategy = RedactionStrategy()
>>> strategy.anonymize(text, entities)
Attributes:
| Name | Type | Description |
|---|---|---|
substitute_label | str | The label to substitute in the anonymized text. |
Methods:
| Name | Description |
|---|---|
anonymize | Anonymize the text based on the entities. |
Source code in anonipy/anonymize/strategies/redaction.py
__init__(substitute_label='[REDACTED]', *args, **kwargs)
Initializes the redaction strategy.
Examples:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
substitute_label | str | The label to substitute in the anonymized text. | '[REDACTED]' |
Source code in anonipy/anonymize/strategies/redaction.py
anonymize(text, entities, *args, **kwargs)
Anonymize the text using the redaction strategy.
Examples:
>>> from anonipy.anonymize.strategies import RedactionStrategy
>>> strategy = RedactionStrategy()
>>> strategy.anonymize(text, entities)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text | str | The text to anonymize. | required |
entities | List[Entity] | The list of entities to anonymize. | required |
Returns:
| Type | Description |
|---|---|
str | The anonymized text. |
List[Replacement] | The list of applied replacements. |
Source code in anonipy/anonymize/strategies/redaction.py
anonipy.anonymize.strategies.MaskingStrategy
Bases: StrategyInterface
The class representing the masking strategy.
Examples:
>>> from anonipy.anonymize.strategies import MaskingStrategy
>>> strategy = MaskingStrategy()
>>> strategy.anonymize(text, entities)
Attributes:
| Name | Type | Description |
|---|---|---|
substitute_label | str | The label to substitute in the anonymized text. |
Methods:
| Name | Description |
|---|---|
anonymize | Anonymize the text based on the entities. |
Source code in anonipy/anonymize/strategies/masking.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 | |
__init__(substitute_label='*', *args, **kwargs)
Initializes the masking strategy.
Examples:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
substitute_label | str | The label to substitute in the anonymized text. | '*' |
Source code in anonipy/anonymize/strategies/masking.py
anonymize(text, entities, *args, **kwargs)
Anonymize the text using the masking strategy.
Examples:
>>> from anonipy.anonymize.strategies import MaskingStrategy
>>> strategy = MaskingStrategy()
>>> strategy.anonymize(text, entities)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text | str | The text to anonymize. | required |
entities | List[Entity] | The list of entities to anonymize. | required |
Returns:
| Type | Description |
|---|---|
str | The anonymized text. |
List[Replacement] | The list of applied replacements. |
Source code in anonipy/anonymize/strategies/masking.py
anonipy.anonymize.strategies.PseudonymizationStrategy
Bases: StrategyInterface
The class representing the pseudonymization strategy.
Examples:
>>> from anonipy.anonymize.strategies import PseudonymizationStrategy
>>> strategy = PseudonymizationStrategy(mapping)
>>> strategy.anonymize(text, entities)
Attributes:
| Name | Type | Description |
|---|---|---|
mapping | The mapping of entities to pseudonyms. |
Methods:
| Name | Description |
|---|---|
anonymize | Anonymize the text based on the entities. |
Source code in anonipy/anonymize/strategies/pseudonymization.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 | |
__init__(mapping, *args, **kwargs)
Initializes the pseudonymization strategy.
Examples:
>>> from anonipy.anonymize.strategies import PseudonymizationStrategy
>>> strategy = PseudonymizationStrategy(mapping)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping | Callable | The mapping function on how to handle each entity type. | required |
Source code in anonipy/anonymize/strategies/pseudonymization.py
anonymize(text, entities, *args, **kwargs)
Anonymize the text using the pseudonymization strategy.
Examples:
>>> from anonipy.anonymize.strategies import PseudonymizationStrategy
>>> strategy = PseudonymizationStrategy(mapping)
>>> strategy.anonymize(text, entities)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text | str | The text to anonymize. | required |
entities | List[Entity] | The list of entities to anonymize. | required |
Returns:
| Type | Description |
|---|---|
str | The anonymized text. |
List[Replacement] | The list of applied replacements. |
Source code in anonipy/anonymize/strategies/pseudonymization.py
anonipy.anonymize.strategies.StrategyInterface
The class representing the strategy interface.
All strategies should inherit from this class.
Methods:
| Name | Description |
|---|---|
anonymize | Anonymize the text based on the entities. |