/// <summary> /// Applies given criterion action to rows satisfying given criterion /// </summary> public void ApplyFilterAction(AbstractLocalizationCriterion crit, LocalizationCriterionAction2 act) { if (crit == null) { throw new ArgumentNullException("crit"); } List <DataGridViewRow> toBeDeletedRows = new List <DataGridViewRow>(); // list of rows to be deleted foreach (DataGridViewKeyValueRow <CodeStringResultItem> row in Rows) { bool oldCheckValue = (bool)row.Cells[CheckBoxColumnName].Value; bool newCheckValue = oldCheckValue; var evalResult = crit.Eval(row.DataSourceItem); // criterion evaluation result if (evalResult == true) // row satisfies the criterion { if (act == LocalizationCriterionAction2.CHECK || act == LocalizationCriterionAction2.CHECK_REMOVE) // check the row { row.Cells[CheckBoxColumnName].Tag = row.Cells[CheckBoxColumnName].Value = true; newCheckValue = true; } else if (act == LocalizationCriterionAction2.UNCHECK) { row.Cells[CheckBoxColumnName].Tag = row.Cells[CheckBoxColumnName].Value = false; // uncheck the row newCheckValue = false; } else if (act == LocalizationCriterionAction2.REMOVE) { row.Cells[CheckBoxColumnName].Tag = row.Cells[CheckBoxColumnName].Value = false; toBeDeletedRows.Add(row); // add row to the list of rows to be deleted newCheckValue = false; } } else if (!oldCheckValue && evalResult == false && act == LocalizationCriterionAction2.CHECK_REMOVE) { toBeDeletedRows.Add(row); newCheckValue = false; } ChangeRowCheckState(row, oldCheckValue, newCheckValue); // change row check state } foreach (DataGridViewKeyValueRow <CodeStringResultItem> row in toBeDeletedRows) { ConflictResolver.TryAdd(row.Key, null, row); // remove the row from conflict resolver row.Cells[KeyColumnName].Tag = null; row.ErrorText = null; Rows.Remove(row); removedRows.Add(row); // add to the list of remebered rows } UpdateCheckHeader(); }
/// <summary> /// Calculates localization probability from given criteria /// </summary> public int GetLocalizationProbability(Dictionary <string, AbstractLocalizationCriterion> criteria) { bool disableRequest = false; float sum = 0; foreach (var pair in criteria) { AbstractLocalizationCriterion crit = pair.Value; bool?result = crit.Eval(this); if (result.HasValue && result.Value) { switch (crit.Action) { case LocalizationCriterionAction.FORCE_ENABLE: return(AbstractLocalizationCriterion.MAX_LOC_PROBABILITY); case LocalizationCriterionAction.FORCE_DISABLE: disableRequest = true; break; case LocalizationCriterionAction.VALUE: sum += crit.Weight; break; case LocalizationCriterionAction.IGNORE: break; } } } if (disableRequest) { return(0); } double half = AbstractLocalizationCriterion.MAX_LOC_PROBABILITY / 2.0; int x = (int)(half + Math.Atan(sum / half) * AbstractLocalizationCriterion.MAX_LOC_PROBABILITY / Math.PI); if (x >= 0 && x <= AbstractLocalizationCriterion.MAX_LOC_PROBABILITY) { return(x); } else { return(x < 0 ? 0 : AbstractLocalizationCriterion.MAX_LOC_PROBABILITY); } }