build a generalisation hierarchy from a table of edges
Source:R/generalize.R
generalization_hierarchy.RdA hierarchy says which coarse value each fine value rolls up into: 千代田区 into 東京都 into 関東, `[35,40)` into `[30,40)`. It is a *declaration*, not something inferred from the data (Issue #20 puts inference out of scope): guessing the anonymiser's intent would move the reported risk in an uncontrolled direction.
Value
an object of class "reid_hierarchy": a list with `edges` (the validated data frame, plus a derived `level` column) and `descendants` (for each attribute, the transitive closure below every node).
Details
Only the edges have to be listed. A raw value that is not itself a node – an exact age of 37, say – is matched into the finest node that contains it by [node_matches()], so a numeric hierarchy only needs its bin definitions and not one row per possible value.
Examples
h <- generalization_hierarchy(data.frame(
attribute = "AREA",
value = c("chiyoda", "shinjuku", "yokohama", "tokyo", "kanagawa"),
parent = c("tokyo", "tokyo", "kanagawa", "kanto", "kanto"),
stringsAsFactors = FALSE
))
h
#> generalization hierarchy: 5 edge(s) over 1 attribute(s)
#> AREA: 5 edge(s), 3 level(s), root(s): kanto