Skip to content

Commit

Permalink
Support using g/s factor through UI when doing local anonymizations
Browse files Browse the repository at this point in the history
  • Loading branch information
prasser committed Dec 13, 2024
1 parent a93eeff commit 3fce38c
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/gui/org/deidentifier/arx/gui/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ public void actionMenuEditAnonymize() {
}

// Open configuration dialog
ModelAnonymizationConfiguration configuration = this.actionShowLocalAnonymizationDialog();
ModelAnonymizationConfiguration configuration = this.actionShowAnonymizationDialog();
if (configuration == null) {
return;
}
Expand Down Expand Up @@ -1817,11 +1817,11 @@ public String actionShowInputDialog(final Shell shell,
}

/**
* Shows a dialog for configuration of local anonymization.
* Shows a dialog for configuration of anonymization.
* @return Returns the parameters selected by the user. Returns a pair.
* First: max. time per iteration. Second: min. records per iteration.
*/
public ModelAnonymizationConfiguration actionShowLocalAnonymizationDialog() {
public ModelAnonymizationConfiguration actionShowAnonymizationDialog() {
return main.showLocalAnonymizationDialog(model);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public static enum TransformationType {
private ModelAnonymizationConfiguration.TransformationType transformationType = TransformationType.GLOBAL;
/** Limits */
private Boolean stepLimitEnabled = false;
/** Code model settings*/
private Boolean useCodingModelSettings = false;

/**
* Creates a new instance
Expand Down Expand Up @@ -143,6 +145,18 @@ public boolean isTimeLimitEnabled() {
return !isStepLimitEnabled();
}

/**
* Use coding model settings from main UI
* @return
*/
public boolean isUseCodingModelSettings() {
// Backwards compatibility
if (this.useCodingModelSettings == null) {
this.useCodingModelSettings = false;
}
return this.useCodingModelSettings;
}

/**
* @param heuristicSearchStepLimit the heuristicSearchStepLimit to set
*/
Expand All @@ -156,7 +170,7 @@ public void setHeuristicSearchStepLimit(int heuristicSearchStepLimit) {
public void setHeuristicSearchTimeLimit(double heuristicSearchTimeLimit) {
model.setHeuristicSearchTimeLimit((int)(heuristicSearchTimeLimit * 1000d));
}

/**
* @param numIterations the numIterations to set
*/
Expand Down Expand Up @@ -191,4 +205,12 @@ public void setTimeLimitEnabled(boolean timeLimitEnabled) {
public void setTransformationType(ModelAnonymizationConfiguration.TransformationType transformationType) {
this.transformationType = transformationType;
}

/**
* Set use coding model
* @param useCodingModelSettings
*/
public void setUseCodingModelSettings(boolean useCodingModelSettings) {
this.useCodingModelSettings = useCodingModelSettings;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1494,6 +1494,7 @@ DialogAnonymization.19=Best-effort, binary
DialogAnonymization.20=Best-effort, top down
DialogAnonymization.21=No algorithm has been selected
DialogAnonymization.22=No transformation type has been selected
DialogAnonymization.23=Use coding model settings
PaginationTable.0=Previous
PaginationTable.1=Next
PaginationTable.2=Items {0}-{1} of {2}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public class DialogAnonymization extends TitleAreaDialog {
private Text txtHeuristicSearchStepLimit;
/** View */
private Text textNumIterations;
/** Button */
private Button btnUseCodingModelSettings;
/** View */
private Button radioTimeLimit;
/** View */
Expand Down Expand Up @@ -185,6 +187,10 @@ private void checkAndUpdateModel() {
configuration.setNumIterations(getNumIterations());
}

// Handle parameter
configuration.setUseCodingModelSettings(this.btnUseCodingModelSettings.getSelection());

// Handle parameters
if (btnLocalTransformation.isEnabled() && btnLocalTransformation.getSelection()) {
configuration.setTransformationType(TransformationType.LOCAL);
} else if (btnGlobalTransformation.isEnabled() && btnGlobalTransformation.getSelection()) {
Expand Down Expand Up @@ -380,12 +386,12 @@ protected Control createDialogArea(Composite parent) {
GridData data3 = SWTUtil.createFillGridData();
data3.horizontalIndent = 5;
group3.setLayoutData(data3);
group3.setLayout(GridLayoutFactory.swtDefaults().numColumns(2).create());
group3.setLayout(GridLayoutFactory.swtDefaults().numColumns(3).create());

// Radio - global transformation
this.btnGlobalTransformation = new Button(group3, SWT.RADIO);
this.btnGlobalTransformation.setText(Resources.getMessage("DialogAnonymization.10")); //$NON-NLS-1$
this.btnGlobalTransformation.setLayoutData(GridDataFactory.swtDefaults().span(2, 1).create());
this.btnGlobalTransformation.setLayoutData(GridDataFactory.swtDefaults().span(3, 1).create());

// Radio - local transformation
this.btnLocalTransformation = new Button(group3, SWT.RADIO);
Expand All @@ -394,6 +400,10 @@ protected Control createDialogArea(Composite parent) {
// Tet - number iterations
this.textNumIterations = new Text(group3, SWT.BORDER);
this.textNumIterations.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());

this.btnUseCodingModelSettings = new Button(group3, SWT.CHECK);
this.btnUseCodingModelSettings.setText(Resources.getMessage("DialogAnonymization.23")); //$NON-NLS-1$
this.btnUseCodingModelSettings.setLayoutData(GridDataFactory.swtDefaults().create());

/*
* Set initial values
Expand Down Expand Up @@ -425,6 +435,7 @@ protected Control createDialogArea(Composite parent) {
case LOCAL: btnLocalTransformation.setSelection(true); break;
}
this.textNumIterations.setText(String.valueOf(configuration.getNumIterations()));
this.btnUseCodingModelSettings.setSelection(configuration.isUseCodingModelSettings());

/*
* Customize according to currently available settings
Expand All @@ -438,6 +449,7 @@ protected Control createDialogArea(Composite parent) {
this.btnGlobalTransformation.setSelection(true);
this.configuration.setTransformationType(TransformationType.GLOBAL);
this.textNumIterations.setEnabled(false);
this.btnUseCodingModelSettings.setEnabled(false);
createMessage(group3, 2, Resources.getMessage("DialogAnonymization.12")); //$NON-NLS-1$
}

Expand Down Expand Up @@ -601,6 +613,15 @@ public void modifyText(ModifyEvent arg0) {
}
});

this.btnUseCodingModelSettings.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
btnLocalTransformation.setSelection(true);
btnGlobalTransformation.setSelection(false);
checkAndUpdateModel();
}
});

// Done
applyDialogFont(base);
checkAndUpdateModel();
Expand Down
9 changes: 8 additions & 1 deletion src/gui/org/deidentifier/arx/gui/worker/WorkerAnonymize.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,14 @@ public void run(final IProgressMonitor monitor) throws InvocationTargetException
// Overwrite user-defined settings to prepare local recoding
if (transformationType == TransformationType.LOCAL) {
MetricConfiguration metricConfig = config.getQualityModel().getConfiguration();
metricConfig.setGsFactor(0d);

// Use user-defined gs factor, if configured
if (model.getAnonymizationConfiguration().isUseCodingModelSettings()) {
metricConfig.setGsFactor(model.getMetricConfiguration().getGsFactor());
// Default is 0
} else {
metricConfig.setGsFactor(0d);
}
config.setQualityModel(config.getQualityModel().getDescription().createInstance(metricConfig));
config.setSuppressionLimit(1d - (1d / (double)model.getLocalRecodingModel().getNumIterations()));
}
Expand Down

0 comments on commit 3fce38c

Please sign in to comment.