Logger for Smartnoise Synth Transformers
Serialize and deserialize Smartnoise Synth constraints to and from JSON.
Constraints as specified in the Smartnoise Synth Transforms documentation: https://docs.smartnoise.org/synth/transforms/index.html with tt = TableTransformer(constraint)
.
Install with pip:
pip install smartnoise-synth-logger
from snsynth.transform import (
AnonymizationTransformer,
BinTransformer,
ChainTransformer,
ClampTransformer,
DropTransformer,
LabelTransformer,
LogTransformer,
MinMaxTransformer,
OneHotEncoder,
StandardScaler,
)
from snsynth.transform.datetime import DateTimeTransformer
constraints = {
"id": AnonymizationTransformer("uuid4"),
"email": "email", # also possible
"income": ChainTransformer(
[
LogTransformer(),
BinTransformer(bins=20, lower=0, upper=50),
]
),
"height": ChainTransformer(
[
StandardScaler(lower=0, upper=1),
BinTransformer(bins=20, lower=0, upper=1),
]
),
"weight": ChainTransformer(
[ClampTransformer(lower=10, upper=200), BinTransformer(bins=20)]
),
"age": MinMaxTransformer(lower=0, upper=100),
"sex": ChainTransformer(
[LabelTransformer(nullable=True), OneHotEncoder()]
),
"rank": LabelTransformer(nullable=False),
"job": DropTransformer(),
"date": DateTimeTransformer(epoch="1993-06-04"),
}
from smartnoise_synth_logger import serialise_constraints
serialised_constraints = serialise_constraints(constraints)
from smartnoise_synth_logger import deserialise_constraints
deserialised_constraints = deserialise_constraints(serialised_constraints)
tt = TableTransformer(deserialised_constraints)
It can now be expected that the deserialised_constraints
has the same constraints as constraints
.
NOTE: lambda function in AnonymizationTransformer are not supported.