Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loading .ahs files in the api #436

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions src/main/org/deidentifier/arx/aggregates/HierarchyBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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:<br>
Expand Down Expand Up @@ -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();
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@
*/
public class HierarchyBuilderDate extends HierarchyBuilder<Date> 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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
*/
public abstract class HierarchyBuilderGroupingBased<T> extends HierarchyBuilder<T> implements Serializable {

/**
* A constructor to use the load function, see example 24.
*/
public HierarchyBuilderGroupingBased(){
super(Type.ORDER_BASED);
}

/**
* This class represents a fanout parameter.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@
*/
public class HierarchyBuilderIntervalBased<T> extends HierarchyBuilderGroupingBased<T> { // NO_UCD

/**
* A constructor to use the load function, see example 24.
*/
public HierarchyBuilderIntervalBased(){
super();
}

/**
* This class represents an node.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@
*/
public class HierarchyBuilderOrderBased<T> extends HierarchyBuilderGroupingBased<T> { // NO_UCD

/**
* A constructor to use the load function, see example 24.
*/
public HierarchyBuilderOrderBased(){
super();
this.comparator = null;
}

/**
* A serializable comparator.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@
*/
public class HierarchyBuilderPriorityBased<T> extends HierarchyBuilder<T> implements Serializable {

/**
* A constructor to use the load function, see example 24.
*/
public HierarchyBuilderPriorityBased(){
super(Type.PRIORITY_BASED);
}

/**
* For priorities
* @author Fabian Prasser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@
*/
public class HierarchyBuilderRedactionBased<T> extends HierarchyBuilder<T> implements Serializable { // NO_UCD

/**
* A constructor to use the load function.
*/
public HierarchyBuilderRedactionBased(){
super(Type.REDACTION_BASED);
}

/**
* Order
*/
Expand Down
Binary file added testBuilder1Age.ahs
Binary file not shown.