/*
* ARX: Powerful Data Anonymization
* Copyright 2012 - 2017 Fabian Prasser, Florian Kohlmayer and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.deidentifier.arx.examples;
import java.io.IOException;
import java.util.Iterator;
import org.deidentifier.arx.ARXAnonymizer;
import org.deidentifier.arx.ARXConfiguration;
import org.deidentifier.arx.ARXResult;
import org.deidentifier.arx.AttributeType;
import org.deidentifier.arx.Data;
import org.deidentifier.arx.Data.DefaultData;
import org.deidentifier.arx.aggregates.HierarchyBuilderRedactionBased;
import org.deidentifier.arx.aggregates.HierarchyBuilderRedactionBased.Order;
import org.deidentifier.arx.criteria.KAnonymity;
import cern.colt.Arrays;
/**
* This class implements examples on how to directly use empty and functional
* hierarchies.
*
* @author Fabian Prasser
* @author Florian Kohlmayer
*/
public class Example24 extends Example {
/**
* Entry point.
*
* @param args
* The arguments
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// Define data
DefaultData data = Data.create();
data.add("age", "gender", "zipcode");
data.add("34", "male", "81667");
data.add("45", "female", "81675");
data.add("66", "male", "81925");
data.add("70", "female", "81931");
data.add("34", "female", "81931");
data.add("70", "male", "81931");
data.add("45", "male", "81931");
// Define hierarchies
HierarchyBuilderRedactionBased<?> builder1 = HierarchyBuilderRedactionBased.create(Order.RIGHT_TO_LEFT,
Order.RIGHT_TO_LEFT,
' ',
'*');
HierarchyBuilderRedactionBased<?> builder2 = HierarchyBuilderRedactionBased.create(Order.RIGHT_TO_LEFT,
Order.RIGHT_TO_LEFT,
' ',
'*');
data.getDefinition().setAttributeType("age", builder1);
data.getDefinition().setAttributeType("gender", AttributeType.QUASI_IDENTIFYING_ATTRIBUTE);
data.getDefinition().setAttributeType("zipcode", builder2);
// Create an instance of the anonymizer
ARXAnonymizer anonymizer = new ARXAnonymizer();
ARXConfiguration config = ARXConfiguration.create();
config.addPrivacyModel(new KAnonymity(3));
config.setMaxOutliers(0d);
ARXResult result = anonymizer.anonymize(data, config);
// Print info
printResult(result, data);
// Process results
System.out.println(" - Transformed data:");
Iterator<String[]> transformed = result.getOutput(false).iterator();
while (transformed.hasNext()) {
System.out.print(" ");
System.out.println(Arrays.toString(transformed.next()));
}
}
}