Commit c0f43c0b authored by Klaus Hamberger's avatar Klaus Hamberger
Browse files

Added anonymization by consistent (cross-label) numbering (meant specially for place names).

git-svn-id: svn+ssh://svn.code.sf.net/p/tip-puck/code/trunk@2341 fbf60bc9-78ff-467a-80f5-d9f1d8e511fc
parent 55fababf
......@@ -158,6 +158,7 @@ public class Attributes extends HashMap<String, Attribute> implements Iterable<A
//
return result;
}
/**
*
......
......@@ -18,6 +18,7 @@ public class AttributeFilter {
REPLACE_BY_BLANK,
FORCE_TO_BLANK,
ANONYMIZE_BY_NUMBERING,
ANONYMIZE_BY_CONSISTENT_NUMBERING,
ANONYMIZE_BY_GENDER_AND_ID_HF,
ANONYMIZE_BY_GENDER_AND_ID_MF,
ANONYMIZE_BY_FIRST_NAME,
......
......@@ -9,6 +9,7 @@ import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.batik.dom.util.HashTable;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -289,6 +290,63 @@ public class AttributeWorker {
return result;
}
/**
* This method anonymizes families by numbering each one.
*
* @param source
* Source to anonymize.
*
* @label label of attribute to anonymize.
*
* @return the number of field anonymized
*/
public static int anonymizeByNumbering(final Hashtable<String, String> pivot, final Actors source, final String labelPart) {
int result;
//
result = 0;
//
if ((source != null) && (labelPart != null)) {
//
for (Actor actor : source) {
for (Attribute attribute : actor.attributes()){
String label = attribute.getLabel();
if (label.contains(labelPart)){
//
String oldValue = actor.attributes().getValue(label);
if (oldValue != null) {
//
oldValue = oldValue.toLowerCase();
//
String newValue = pivot.get(oldValue);
//
if (newValue == null) {
newValue = String.valueOf(pivot.size() + 1);
pivot.put(oldValue, newValue);
}
//
actor.attributes().put(label, newValue);
//
result += 1;
}
}
}
}
}
//
return result;
}
/**
* This method anonymizes families by numbering each one.
*
......@@ -340,6 +398,124 @@ public class AttributeWorker {
return result;
}
/**
* This method anonymizes families by numbering each one.
*
* @param source
* Source to anonymize.
*
* @label label of attribute to anonymize.
*
* @return the number of field anonymized
*/
public static int anonymizeByNumbering(final Hashtable<String, String> pivot, final Families source, final String labelPart) {
int result;
//
result = 0;
//
if ((source != null) && (labelPart != null)) {
//
for (Family family : source) {
for (Attribute attribute : family.attributes()){
String label = attribute.getLabel();
if (label.contains(labelPart)){
//
String oldValue = family.attributes().getValue(label);
if (oldValue != null) {
//
oldValue = oldValue.toLowerCase();
//
String newValue = pivot.get(oldValue);
//
if (newValue == null) {
newValue = String.valueOf(pivot.size() + 1);
pivot.put(oldValue, newValue);
}
//
family.attributes().put(label, newValue);
//
result += 1;
}
}
}
}
}
//
return result;
}
/**
* This method anonymizes families by numbering each one.
*
* @param source
* Source to anonymize.
*
* @label Label of attribute to anonymize.
*
* @return The number of field anonymized.
*/
public static int anonymizeByNumbering(final Hashtable<String, String> pivot, final Individuals source, final String labelPart) {
int result;
//
result = 0;
//
if ((source != null) && (labelPart != null)) {
//
for (Individual individual : source) {
for (Attribute attribute : individual.attributes()){
String label = attribute.getLabel();
if (label.contains(labelPart)){
//
String oldValue = individual.attributes().getValue(label);
if (oldValue != null) {
//
oldValue = oldValue.toLowerCase();
//
String newValue = pivot.get(oldValue);
//
if (newValue == null) {
newValue = String.valueOf(pivot.size() + 1);
pivot.put(oldValue, newValue);
}
//
individual.attributes().put(label, newValue);
//
result += 1;
}
}
}
}
}
//
return result;
}
/**
* This method anonymizes families by numbering each one.
*
......@@ -448,6 +624,66 @@ public class AttributeWorker {
//
return result;
}
/**
*
* @param net
* @param filter
* @return The number of field anonymized.
*/
public static long anonymizeByConsistentNumbering(final Net net, final Segmentation segmentation, final AttributeFilter filter) {
long result;
//
result = 0;
Hashtable<String, String> pivot = new Hashtable<String, String>();
//
if ((net != null) && (filter != null)) {
//
if ((filter.getScope() == AttributeFilter.Scope.ALL) || (filter.getScope() == AttributeFilter.Scope.CORPUS)) {
//
result += filter(net.attributes(), filter.getLabel(), filter.getMode());
}
//
if ((filter.getScope() == AttributeFilter.Scope.ALL) || (filter.getScope() == AttributeFilter.Scope.INDIVIDUALS)) {
//
result += anonymizeByNumbering(pivot, segmentation.getCurrentIndividuals(), filter.getLabel());
}
//
if ((filter.getScope() == AttributeFilter.Scope.ALL) || (filter.getScope() == AttributeFilter.Scope.FAMILIES)) {
//
result += anonymizeByNumbering(pivot, segmentation.getCurrentFamilies(), filter.getLabel());
}
//
if ((filter.getScope() == AttributeFilter.Scope.ALL) || (filter.getScope() == AttributeFilter.Scope.RELATIONS)) {
//
for (RelationModel model : net.relationModels()) {
//
Relations relations = segmentation.getCurrentRelations().getByModel(model);
result += anonymizeByNumbering(pivot, relations, filter.getLabel());
}
} else if (filter.getScope() == AttributeFilter.Scope.RELATION) {
//
Relations relations = segmentation.getCurrentRelations().getByModelName(filter.getOptionalRelationName());
result = anonymizeByNumbering(pivot, relations, filter.getLabel());
}
//
if ((filter.getScope() == AttributeFilter.Scope.ALL) || (filter.getScope() == AttributeFilter.Scope.ACTORS)) {
//
result += anonymizeByNumbering(pivot, segmentation.getCurrentRelations().getActors(), filter.getLabel());
}
}
//
return result;
}
/**
*
......@@ -554,6 +790,59 @@ public class AttributeWorker {
return result;
}
/**
*
* @param source
* @param label
* @return The number of field anonymized.
*/
public static int anonymizeByNumbering(final Hashtable<String,String> pivot, final Relations source, final String labelPart) {
int result;
//
result = 0;
//
if ((source != null) && (labelPart != null)) {
//
for (Relation relation : source) {
for (Attribute attribute : relation.attributes()){
String label = attribute.getLabel();
if (label.contains(labelPart)){
//
String oldValue = relation.attributes().getValue(label);
if (oldValue != null) {
//
oldValue = oldValue.toLowerCase();
//
String newValue = pivot.get(oldValue);
//
if (newValue == null) {
newValue = String.valueOf(pivot.size() + 1);
pivot.put(oldValue, newValue);
}
//
relation.attributes().put(label, newValue);
//
result += 1;
}
}
}
}
}
//
return result;
}
/**
*
* @param target
......@@ -875,6 +1164,10 @@ public class AttributeWorker {
//
result = anonymizeByNumbering(net, segmentation, filter);
} else if (filter.getMode() == AttributeFilter.Mode.ANONYMIZE_BY_CONSISTENT_NUMBERING) {
//
result = anonymizeByConsistentNumbering(net, segmentation, filter);
} else if ((filter.getScope() == AttributeFilter.Scope.INDIVIDUALS) && (filter.getMode() == AttributeFilter.Mode.ANONYMIZE_BY_FIRST_NAME)) {
//
result = AttributeWorker.anonymizeByFirstName(segmentation.getCurrentIndividuals());
......
......@@ -52,6 +52,7 @@ public class AttributeFilterInputDialog extends JDialog {
private JRadioButton rdbtnBlank;
private JRadioButton rdbtnForcedBlank;
private JRadioButton rdbtnAnonymizeByNumbering;
private JRadioButton rdbtnAnonymizeByConsistentNumbering;
private JRadioButton rdbtnRemove;
private JRadioButton rdbtnCleanBlank;
private JRadioButton rdbtnReduceDate;
......@@ -192,6 +193,11 @@ public class AttributeFilterInputDialog extends JDialog {
this.buttonGroupType.add(this.rdbtnAnonymizeByNumbering);
panel.add(this.rdbtnAnonymizeByNumbering);
}
{
this.rdbtnAnonymizeByConsistentNumbering = new JRadioButton("anonymize by consistent numbering");
this.buttonGroupType.add(this.rdbtnAnonymizeByConsistentNumbering);
panel.add(this.rdbtnAnonymizeByConsistentNumbering);
}
{
this.rdbtnBlank = new JRadioButton("replace by an empty string");
this.buttonGroupType.add(this.rdbtnBlank);
......@@ -346,6 +352,8 @@ public class AttributeFilterInputDialog extends JDialog {
result.setMode(AttributeFilter.Mode.CLEAN_BLANK);
} else if (this.rdbtnAnonymizeByNumbering.isSelected()) {
result.setMode(AttributeFilter.Mode.ANONYMIZE_BY_NUMBERING);
} else if (this.rdbtnAnonymizeByConsistentNumbering.isSelected()) {
result.setMode(AttributeFilter.Mode.ANONYMIZE_BY_CONSISTENT_NUMBERING);
} else if (this.rdbtnBlank.isSelected()) {
result.setMode(AttributeFilter.Mode.REPLACE_BY_BLANK);
} else if (this.rdbtnForcedBlank.isSelected()) {
......@@ -427,10 +435,15 @@ public class AttributeFilterInputDialog extends JDialog {
//
switch (source.getMode()) {
case ANONYMIZE_BY_NUMBERING:
unsetMode();
this.rdbtnAnonymizeByNumbering.setSelected(true);
break;
case ANONYMIZE_BY_NUMBERING:
unsetMode();
this.rdbtnAnonymizeByNumbering.setSelected(true);
break;
case ANONYMIZE_BY_CONSISTENT_NUMBERING:
unsetMode();
this.rdbtnAnonymizeByConsistentNumbering.setSelected(true);
break;
case CAPITALIZE_VALUE:
unsetMode();
......@@ -495,6 +508,7 @@ public class AttributeFilterInputDialog extends JDialog {
this.rdbtnClean.setSelected(false);
this.rdbtnCleanBlank.setSelected(false);
this.rdbtnAnonymizeByNumbering.setSelected(false);
this.rdbtnAnonymizeByConsistentNumbering.setSelected(false);
this.rdbtnBlank.setSelected(false);
this.rdbtnForcedBlank.setSelected(false);
this.rdbtnRemove.setSelected(false);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment