-
Notifications
You must be signed in to change notification settings - Fork 0
/
anonymize_kg.py
63 lines (49 loc) · 1.82 KB
/
anonymize_kg.py
1
2
3
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
import sys
import argparse
import logging
import anonygraph.utils.runner as rutils
import anonygraph.utils.data as dutils
import anonygraph.utils.path as putils
import anonygraph.algorithms.generalization as gen
from anonygraph.algorithms import Clusters
logger = logging.getLogger(__file__)
def add_arguments(parser):
rutils.add_data_argument(parser)
rutils.add_k_generator_argument(parser)
rutils.add_info_loss_argument(parser)
rutils.add_clustering_argument(parser)
rutils.add_cluster_constraint_enforcer_argument(parser)
rutils.add_log_argument(parser)
def main(args):
logger.info(args)
data_name = args["data"]
sample = args["sample"]
info_loss_name = args["info_loss"]
k_generator_name = args["gen"]
calgo_name = args["calgo"]
enforcer_name = args["enforcer"]
# max_dist = args["max_dist"]
handler_name = args["handler"]
graph = dutils.load_raw_graph(data_name, sample)
logger.debug(graph)
clusters_path = putils.get_anony_clusters_path(data_name, sample, k_generator_name, info_loss_name, handler_name, calgo_name, enforcer_name, args)
clusters = Clusters.from_file(clusters_path)
# load algo to generate graphs
gen_fn = gen.GraphGeneralization()
anony_graph = gen_fn.run(graph, clusters)
logger.debug("final anonymized subgraph: {}".format(anony_graph))
# save anonymized graph
anony_graph_path = putils.get_anony_graph_path(
data_name, sample, k_generator_name, info_loss_name, handler_name, calgo_name, enforcer_name, args
)
anony_graph.to_edge_files(anony_graph_path)
logger.info(
"saved anonymized graph to {}".format(
anony_graph_path
)
)
sys.exit(0)
if __name__ == "__main__":
args = rutils.setup_arguments(add_arguments)
rutils.setup_console_logging(args)
main(args)