当前位置: 首页>>代码示例>>Java>>正文


Java DataHandle.sort方法代码示例

本文整理汇总了Java中org.deidentifier.arx.DataHandle.sort方法的典型用法代码示例。如果您正苦于以下问题:Java DataHandle.sort方法的具体用法?Java DataHandle.sort怎么用?Java DataHandle.sort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.deidentifier.arx.DataHandle的用法示例。


在下文中一共展示了DataHandle.sort方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testSorting

import org.deidentifier.arx.DataHandle; //导入方法依赖的package包/类
/**
 * Test case
 *
 * @throws IllegalArgumentException
 * @throws IOException
 */
@Test
public void testSorting() throws IllegalArgumentException, IOException {
    
    provider.createDataDefinition();
    final ARXAnonymizer anonymizer = new ARXAnonymizer();
    final ARXConfiguration config = ARXConfiguration.create();
    config.addPrivacyModel(new KAnonymity(2));
    config.setMaxOutliers(0d);
    
    final ARXResult result = anonymizer.anonymize(provider.getData(), config);
    final DataHandle outHandle = result.getOutput(false);
    final DataHandle inHandle = provider.getData().getHandle();
    inHandle.sort(true, 0);
    
    final String[][] inArray = iteratorToArray(inHandle.iterator());
    final String[][] resultArray = iteratorToArray(outHandle.iterator());
    
    final String[][] expected = { { "age", "gender", "zipcode" }, { "<50", "*", "816**" }, { "<50", "*", "819**" }, { "<50", "*", "816**" }, { "<50", "*", "819**" }, { ">=50", "*", "819**" }, { ">=50", "*", "819**" }, { ">=50", "*", "819**" } };
    
    final String[][] expectedIn = { { "age", "gender", "zipcode" }, { "34", "male", "81667" }, { "34", "female", "81931" }, { "45", "female", "81675" }, { "45", "male", "81931" }, { "66", "male", "81925" }, { "70", "female", "81931" }, { "70", "male", "81931" } };
    
    assertTrue(Arrays.deepEquals(inArray, expectedIn));
    assertTrue(Arrays.deepEquals(resultArray, expected));
    
}
 
开发者ID:arx-deidentifier,项目名称:arx,代码行数:32,代码来源:TestDataHandle.java

示例2: testStableSorting

import org.deidentifier.arx.DataHandle; //导入方法依赖的package包/类
/**
 * Test case
 *
 * @throws IllegalArgumentException
 * @throws IOException
 */
@Test
public void testStableSorting() throws IllegalArgumentException, IOException {
    
    provider.createDataDefinition();
    final ARXAnonymizer anonymizer = new ARXAnonymizer();
    final DataHandle inHandle = provider.getData().getHandle();
    
    // Alter the definition
    provider.getData().getDefinition().setAttributeType("gender", AttributeType.IDENTIFYING_ATTRIBUTE);
    
    final ARXConfiguration config = ARXConfiguration.create();
    config.addPrivacyModel(new KAnonymity(2));
    config.setMaxOutliers(0d);
    
    final ARXResult result = anonymizer.anonymize(provider.getData(), config);
    final DataHandle outHandle = result.getOutput(false);
    outHandle.sort(true, 2);
    
    final String[][] inArray = iteratorToArray(inHandle.iterator());
    final String[][] resultArray = iteratorToArray(outHandle.iterator());
    
    final String[][] expected = { { "age", "gender", "zipcode" }, { "<50", "*", "816**" }, { "<50", "*", "816**" }, { ">=50", "*", "819**" }, { ">=50", "*", "819**" }, { "<50", "*", "819**" }, { ">=50", "*", "819**" }, { "<50", "*", "819**" } };
    
    final String[][] expectedIn = { { "age", "gender", "zipcode" }, { "34", "male", "81667" }, { "45", "female", "81675" }, { "66", "male", "81925" }, { "70", "female", "81931" }, { "34", "female", "81931" }, { "70", "male", "81931" }, { "45", "male", "81931" } };
    
    assertTrue(Arrays.deepEquals(resultArray, expected));
    assertTrue(Arrays.deepEquals(inArray, expectedIn));
    
}
 
开发者ID:arx-deidentifier,项目名称:arx,代码行数:36,代码来源:TestDataHandle.java

示例3: testSubset1

import org.deidentifier.arx.DataHandle; //导入方法依赖的package包/类
/**
 * Test case
 *
 * @throws IllegalArgumentException
 * @throws IOException
 */
@Test
public void testSubset1() throws IllegalArgumentException, IOException {
    
    provider.createDataDefinition();
    final ARXAnonymizer anonymizer = new ARXAnonymizer();
    final DataHandle inHandle = provider.getData().getHandle();
    
    // Alter the definition
    provider.getData().getDefinition().setAttributeType("gender", AttributeType.IDENTIFYING_ATTRIBUTE);
    
    DataSelector selector = DataSelector.create(provider.getData()).field("age").equals("70").or().equals("34");
    
    DataSubset subset = DataSubset.create(provider.getData(), selector);
    
    final ARXConfiguration config = ARXConfiguration.create();
    config.addPrivacyModel(new KAnonymity(2));
    config.addPrivacyModel(new DPresence(0, 1, subset));
    config.setMaxOutliers(0d);
    
    final ARXResult result = anonymizer.anonymize(provider.getData(), config);
    final DataHandle outHandle = result.getOutput(false);
    outHandle.sort(true, 2);
    
    outHandle.getView().sort(false, 0);
    
    String[][] given = iteratorToArray(inHandle.getView().iterator());
    String[][] expected = { { "age", "gender", "zipcode" }, { "70", "female", "81931" }, { "70", "male", "81931" }, { "34", "male", "81667" }, { "34", "female", "81931" } };
    
    assertTrue(Arrays.deepEquals(given, expected));
    
}
 
开发者ID:arx-deidentifier,项目名称:arx,代码行数:38,代码来源:TestDataHandle.java

示例4: main

import org.deidentifier.arx.DataHandle; //导入方法依赖的package包/类
/**
 * Entry point.
 * 
 * @param args
 *            the arguments
 */
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");

    // Obtain a handle
    DataHandle inHandle = data.getHandle();

    // Read the encoded data
    inHandle.getNumRows();
    inHandle.getNumColumns();
    inHandle.getAttributeName(0);
    inHandle.getValue(0, 0);

    // Define hierarchy. Only excerpts for readability
    DefaultHierarchy zipcode = Hierarchy.create();
    zipcode.add("81667", "8166*", "816**", "81***", "8****", "*****");
    zipcode.add("81675", "8167*", "816**", "81***", "8****", "*****");
    zipcode.add("81925", "8192*", "819**", "81***", "8****", "*****");
    zipcode.add("81931", "8193*", "819**", "81***", "8****", "*****");

    // Create a data definition
    data.getDefinition()
        .setAttributeType("age", AttributeType.IDENTIFYING_ATTRIBUTE);
    data.getDefinition()
        .setAttributeType("gender", AttributeType.INSENSITIVE_ATTRIBUTE);
    data.getDefinition().setAttributeType("zipcode", zipcode);

    data.getDefinition().setDataType("zipcode", DataType.DECIMAL);

    // Create an instance of the anonymizer
    ARXAnonymizer anonymizer = new ARXAnonymizer();
    ARXConfiguration config = ARXConfiguration.create();
    config.addPrivacyModel(new KAnonymity(2));
    config.setMaxOutliers(0d);

    // Now anonymize the data utilizing the pre-encoded data
    ARXResult result = anonymizer.anonymize(data, config);

    // Obtain a handle for the transformed data
    DataHandle outHandle = result.getOutput(false);

    // Sort the data. This operation is implicitly performed on both
    // representations of the dataset.
    outHandle.sort(false, 2);

    // 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()));
    }
}
 
开发者ID:arx-deidentifier,项目名称:arx,代码行数:72,代码来源:Example4.java

示例5: testMultipleDataHandlesForkSync

import org.deidentifier.arx.DataHandle; //导入方法依赖的package包/类
/**
 * Test case
 *
 * @throws IllegalArgumentException
 * @throws IOException
 */
@Test
public void testMultipleDataHandlesForkSync() throws IllegalArgumentException, IOException {
    
    provider.createDataDefinition();
    final ARXAnonymizer anonymizer = new ARXAnonymizer();
    final DataHandle inHandle = provider.getData().getHandle();
    
    final ARXConfiguration config = ARXConfiguration.create();
    config.addPrivacyModel(new KAnonymity(2));
    config.setMaxOutliers(0d);
    config.setSuppressionAlwaysEnabled(false);
    
    final ARXResult result = anonymizer.anonymize(provider.getData(), config);
    
    // get top and bottom node
    ARXLattice lattice = result.getLattice();
    ARXNode topNode = lattice.getTop();
    ARXNode bottomNode = lattice.getBottom();
    
    // get various handle copies
    DataHandle optimal = result.getOutput();
    DataHandle top = result.getOutput(topNode);
    DataHandle bottom = result.getOutput(bottomNode);
    
    // sort input data
    optimal.sort(false, 0);
    
    // sort bottom handle
    bottom.sort(true, 2);
    
    final String[][] inArray = iteratorToArray(inHandle.iterator());
    final String[][] optimalArray = iteratorToArray(optimal.iterator());
    final String[][] topArray = iteratorToArray(top.iterator());
    final String[][] bottomArray = iteratorToArray(bottom.iterator());
    
    final String[][] topExpected = { { "age", "gender", "zipcode" }, { "*", "*", "*****" }, { "*", "*", "*****" }, { "*", "*", "*****" }, { "*", "*", "*****" }, { "*", "*", "*****" }, { "*", "*", "*****" }, { "*", "*", "*****" } };
    final String[][] bottomExpected = { { "age", "gender", "zipcode" }, { "34", "male", "81667" }, { "45", "female", "81675" }, { "66", "male", "81925" }, { "70", "female", "81931" }, { "70", "male", "81931" }, { "34", "female", "81931" }, { "45", "male", "81931" } };
    final String[][] optimalExpected = { { "age", "gender", "zipcode" }, { "<50", "*", "816**" }, { "<50", "*", "816**" }, { ">=50", "*", "819**" }, { ">=50", "*", "819**" }, { ">=50", "*", "819**" }, { "<50", "*", "819**" }, { "<50", "*", "819**" } };
    
    assertTrue(Arrays.deepEquals(optimalArray, optimalExpected));
    assertTrue(Arrays.deepEquals(topArray, topExpected));
    assertTrue(Arrays.deepEquals(bottomArray, bottomExpected));
    assertTrue(Arrays.deepEquals(inArray, bottomExpected));
    
}
 
开发者ID:arx-deidentifier,项目名称:arx,代码行数:52,代码来源:TestDataHandle.java

示例6: testSubset2

import org.deidentifier.arx.DataHandle; //导入方法依赖的package包/类
/**
 * Test case
 *
 * @throws IllegalArgumentException
 * @throws IOException
 */
@Test
public void testSubset2() throws IllegalArgumentException, IOException {
    
    provider.createDataDefinition();
    final ARXAnonymizer anonymizer = new ARXAnonymizer();
    
    // Alter the definition
    provider.getData().getDefinition().setAttributeType("gender", AttributeType.IDENTIFYING_ATTRIBUTE);
    
    DataSelector selector = DataSelector.create(provider.getData()).field("age").equals("70").or().equals("34");
    
    DataSubset subset = DataSubset.create(provider.getData(), selector);
    
    final ARXConfiguration config = ARXConfiguration.create();
    config.addPrivacyModel(new KAnonymity(2));
    config.addPrivacyModel(new DPresence(0, 1, subset));
    config.setMaxOutliers(0d);
    
    final ARXResult result = anonymizer.anonymize(provider.getData(), config);
    final DataHandle outHandle = result.getOutput(false);
    outHandle.sort(true, 2);
    
    outHandle.getView().sort(false, 0);
    
    String[][] given = iteratorToArray(outHandle.getView().iterator());
    String[][] expected = { { "age", "gender", "zipcode" }, { "70", "*", "81***" }, { "70", "*", "81***" }, { "34", "*", "81***" }, { "34", "*", "81***" } };
    
    assertTrue(Arrays.deepEquals(given, expected));
    
}
 
开发者ID:arx-deidentifier,项目名称:arx,代码行数:37,代码来源:TestDataHandle.java


注:本文中的org.deidentifier.arx.DataHandle.sort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。