A class to represent a specific XML parser for BenchBase configuration files Attributes ---------- table : ET.Element XML element with the - tag
| 15 | |
| 16 | |
| 17 | class XMLParser: |
| 18 | """A class to represent a specific XML parser for BenchBase configuration files |
| 19 | |
| 20 | Attributes |
| 21 | ---------- |
| 22 | table : ET.Element |
| 23 | XML element with the <table> - tag |
| 24 | """ |
| 25 | |
| 26 | def __init__(self, table: ET.Element): |
| 27 | self.table = table |
| 28 | |
| 29 | def get_config(self): |
| 30 | """Function that extracts the different types of configuration classes from the XML tree |
| 31 | |
| 32 | Returns: |
| 33 | (DPConfig,ContinuousConfig,SensitiveConfig): The three configuration classes |
| 34 | """ |
| 35 | |
| 36 | anon_config = None |
| 37 | cont_config = None |
| 38 | sens_config = None |
| 39 | continuous_entries = [] |
| 40 | sensitive_entries = [] |
| 41 | |
| 42 | table_name = self.table.get("name") |
| 43 | |
| 44 | # Exit the program if not enough basic information (name of a table) is available |
| 45 | if table_name is None: |
| 46 | sys.exit( |
| 47 | "There was no name provided for the table that should be anonymized. Program is exiting now!" |
| 48 | ) |
| 49 | |
| 50 | print(f"Parsing config for table: {table_name}") |
| 51 | |
| 52 | dp_info = self.table.find("differential_privacy") |
| 53 | |
| 54 | if dp_info is not None: |
| 55 | |
| 56 | cat = self.__get_column_type("ignore", dp_info) |
| 57 | ordi = self.__get_column_type("ordinal", dp_info) |
| 58 | ignore = self.__get_column_type("continuous", dp_info) |
| 59 | |
| 60 | eps = dp_info.get("epsilon", "1.0") |
| 61 | pre_eps = dp_info.get("pre_epsilon", "0.5") |
| 62 | alg = dp_info.get("algorithm", "mst") |
| 63 | |
| 64 | # Specific handling for continuous columns to incorporate a separate config |
| 65 | cont = [] |
| 66 | if dp_info.find("continuous") is not None: |
| 67 | for column in dp_info.find("continuous").findall("column"): |
| 68 | cont.append(column.get("name")) |
| 69 | |
| 70 | if column.get("bins") or column.get("lower") or column.get("upper"): |
| 71 | continuous_entries.append( |
| 72 | ContinuousEntry( |
| 73 | column.get("name"), |
| 74 | column.get("bins", "10"), |
no outgoing calls