fable-model 0.1.7__tar.gz → 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {fable_model-0.1.7 → fable_model-0.2.0}/PKG-INFO +18 -6
- {fable_model-0.1.7 → fable_model-0.2.0}/README.md +16 -3
- {fable_model-0.1.7 → fable_model-0.2.0}/fable_model/__init__.py +2 -0
- {fable_model-0.1.7 → fable_model-0.2.0}/fable_model/mask.py +13 -14
- fable_model-0.2.0/fable_model/match.py +91 -0
- {fable_model-0.1.7 → fable_model-0.2.0}/fable_model/transform.py +3 -4
- {fable_model-0.1.7 → fable_model-0.2.0}/pyproject.toml +2 -3
- fable_model-0.1.7/fable_model/match.py +0 -50
- {fable_model-0.1.7 → fable_model-0.2.0}/LICENSE +0 -0
- {fable_model-0.1.7 → fable_model-0.2.0}/fable_model/common.py +0 -0
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fable-model
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Data models utilized in the FABLE ecosystem's HTTP-based PPRL service.
|
|
5
5
|
License-Expression: MIT
|
|
6
6
|
License-File: LICENSE
|
|
7
7
|
Keywords: record linkage,privacy,bloom filter
|
|
8
8
|
Author: Maximilian Jugl
|
|
9
|
-
Requires-Python: >=3.
|
|
9
|
+
Requires-Python: >=3.11
|
|
10
10
|
Classifier: Development Status :: 4 - Beta
|
|
11
11
|
Classifier: Intended Audience :: Developers
|
|
12
12
|
Classifier: Intended Audience :: Science/Research
|
|
13
13
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
14
14
|
Classifier: Programming Language :: Python :: 3
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
16
15
|
Classifier: Programming Language :: Python :: 3.11
|
|
17
16
|
Classifier: Programming Language :: Python :: 3.12
|
|
18
17
|
Classifier: Programming Language :: Python :: 3.13
|
|
@@ -36,6 +35,12 @@ Validation, serialization and deserialization are done using [Pydantic](https://
|
|
|
36
35
|
It is rare to use this package directly.
|
|
37
36
|
Rather, it powers the functionalities of other packages.
|
|
38
37
|
|
|
38
|
+
## Installation
|
|
39
|
+
|
|
40
|
+
```commandline
|
|
41
|
+
pip install fable-model
|
|
42
|
+
```
|
|
43
|
+
|
|
39
44
|
## Data models
|
|
40
45
|
|
|
41
46
|
Models for entity pre-processing, masking and bit vector matching are exposed through this package.
|
|
@@ -296,12 +301,19 @@ _ = EntityMaskRequest(
|
|
|
296
301
|
### Bit vector matching
|
|
297
302
|
|
|
298
303
|
```python
|
|
299
|
-
from fable_model import
|
|
304
|
+
from fable_model import (
|
|
305
|
+
VectorMatchRequest,
|
|
306
|
+
MatchConfig,
|
|
307
|
+
SimilarityMeasure,
|
|
308
|
+
BitVectorEntity,
|
|
309
|
+
SimilarityAggregator,
|
|
310
|
+
)
|
|
300
311
|
|
|
301
312
|
_ = VectorMatchRequest(
|
|
302
313
|
config=MatchConfig(
|
|
303
|
-
|
|
304
|
-
|
|
314
|
+
measures=[SimilarityMeasure.jaccard, SimilarityMeasure.cosine],
|
|
315
|
+
thresholds=0.8,
|
|
316
|
+
aggregator=SimilarityAggregator.avg,
|
|
305
317
|
),
|
|
306
318
|
domain=[
|
|
307
319
|
BitVectorEntity(
|
|
@@ -13,6 +13,12 @@ Validation, serialization and deserialization are done using [Pydantic](https://
|
|
|
13
13
|
It is rare to use this package directly.
|
|
14
14
|
Rather, it powers the functionalities of other packages.
|
|
15
15
|
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```commandline
|
|
19
|
+
pip install fable-model
|
|
20
|
+
```
|
|
21
|
+
|
|
16
22
|
## Data models
|
|
17
23
|
|
|
18
24
|
Models for entity pre-processing, masking and bit vector matching are exposed through this package.
|
|
@@ -273,12 +279,19 @@ _ = EntityMaskRequest(
|
|
|
273
279
|
### Bit vector matching
|
|
274
280
|
|
|
275
281
|
```python
|
|
276
|
-
from fable_model import
|
|
282
|
+
from fable_model import (
|
|
283
|
+
VectorMatchRequest,
|
|
284
|
+
MatchConfig,
|
|
285
|
+
SimilarityMeasure,
|
|
286
|
+
BitVectorEntity,
|
|
287
|
+
SimilarityAggregator,
|
|
288
|
+
)
|
|
277
289
|
|
|
278
290
|
_ = VectorMatchRequest(
|
|
279
291
|
config=MatchConfig(
|
|
280
|
-
|
|
281
|
-
|
|
292
|
+
measures=[SimilarityMeasure.jaccard, SimilarityMeasure.cosine],
|
|
293
|
+
thresholds=0.8,
|
|
294
|
+
aggregator=SimilarityAggregator.avg,
|
|
282
295
|
),
|
|
283
296
|
domain=[
|
|
284
297
|
BitVectorEntity(
|
|
@@ -38,6 +38,7 @@ from .match import (
|
|
|
38
38
|
Match,
|
|
39
39
|
BaseMatchRequest,
|
|
40
40
|
MatchMethod,
|
|
41
|
+
SimilarityAggregator,
|
|
41
42
|
)
|
|
42
43
|
from .transform import (
|
|
43
44
|
EmptyValueHandling,
|
|
@@ -117,4 +118,5 @@ __all__ = [
|
|
|
117
118
|
"BaseTransformRequest",
|
|
118
119
|
"BaseMatchRequest",
|
|
119
120
|
"MatchMethod",
|
|
121
|
+
"SimilarityAggregator",
|
|
120
122
|
]
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
from enum import Enum
|
|
2
|
-
from typing import Literal, Union, Annotated
|
|
2
|
+
from typing import Literal, Union, Annotated, Self
|
|
3
3
|
|
|
4
|
-
from pydantic import Field,
|
|
5
|
-
from typing_extensions import Self
|
|
4
|
+
from pydantic import Field, model_validator
|
|
6
5
|
|
|
7
6
|
from fable_model.common import ParentModel, BitVectorEntity, AttributeValueEntity
|
|
8
7
|
|
|
@@ -58,19 +57,19 @@ class FilterType(str, Enum):
|
|
|
58
57
|
|
|
59
58
|
class CLKFilter(ParentModel):
|
|
60
59
|
type: Literal[FilterType.clk] = FilterType.clk
|
|
61
|
-
filter_size:
|
|
62
|
-
hash_values:
|
|
60
|
+
filter_size: Annotated[int, Field(gt=0)]
|
|
61
|
+
hash_values: Annotated[int, Field(gt=0)]
|
|
63
62
|
|
|
64
63
|
|
|
65
64
|
class RBFFilter(ParentModel):
|
|
66
65
|
type: Literal[FilterType.rbf] = FilterType.rbf
|
|
67
|
-
hash_values:
|
|
66
|
+
hash_values: Annotated[int, Field(gt=0)]
|
|
68
67
|
seed: int
|
|
69
68
|
|
|
70
69
|
|
|
71
70
|
class CLKRBFFilter(ParentModel):
|
|
72
71
|
type: Literal[FilterType.clkrbf] = FilterType.clkrbf
|
|
73
|
-
hash_values:
|
|
72
|
+
hash_values: Annotated[int, Field(gt=0)]
|
|
74
73
|
|
|
75
74
|
|
|
76
75
|
AnyFilter = Union[CLKFilter, RBFFilter, CLKRBFFilter]
|
|
@@ -100,7 +99,7 @@ class PermuteHardener(ParentModel):
|
|
|
100
99
|
|
|
101
100
|
class RandomizedResponseHardener(ParentModel):
|
|
102
101
|
name: Literal[Hardener.randomized_response] = Hardener.randomized_response
|
|
103
|
-
probability:
|
|
102
|
+
probability: Annotated[float, Field(ge=0, le=1)]
|
|
104
103
|
seed: int
|
|
105
104
|
|
|
106
105
|
|
|
@@ -110,9 +109,9 @@ class Rule90Hardener(ParentModel):
|
|
|
110
109
|
|
|
111
110
|
class RehashHardener(ParentModel):
|
|
112
111
|
name: Literal[Hardener.rehash] = Hardener.rehash
|
|
113
|
-
window_size:
|
|
114
|
-
window_step:
|
|
115
|
-
samples:
|
|
112
|
+
window_size: Annotated[int, Field(gt=0, le=32)]
|
|
113
|
+
window_step: Annotated[int, Field(gt=0)]
|
|
114
|
+
samples: Annotated[int, Field(gt=0)]
|
|
116
115
|
|
|
117
116
|
|
|
118
117
|
AnyHardener = Union[
|
|
@@ -126,7 +125,7 @@ AnyHardener = Union[
|
|
|
126
125
|
|
|
127
126
|
|
|
128
127
|
class MaskConfig(ParentModel):
|
|
129
|
-
token_size:
|
|
128
|
+
token_size: Annotated[int, Field(gt=1)]
|
|
130
129
|
hash: HashConfig
|
|
131
130
|
prepend_attribute_name: Annotated[bool, Field(default=True)]
|
|
132
131
|
filter: Annotated[AnyFilter, Field(discriminator="type")]
|
|
@@ -157,8 +156,8 @@ class StaticAttributeConfig(ParentModel):
|
|
|
157
156
|
class WeightedAttributeConfig(ParentModel):
|
|
158
157
|
attribute_name: str
|
|
159
158
|
salt: AttributeSalt | None = Field(default=None)
|
|
160
|
-
weight:
|
|
161
|
-
average_token_count:
|
|
159
|
+
weight: Annotated[float, Field(gt=0)]
|
|
160
|
+
average_token_count: Annotated[float, Field(gt=0)]
|
|
162
161
|
|
|
163
162
|
|
|
164
163
|
class BaseMaskRequest(ParentModel):
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
from typing import Annotated, Any, Self
|
|
3
|
+
|
|
4
|
+
from pydantic import Field, model_validator, field_validator
|
|
5
|
+
|
|
6
|
+
from fable_model.common import ParentModel, BitVectorEntity
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class MatchMethod(str, Enum):
|
|
10
|
+
crosswise = "crosswise"
|
|
11
|
+
pairwise = "pairwise"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class SimilarityMeasure(str, Enum):
|
|
15
|
+
dice = "dice"
|
|
16
|
+
cosine = "cosine"
|
|
17
|
+
jaccard = "jaccard"
|
|
18
|
+
russell_rao = "russell_rao"
|
|
19
|
+
sokal_sneath = "sokal_sneath"
|
|
20
|
+
sokal_michener = "sokal_michener"
|
|
21
|
+
roger_tanimoto = "roger_tanimoto"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class SimilarityAggregator(str, Enum):
|
|
25
|
+
none = "none"
|
|
26
|
+
avg = "avg"
|
|
27
|
+
max = "max"
|
|
28
|
+
min = "min"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class MatchConfig(ParentModel):
|
|
32
|
+
measures: Annotated[list[SimilarityMeasure], Field(min_length=1)]
|
|
33
|
+
thresholds: Annotated[list[Annotated[float, Field(ge=0, le=1)]], Field(min_length=1)]
|
|
34
|
+
aggregator: SimilarityAggregator = SimilarityAggregator.none
|
|
35
|
+
aggregator_args: Annotated[dict[str, Any], Field(default_factory=dict)]
|
|
36
|
+
method: MatchMethod = MatchMethod.crosswise
|
|
37
|
+
|
|
38
|
+
@field_validator("measures", mode="before")
|
|
39
|
+
@classmethod
|
|
40
|
+
def cast_measures(cls, v):
|
|
41
|
+
if isinstance(v, str):
|
|
42
|
+
return [v]
|
|
43
|
+
return v
|
|
44
|
+
|
|
45
|
+
@field_validator("thresholds", mode="before")
|
|
46
|
+
@classmethod
|
|
47
|
+
def cast_thresholds(cls, v):
|
|
48
|
+
if isinstance(v, (float, int)):
|
|
49
|
+
return [v]
|
|
50
|
+
return v
|
|
51
|
+
|
|
52
|
+
@model_validator(mode="after")
|
|
53
|
+
def validate_measures_and_thresholds(self) -> Self:
|
|
54
|
+
if self.aggregator == SimilarityAggregator.none:
|
|
55
|
+
if len(self.measures) != len(self.thresholds):
|
|
56
|
+
raise ValueError(
|
|
57
|
+
"Without an aggregator, there must be as many similarity measures as there are thresholds."
|
|
58
|
+
)
|
|
59
|
+
else:
|
|
60
|
+
if len(self.thresholds) != 1:
|
|
61
|
+
raise ValueError("With an aggregator, there need to be exactly one threshold.")
|
|
62
|
+
|
|
63
|
+
return self
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class BaseMatchRequest(ParentModel):
|
|
67
|
+
config: MatchConfig
|
|
68
|
+
|
|
69
|
+
def with_vectors(self, domain_lst: list[BitVectorEntity], range_lst: list[BitVectorEntity]) -> "VectorMatchRequest":
|
|
70
|
+
return VectorMatchRequest(
|
|
71
|
+
config=self.config,
|
|
72
|
+
domain=domain_lst,
|
|
73
|
+
range=range_lst,
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class VectorMatchRequest(BaseMatchRequest):
|
|
78
|
+
domain: Annotated[list[BitVectorEntity], Field(min_length=1)]
|
|
79
|
+
range: Annotated[list[BitVectorEntity], Field(min_length=1)]
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
class Match(ParentModel):
|
|
83
|
+
domain: BitVectorEntity
|
|
84
|
+
range: BitVectorEntity
|
|
85
|
+
similarities: Annotated[list[Annotated[float, Field(ge=0, le=1)]], Field(min_length=1)]
|
|
86
|
+
aggregated_similarity: Annotated[float, Field(ge=0, le=1)] | None
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
class VectorMatchResponse(ParentModel):
|
|
90
|
+
config: MatchConfig
|
|
91
|
+
matches: list[Match]
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
from enum import Enum
|
|
2
|
-
from typing import Literal, Union, Annotated
|
|
2
|
+
from typing import Literal, Union, Annotated, Self
|
|
3
3
|
|
|
4
|
-
from pydantic import Field,
|
|
5
|
-
from typing_extensions import Self
|
|
4
|
+
from pydantic import Field, model_validator
|
|
6
5
|
|
|
7
6
|
from fable_model.common import ParentModel, AttributeValueEntity
|
|
8
7
|
|
|
@@ -50,7 +49,7 @@ class MappingTransformer(ParentModel):
|
|
|
50
49
|
|
|
51
50
|
class NumberTransformer(ParentModel):
|
|
52
51
|
name: Literal[Transformer.number] = Transformer.number
|
|
53
|
-
decimal_places:
|
|
52
|
+
decimal_places: Annotated[int, Field(ge=0)]
|
|
54
53
|
|
|
55
54
|
|
|
56
55
|
class PhoneticCodeAlgorithm(str, Enum):
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "fable-model"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.2.0"
|
|
4
4
|
description = "Data models utilized in the FABLE ecosystem's HTTP-based PPRL service."
|
|
5
5
|
authors = [
|
|
6
6
|
{name = "Maximilian Jugl"},
|
|
7
7
|
{name = "Paul Brassel", email = "paul.brassel@medizin.uni-leipzig.de"}
|
|
8
8
|
]
|
|
9
9
|
readme = "README.md"
|
|
10
|
-
requires-python = ">=3.
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
11
|
dependencies = [
|
|
12
12
|
"pydantic (>=2.7.0,<3.0.0)"
|
|
13
13
|
]
|
|
@@ -18,7 +18,6 @@ classifiers = [
|
|
|
18
18
|
"Intended Audience :: Science/Research",
|
|
19
19
|
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
20
20
|
"Programming Language :: Python :: 3",
|
|
21
|
-
"Programming Language :: Python :: 3.10",
|
|
22
21
|
"Programming Language :: Python :: 3.11",
|
|
23
22
|
"Programming Language :: Python :: 3.12",
|
|
24
23
|
"Programming Language :: Python :: 3.13",
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
from enum import Enum
|
|
2
|
-
from typing import Annotated
|
|
3
|
-
|
|
4
|
-
from pydantic import confloat, Field
|
|
5
|
-
|
|
6
|
-
from fable_model.common import ParentModel, BitVectorEntity
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class MatchMethod(str, Enum):
|
|
10
|
-
crosswise = "crosswise"
|
|
11
|
-
pairwise = "pairwise"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
class SimilarityMeasure(str, Enum):
|
|
15
|
-
dice = "dice"
|
|
16
|
-
cosine = "cosine"
|
|
17
|
-
jaccard = "jaccard"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
class MatchConfig(ParentModel):
|
|
21
|
-
measure: SimilarityMeasure
|
|
22
|
-
threshold: confloat(ge=0, le=1)
|
|
23
|
-
method: MatchMethod = MatchMethod.crosswise
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
class BaseMatchRequest(ParentModel):
|
|
27
|
-
config: MatchConfig
|
|
28
|
-
|
|
29
|
-
def with_vectors(self, domain_lst: list[BitVectorEntity], range_lst: list[BitVectorEntity]) -> "VectorMatchRequest":
|
|
30
|
-
return VectorMatchRequest(
|
|
31
|
-
config=self.config,
|
|
32
|
-
domain=domain_lst,
|
|
33
|
-
range=range_lst,
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
class VectorMatchRequest(BaseMatchRequest):
|
|
38
|
-
domain: Annotated[list[BitVectorEntity], Field(min_length=1)]
|
|
39
|
-
range: Annotated[list[BitVectorEntity], Field(min_length=1)]
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
class Match(ParentModel):
|
|
43
|
-
domain: BitVectorEntity
|
|
44
|
-
range: BitVectorEntity
|
|
45
|
-
similarity: float
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
class VectorMatchResponse(ParentModel):
|
|
49
|
-
config: MatchConfig
|
|
50
|
-
matches: list[Match]
|
|
File without changes
|
|
File without changes
|