本文整理汇总了Java中org.deidentifier.arx.AttributeType类的典型用法代码示例。如果您正苦于以下问题:Java AttributeType类的具体用法?Java AttributeType怎么用?Java AttributeType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AttributeType类属于org.deidentifier.arx包,在下文中一共展示了AttributeType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.deidentifier.arx.AttributeType; //导入依赖的package包/类
/**
* Entry point.
*
* @param args the arguments
*/
public static void main(String[] args) throws IOException {
Data data = loadData();
// Flag every attribute as quasi identifier
for (int i = 0; i < data.getHandle().getNumColumns(); i++) {
data.getDefinition().setAttributeType(data.getHandle().getAttributeName(i), AttributeType.QUASI_IDENTIFYING_ATTRIBUTE);
}
// Perform risk analysis
System.out.println("\n - Input data");
print(data.getHandle());
System.out.println("\n - Quasi-identifiers with values (in percent):");
analyzeAttributes(data.getHandle());
}
示例2: main
import org.deidentifier.arx.AttributeType; //导入依赖的package包/类
/**
* Entry point.
*
* @param args the arguments
* @throws IOException
*/
public static void main(String[] args) throws IOException {
Data data = createData("adult");
data.getDefinition().setAttributeType("occupation", AttributeType.SENSITIVE_ATTRIBUTE);
ARXAnonymizer anonymizer = new ARXAnonymizer();
ARXConfiguration config = ARXConfiguration.create();
config.addPrivacyModel(new EntropyLDiversity("occupation", 5));
config.setMaxOutliers(0.04d);
config.setQualityModel(Metric.createEntropyMetric());
// Anonymize
ARXResult result = anonymizer.anonymize(data, config);
printResult(result, data);
}
示例3: updateEntries
import org.deidentifier.arx.AttributeType; //导入依赖的package包/类
/**
* Updates the view.
*
* @param node
*/
private void updateEntries() {
// Check
if (model == null || model.getInputConfig() == null || model.getInputConfig().getInput() == null) {
return;
}
table.setRedraw(false);
table.removeAll();
DataHandle data = model.getInputConfig().getInput().getHandle();
for (int i = 0; i < data.getNumColumns(); i++) {
String attribute = data.getAttributeName(i);
TableItem item = new TableItem(table, SWT.NONE);
item.setText(new String[] { "", attribute, getDataType(attribute), getDataTypeFormat(attribute) }); //$NON-NLS-1$
AttributeType type = model.getInputDefinition().getAttributeType(attribute);
item.setImage(0, controller.getResources().getImage(type));
if (model.getSelectedAttribute() != null && model.getSelectedAttribute().equals(attribute)) {
table.select(i);
}
}
table.setRedraw(true);
SWTUtil.enable(table);
}
示例4: getResult
import org.deidentifier.arx.AttributeType; //导入依赖的package包/类
/**
* Performs anonymization and returns result.
*
* @return
* @throws IOException
*/
private ARXResult getResult() throws IOException {
if (result == null) {
// Data
Data data = getData("adult");
data.getDefinition().setAttributeType("marital-status", AttributeType.INSENSITIVE_ATTRIBUTE);
data.getDefinition().setDataType("age", DataType.INTEGER);
// Config
ARXConfiguration config = ARXConfiguration.create();
config.addPrivacyModel(new KAnonymity(5));
config.setMaxOutliers(1d);
ARXAnonymizer anonymizer = new ARXAnonymizer();
result = anonymizer.anonymize(data, config);
}
return result;
}
示例5: testSubset4
import org.deidentifier.arx.AttributeType; //导入依赖的package包/类
/**
* Test case
*
* @throws IllegalArgumentException
* @throws IOException
*/
@Test
public void testSubset4() throws IllegalArgumentException, IOException {
Data data = Data.create("./data/dis.csv", StandardCharsets.UTF_8, ';');
data.getDefinition().setAttributeType("age", Hierarchy.create("./data/dis_hierarchy_age.csv", StandardCharsets.UTF_8, ';'));
data.getDefinition().setAttributeType("gender", AttributeType.INSENSITIVE_ATTRIBUTE);
data.getDefinition().setAttributeType("zipcode", AttributeType.INSENSITIVE_ATTRIBUTE);
DataSelector selector = DataSelector.create(data).field("gender").equals("male");
DataSubset subset = DataSubset.create(data, selector);
final ARXAnonymizer anonymizer = new ARXAnonymizer();
final ARXConfiguration config = ARXConfiguration.create();
config.addPrivacyModel(new Inclusion(subset));
anonymizer.anonymize(data, config);
String[][] given = iteratorToArray(data.getHandle().getView().iterator());
String[][] expected = { { "age", "gender", "zipcode" }, { "34", "male", "82667" }, { "66", "male", "81925" }, { "70", "male", "81825" }, { "21", "male", "82451" } };
assertTrue(Arrays.deepEquals(given, expected));
}
示例6: testAllAttributesIdentifying
import org.deidentifier.arx.AttributeType; //导入依赖的package包/类
/**
* Performs a test
*
* @throws IOException
*/
@Test
public void testAllAttributesIdentifying() throws IOException {
try {
provider.createDataDefinition();
final Data data = provider.getData();
data.getDefinition().setAttributeType("age", AttributeType.IDENTIFYING_ATTRIBUTE);
data.getDefinition().setAttributeType("gender", AttributeType.IDENTIFYING_ATTRIBUTE);
data.getDefinition().setAttributeType("zipcode", AttributeType.IDENTIFYING_ATTRIBUTE);
final ARXAnonymizer anonymizer = new ARXAnonymizer();
final ARXConfiguration config = ARXConfiguration.create();
config.addPrivacyModel(new KAnonymity(2));
config.setMaxOutliers(0d);
anonymizer.anonymize(provider.getData(), config);
} catch (final IllegalArgumentException e) {
return;
}
Assert.fail();
}
示例7: testAllAttributesInsensitive
import org.deidentifier.arx.AttributeType; //导入依赖的package包/类
/**
* Performs a test
*
* @throws IOException
*/
@Test
public void testAllAttributesInsensitive() throws IOException {
try {
provider.createDataDefinition();
final Data data = provider.getData();
data.getDefinition().setAttributeType("age", AttributeType.INSENSITIVE_ATTRIBUTE);
data.getDefinition().setAttributeType("gender", AttributeType.INSENSITIVE_ATTRIBUTE);
data.getDefinition().setAttributeType("zipcode", AttributeType.INSENSITIVE_ATTRIBUTE);
final ARXAnonymizer anonymizer = new ARXAnonymizer();
final ARXConfiguration config = ARXConfiguration.create();
config.addPrivacyModel(new KAnonymity(2));
config.setMaxOutliers(0d);
anonymizer.anonymize(provider.getData(), config);
} catch (final IllegalArgumentException e) {
return;
}
Assert.fail();
}
示例8: testAllAttributesSensitive
import org.deidentifier.arx.AttributeType; //导入依赖的package包/类
/**
* Performs a test
*
* @throws IOException
*/
@Test
public void testAllAttributesSensitive() throws IOException {
try {
final ARXAnonymizer anonymizer = new ARXAnonymizer();
provider.createDataDefinition();
final Data data = provider.getData();
data.getDefinition().setAttributeType("age", AttributeType.SENSITIVE_ATTRIBUTE);
data.getDefinition().setAttributeType("gender", AttributeType.SENSITIVE_ATTRIBUTE);
data.getDefinition().setAttributeType("zipcode", AttributeType.SENSITIVE_ATTRIBUTE);
final ARXConfiguration config = ARXConfiguration.create();
config.addPrivacyModel(new KAnonymity(2));
config.setMaxOutliers(-0.2d);
anonymizer.anonymize(provider.getData(), config);
} catch (final IllegalArgumentException e) {
return;
}
Assert.fail();
}
示例9: testMoreThanOneAttributeSensitive
import org.deidentifier.arx.AttributeType; //导入依赖的package包/类
/**
* Performs a test
*
* @throws IOException
*/
@Test
public void testMoreThanOneAttributeSensitive() throws IOException {
try {
final ARXAnonymizer anonymizer = new ARXAnonymizer();
provider.createDataDefinition();
final Data data = provider.getData();
data.getDefinition().setAttributeType("gender", AttributeType.SENSITIVE_ATTRIBUTE);
data.getDefinition().setAttributeType("zipcode", AttributeType.SENSITIVE_ATTRIBUTE);
final ARXConfiguration config = ARXConfiguration.create();
config.addPrivacyModel(new KAnonymity(2));
config.setMaxOutliers(0d);
anonymizer.anonymize(data, config);
} catch (final IllegalArgumentException e) {
return;
}
Assert.fail();
}
示例10: testEmptyDatasetWithAttributeDefinition
import org.deidentifier.arx.AttributeType; //导入依赖的package包/类
/**
* Performs a test.
*
* @throws IOException
*/
@Test
public void testEmptyDatasetWithAttributeDefinition() throws IOException {
try {
final ARXAnonymizer anonymizer = new ARXAnonymizer();
final Data data = Data.create();
data.getDefinition()
.setAttributeType("age", AttributeType.IDENTIFYING_ATTRIBUTE);
final ARXConfiguration config = ARXConfiguration.create();
config.addPrivacyModel(new KAnonymity(2));
config.setMaxOutliers(1.2d);
anonymizer.anonymize(provider.getData(), config);
} catch (final IllegalArgumentException e) {
return;
}
Assert.fail();
}
示例11: testNullHierarchy
import org.deidentifier.arx.AttributeType; //导入依赖的package包/类
/**
* Performs a test.
*
* @throws IOException
*/
@Test
public void testNullHierarchy() throws IOException {
try {
final ARXAnonymizer anonymizer = new ARXAnonymizer();
final Data data = provider.getData();
data.getDefinition().setAttributeType("age", (AttributeType) null);
final ARXConfiguration config = ARXConfiguration.create();
config.addPrivacyModel(new KAnonymity(2));
config.setMaxOutliers(1.2d);
anonymizer.anonymize(data, config);
} catch (final NullPointerException e) {
return;
}
Assert.fail();
}
示例12: getMicroAggregationFunction
import org.deidentifier.arx.AttributeType; //导入依赖的package包/类
/**
* Returns the microaggregation function for the given label
*
* @param function
* @return
*/
private MicroAggregationFunctionDescription getMicroAggregationFunction(String label) {
for (MicroAggregationFunctionDescription function : AttributeType.listMicroAggregationFunctions()) {
if (function.getLabel().equals(label)) {
return function;
}
}
return null;
}
示例13: main
import org.deidentifier.arx.AttributeType; //导入依赖的package包/类
/**
* Entry point.
*
* @param args the arguments
* @throws ParseException
* @throws IOException
*/
public static void main(String[] args) throws ParseException, IOException {
String[] features = new String[] {
"sex",
"age",
"race",
"marital-status",
"education",
"native-country",
"workclass",
"occupation",
"salary-class"
};
String clazz = "marital-status";
Data data = createData("adult");
data.getDefinition().setAttributeType("marital-status", AttributeType.INSENSITIVE_ATTRIBUTE);
data.getDefinition().setDataType("age", DataType.INTEGER);
System.out.println("Input dataset");
System.out.println(data.getHandle().getStatistics().getClassificationPerformance(features, clazz, ARXLogisticRegressionConfiguration.create()));
ARXAnonymizer anonymizer = new ARXAnonymizer();
ARXConfiguration config = ARXConfiguration.create();
config.addPrivacyModel(new KAnonymity(5));
config.setMaxOutliers(1d);
config.setQualityModel(Metric.createLossMetric());
ARXResult result = anonymizer.anonymize(data, config);
System.out.println("5-anonymous dataset");
System.out.println(result.getOutput().getStatistics().getClassificationPerformance(features, clazz, ARXLogisticRegressionConfiguration.create()));
}
示例14: main
import org.deidentifier.arx.AttributeType; //导入依赖的package包/类
/**
* Entry point.
*
* @param args
* the arguments
*/
public static void main(String[] args) throws IOException {
// Define data
Data data = getData();
// Define attribute types
data.getDefinition().setAttributeType("age", getHierarchyAge());
data.getDefinition().setAttributeType("zipcode", getHierarchyZipcode());
data.getDefinition().setAttributeType("disease1", AttributeType.SENSITIVE_ATTRIBUTE);
data.getDefinition().setAttributeType("disease2", AttributeType.SENSITIVE_ATTRIBUTE);
// Create an instance of the anonymizer
ARXAnonymizer anonymizer = new ARXAnonymizer();
ARXConfiguration config = ARXConfiguration.create();
config.addPrivacyModel(new KAnonymity(3));
config.addPrivacyModel(new HierarchicalDistanceTCloseness("disease1", 0.6d, getHierarchyDisease()));
config.addPrivacyModel(new RecursiveCLDiversity("disease2", 3d, 2));
config.setMaxOutliers(0d);
config.setQualityModel(Metric.createEntropyMetric());
// Now anonymize
ARXResult result = anonymizer.anonymize(data, config);
// Print info
printResult(result, data);
// Process results
if (result.getGlobalOptimum() != null) {
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()));
}
}
}
示例15: main
import org.deidentifier.arx.AttributeType; //导入依赖的package包/类
/**
* Entry point.
*
* @param args the arguments
*/
public static void main(String[] args) throws IOException {
// Load data
DataSource source = DataSource.createCSVSource("data/test2.csv", Charset.forName("UTF-8"), ';', true);
source.addColumn("ZIPCode", DataType.STRING);
source.addColumn("Age", DataType.INTEGER);
source.addColumn("Salary", DataType.INTEGER); // in k
source.addColumn("Disease", DataType.STRING);
Data data = Data.create(source);
// Load hierarchies
Hierarchy zipcode = Hierarchy.create("data/test2_hierarchy_ZIPCode.csv", Charset.forName("UTF-8"), ';');
Hierarchy age = Hierarchy.create("data/test2_hierarchy_Age.csv", Charset.forName("UTF-8"), ';');
// Define
data.getDefinition().setAttributeType("ZIPCode", zipcode);
data.getDefinition().setAttributeType("Age", age);
data.getDefinition().setAttributeType("Salary", AttributeType.SENSITIVE_ATTRIBUTE);
// Create an instance of the anonymizer
ARXAnonymizer anonymizer = new ARXAnonymizer();
ARXConfiguration config = ARXConfiguration.create();
config.addPrivacyModel(new OrderedDistanceTCloseness("Salary", 0.3751));
config.setMaxOutliers(0d);
// Anonymize
ARXResult result = anonymizer.anonymize(data, config);
// Print results
System.out.println("Output data:");
print(result.getOutput());
}