From 024051f01af5185812451aae99aad23e6257f241 Mon Sep 17 00:00:00 2001 From: idhamari Date: Wed, 4 Jan 2023 12:08:49 +0100 Subject: [PATCH] load store .ahs files in the api --- .../arx/aggregates/HierarchyBuilder.java | 59 ++++++++++++++++++ .../arx/aggregates/HierarchyBuilderDate.java | 8 +++ .../HierarchyBuilderGroupingBased.java | 7 +++ .../HierarchyBuilderIntervalBased.java | 7 +++ .../HierarchyBuilderOrderBased.java | 8 +++ .../HierarchyBuilderPriorityBased.java | 7 +++ .../HierarchyBuilderRedactionBased.java | 7 +++ testBuilder1Age.ahs | Bin 0 -> 672 bytes 8 files changed, 103 insertions(+) create mode 100644 testBuilder1Age.ahs diff --git a/src/main/org/deidentifier/arx/aggregates/HierarchyBuilder.java b/src/main/org/deidentifier/arx/aggregates/HierarchyBuilder.java index 21b0506918..c699e20861 100644 --- a/src/main/org/deidentifier/arx/aggregates/HierarchyBuilder.java +++ b/src/main/org/deidentifier/arx/aggregates/HierarchyBuilder.java @@ -25,6 +25,7 @@ import java.io.Serializable; import org.deidentifier.arx.AttributeType.Hierarchy; +import org.deidentifier.arx.DataHandle; /** * Base class for hierarchy builders. Hierarchies can be built in two ways:
@@ -188,4 +189,62 @@ public void save(File file) throws IOException{ public void save(String file) throws IOException{ save(new File(file)); } + /** + * Load the specification of a builder from a given file. + * + * @param file: path of the .ahs file + * @param attrib: attribute name + * @param inputHandle: input data handle + * @throws IOException + */ + public void load(String file, String attrib, DataHandle inputHandle) throws IOException{ + + try { + HierarchyBuilder loaded = HierarchyBuilder.create(file); + + HierarchyBuilderIntervalBased builderIB = null; + HierarchyBuilderRedactionBased builderRB = null; + HierarchyBuilderOrderBased builderOB = null; + HierarchyBuilderPriorityBased builderPB = null; + HierarchyBuilderDate builderDB = null; + + //TODO: There should be a function to get all rows of a column or all columns of a row + String[] atrribData = new String[inputHandle.getNumRows()]; + for (int i=0; i< inputHandle.getNumRows(); i++){ + atrribData[i] = inputHandle.getValue(i,inputHandle.getColumnIndexOf(attrib)); + } + + if (loaded.getType() == Type.REDACTION_BASED) { + builderRB = (HierarchyBuilderRedactionBased)loaded; + builderRB.prepare(atrribData); + builderRB.build(); + inputHandle.getDefinition().setHierarchy(attrib, builderRB); + } else if (loaded.getType() == Type.INTERVAL_BASED) { + builderIB = (HierarchyBuilderIntervalBased)loaded; + builderIB.prepare(atrribData); + builderIB.build(); + inputHandle.getDefinition().setHierarchy(attrib, builderIB); + } else if (loaded.getType() == Type.ORDER_BASED) { + builderOB = (HierarchyBuilderOrderBased)loaded; + builderOB.prepare(atrribData); + builderOB.build(); + inputHandle.getDefinition().setHierarchy(attrib, builderOB); + } else if (loaded.getType() == Type.PRIORITY_BASED) { + builderPB = (HierarchyBuilderPriorityBased)loaded; + builderPB.prepare(atrribData); + builderPB.build(); + inputHandle.getDefinition().setHierarchy(attrib, builderPB); + } else if (loaded.getType() == Type.DATE_BASED) { + builderDB = (HierarchyBuilderDate)loaded; + builderDB.prepare(atrribData); + builderDB.build(); + inputHandle.getDefinition().setHierarchy(attrib, builderDB); + } else { + System.out.println("UNKNOWn builder type! "); + } + } catch (IOException e) { + e.printStackTrace(); + } + } } + diff --git a/src/main/org/deidentifier/arx/aggregates/HierarchyBuilderDate.java b/src/main/org/deidentifier/arx/aggregates/HierarchyBuilderDate.java index 424631a6fc..e0ea3dc94a 100644 --- a/src/main/org/deidentifier/arx/aggregates/HierarchyBuilderDate.java +++ b/src/main/org/deidentifier/arx/aggregates/HierarchyBuilderDate.java @@ -46,6 +46,14 @@ */ public class HierarchyBuilderDate extends HierarchyBuilder implements Serializable { // NO_UCD + /** + * A constructor to use the load function, see example 24. + */ + public HierarchyBuilderDate(){ + super(Type.DATE_BASED); + this.datatype = null; + } + /** * A format-class for localization * diff --git a/src/main/org/deidentifier/arx/aggregates/HierarchyBuilderGroupingBased.java b/src/main/org/deidentifier/arx/aggregates/HierarchyBuilderGroupingBased.java index 6463b62698..12f7d083cc 100644 --- a/src/main/org/deidentifier/arx/aggregates/HierarchyBuilderGroupingBased.java +++ b/src/main/org/deidentifier/arx/aggregates/HierarchyBuilderGroupingBased.java @@ -38,6 +38,13 @@ */ public abstract class HierarchyBuilderGroupingBased extends HierarchyBuilder implements Serializable { + /** + * A constructor to use the load function, see example 24. + */ + public HierarchyBuilderGroupingBased(){ + super(Type.ORDER_BASED); + } + /** * This class represents a fanout parameter. * diff --git a/src/main/org/deidentifier/arx/aggregates/HierarchyBuilderIntervalBased.java b/src/main/org/deidentifier/arx/aggregates/HierarchyBuilderIntervalBased.java index 9bcaa98df2..cba3ad5f4c 100644 --- a/src/main/org/deidentifier/arx/aggregates/HierarchyBuilderIntervalBased.java +++ b/src/main/org/deidentifier/arx/aggregates/HierarchyBuilderIntervalBased.java @@ -40,6 +40,13 @@ */ public class HierarchyBuilderIntervalBased extends HierarchyBuilderGroupingBased { // NO_UCD + /** + * A constructor to use the load function, see example 24. + */ + public HierarchyBuilderIntervalBased(){ + super(); + } + /** * This class represents an node. * diff --git a/src/main/org/deidentifier/arx/aggregates/HierarchyBuilderOrderBased.java b/src/main/org/deidentifier/arx/aggregates/HierarchyBuilderOrderBased.java index 51fcbd8459..8a05d0d03f 100644 --- a/src/main/org/deidentifier/arx/aggregates/HierarchyBuilderOrderBased.java +++ b/src/main/org/deidentifier/arx/aggregates/HierarchyBuilderOrderBased.java @@ -39,6 +39,14 @@ */ public class HierarchyBuilderOrderBased extends HierarchyBuilderGroupingBased { // NO_UCD + /** + * A constructor to use the load function, see example 24. + */ + public HierarchyBuilderOrderBased(){ + super(); + this.comparator = null; + } + /** * A serializable comparator. * diff --git a/src/main/org/deidentifier/arx/aggregates/HierarchyBuilderPriorityBased.java b/src/main/org/deidentifier/arx/aggregates/HierarchyBuilderPriorityBased.java index f6418644d6..bcbdc8421d 100644 --- a/src/main/org/deidentifier/arx/aggregates/HierarchyBuilderPriorityBased.java +++ b/src/main/org/deidentifier/arx/aggregates/HierarchyBuilderPriorityBased.java @@ -42,6 +42,13 @@ */ public class HierarchyBuilderPriorityBased extends HierarchyBuilder implements Serializable { + /** + * A constructor to use the load function, see example 24. + */ + public HierarchyBuilderPriorityBased(){ + super(Type.PRIORITY_BASED); + } + /** * For priorities * @author Fabian Prasser diff --git a/src/main/org/deidentifier/arx/aggregates/HierarchyBuilderRedactionBased.java b/src/main/org/deidentifier/arx/aggregates/HierarchyBuilderRedactionBased.java index 3796b7c7b3..d3190ddb66 100644 --- a/src/main/org/deidentifier/arx/aggregates/HierarchyBuilderRedactionBased.java +++ b/src/main/org/deidentifier/arx/aggregates/HierarchyBuilderRedactionBased.java @@ -39,6 +39,13 @@ */ public class HierarchyBuilderRedactionBased extends HierarchyBuilder implements Serializable { // NO_UCD + /** + * A constructor to use the load function. + */ + public HierarchyBuilderRedactionBased(){ + super(Type.REDACTION_BASED); + } + /** * Order */ diff --git a/testBuilder1Age.ahs b/testBuilder1Age.ahs new file mode 100644 index 0000000000000000000000000000000000000000..cd054c75ea878de2c3035f7cb7faff2d6c3ef404 GIT binary patch literal 672 zcmb7?ze)o^5XL7#5!6IUFIc3qxD!Dv0zz_kF@eQMa@bgeNp{^^xj*Y>Pc9aD7Aq_9 zE$n;|3kwT-_o9ih5pK(GznS^XxBK)C>k|d1iQ*Pzg0fhPYr&L-DzlJt#W-p{STcK-j+!_Wuy|d7lP>Z470ABc=!9o@uC&8@xk1#F*P|l8!=VJexF$ zP{g_87G_W;P>nFV#4u%q#assqbxA(&o~xxy!C}$7UOt<8@A>ti3?%|Ea;D(8D8alIeohU*Y*EdFvGQOnFHWP?OQ~U}@3~FK@Al4zt>(aUVIL06V7KVt gzhCA1l~zaPnQmyP^t)#rf9Usy#B2Lf%3R<20&6ei@c;k- literal 0 HcmV?d00001