Search in sources :

Example 16 with MatchKeyDefinition

use of org.talend.dataquality.rules.MatchKeyDefinition in project tdq-studio-se by Talend.

the class MatchRuleAnlaysisUtils method createDefaultMatchRow.

/**
 * DOC zshen Comment method "createDefaultRow".
 *
 * @param columnName
 * @return
 */
public static MatchKeyDefinition createDefaultMatchRow(String columnName) {
    MatchKeyDefinition createMatchKeyDefinition1 = RulesFactory.eINSTANCE.createMatchKeyDefinition();
    AlgorithmDefinition createAlgorithmDefinition1 = RulesFactory.eINSTANCE.createAlgorithmDefinition();
    // by default the name of the match attribute rule is the name of the selected column
    createMatchKeyDefinition1.setName(columnName);
    createMatchKeyDefinition1.setColumn(columnName);
    createMatchKeyDefinition1.setConfidenceWeight(1);
    createMatchKeyDefinition1.setHandleNull(HandleNullEnum.NULL_MATCH_NULL.getValue());
    createMatchKeyDefinition1.setTokenizationType(TokenizedResolutionMethod.NO.getComponentValue());
    createAlgorithmDefinition1.setAlgorithmParameters(StringUtils.EMPTY);
    createAlgorithmDefinition1.setAlgorithmType(AttributeMatcherType.values()[0].name());
    createMatchKeyDefinition1.setAlgorithm(createAlgorithmDefinition1);
    createMatchKeyDefinition1.setThreshold(1.0);
    return createMatchKeyDefinition1;
}
Also used : MatchKeyDefinition(org.talend.dataquality.rules.MatchKeyDefinition) AlgorithmDefinition(org.talend.dataquality.rules.AlgorithmDefinition)

Example 17 with MatchKeyDefinition

use of org.talend.dataquality.rules.MatchKeyDefinition in project tdq-studio-se by Talend.

the class MatchRuleAnlaysisUtils method convertDataMapToRuleMatcher.

public static List<MatchRule> convertDataMapToRuleMatcher(Map<String, String> columnMap) {
    List<MatchRule> matcherList = new ArrayList<MatchRule>();
    if (columnMap == null) {
        return matcherList;
    }
    MatchRule createRuleMatcher = RulesFactory.eINSTANCE.createMatchRule();
    for (String columnName : columnMap.keySet()) {
        MatchKeyDefinition createDefaultMatchRow = createDefaultMatchRow(columnName);
        createRuleMatcher.getMatchKeys().add(createDefaultMatchRow);
    }
    matcherList.add(createRuleMatcher);
    return matcherList;
}
Also used : ArrayList(java.util.ArrayList) MatchKeyDefinition(org.talend.dataquality.rules.MatchKeyDefinition) MatchRule(org.talend.dataquality.rules.MatchRule)

Example 18 with MatchKeyDefinition

use of org.talend.dataquality.rules.MatchKeyDefinition in project tdq-studio-se by Talend.

the class MatchAndSurvivorCellModifer method modify.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.viewers.ICellModifier#modify(java.lang.Object, java.lang.String, java.lang.Object)
     */
@Override
public void modify(Object element, String property, Object value) {
    if (element instanceof TableItem) {
        MatchKeyAndSurvivorDefinition mkd = (MatchKeyAndSurvivorDefinition) ((TableItem) element).getData();
        String newValue = String.valueOf(value);
        MatchKeyDefinition matchKey = mkd.getMatchKey();
        if (MatchAnalysisConstant.HANDLE_NULL.equalsIgnoreCase(property)) {
            HandleNullEnum valueByIndex = HandleNullEnum.values()[Integer.valueOf(newValue)];
            if (StringUtils.equals(matchKey.getHandleNull(), valueByIndex.getValue())) {
                return;
            }
            matchKey.setHandleNull(valueByIndex.getValue());
        } else if (MatchAnalysisConstant.MATCHING_TYPE.equalsIgnoreCase(property)) {
            int idx = Integer.valueOf(newValue);
            if (idx == AttributeMatcherType.DUMMY.ordinal()) {
                // The DUMMY algorithm is internal and does not exist in the combo lists of
                idx += 1;
            // MatchRuleItemEditor or MatchRuleAnalysisEditor. So we increment the index by 1 in order
            // to get the correct Matcher.
            }
            AttributeMatcherType valueByIndex = AttributeMatcherType.values()[idx];
            if (StringUtils.equals(matchKey.getAlgorithm().getAlgorithmType(), valueByIndex.name())) {
                return;
            }
            matchKey.getAlgorithm().setAlgorithmType(valueByIndex.name());
            matchKey.getAlgorithm().setAlgorithmParameters(StringUtils.EMPTY);
            if (isMatcherType(mkd, AttributeMatcherType.EXACT)) {
                matchKey.setThreshold(1.0d);
            }
        } else if (MatchAnalysisConstant.CUSTOM_MATCHER.equalsIgnoreCase(property)) {
            if (StringUtils.equals(matchKey.getAlgorithm().getAlgorithmParameters(), newValue)) {
                return;
            }
            matchKey.getAlgorithm().setAlgorithmParameters(String.valueOf(value));
        } else if (MatchAnalysisConstant.CONFIDENCE_WEIGHT.equalsIgnoreCase(property)) {
            if (!org.apache.commons.lang.math.NumberUtils.isDigits(newValue)) {
                return;
            }
            if (matchKey.getConfidenceWeight() == Integer.valueOf(newValue).intValue()) {
                return;
            }
            matchKey.setConfidenceWeight(Integer.valueOf(newValue).intValue());
        } else if (MatchAnalysisConstant.MATCH_KEY_NAME.equalsIgnoreCase(property)) {
            if (StringUtils.equals(matchKey.getName(), newValue)) {
                return;
            }
            matchKey.setName(newValue);
            mkd.getSurvivorShipKey().setName(newValue);
        } else if (MatchAnalysisConstant.INPUT_COLUMN.equalsIgnoreCase(property)) {
            int idx = Integer.valueOf(newValue);
            if (columnList == null || columnList.isEmpty()) {
                return;
            }
            MetadataColumn metaColumn = columnList.get(idx);
            if (metaColumn == null) {
                return;
            }
            if (StringUtils.equals(metaColumn.getName(), newValue)) {
                return;
            }
            matchKey.setColumn(metaColumn.getName());
            mkd.getSurvivorShipKey().setColumn(metaColumn.getName());
            // added TDQ-9296, nodify the change to let the upper layer know this
            tableViewer.noticeColumnSelectChange();
        } else if (MatchAnalysisConstant.THRESHOLD.equalsIgnoreCase(property)) {
            if (!org.apache.commons.lang.math.NumberUtils.isNumber(newValue)) {
                return;
            }
            if (matchKey.getThreshold() == Double.parseDouble(newValue)) {
                return;
            }
            try {
                matchKey.setThreshold(Double.parseDouble(newValue));
            } catch (NumberFormatException e) {
            // revert user change at here so don't need do anything
            }
        } else if (MatchAnalysisConstant.FUNCTION.equalsIgnoreCase(property)) {
            SurvivorShipAlgorithmEnum valueByIndex = SurvivorShipAlgorithmEnum.getTypeByIndex(Integer.valueOf(newValue).intValue());
            if (StringUtils.equals(mkd.getSurvivorShipKey().getFunction().getAlgorithmType(), valueByIndex.getComponentValueName())) {
                return;
            }
            mkd.getSurvivorShipKey().getFunction().setAlgorithmType(valueByIndex.getComponentValueName());
            if (!(isSurvivorShipAlgorithm(mkd, SurvivorShipAlgorithmEnum.MOST_TRUSTED_SOURCE) | (isSurvivorShipAlgorithm(mkd, SurvivorShipAlgorithmEnum.CONCATENATE)))) {
                mkd.getSurvivorShipKey().getFunction().setAlgorithmParameters(StringUtils.EMPTY);
            // MOD mzhao 2014-7-22 there will be an exception here, when switching the surv functions. Confirmed
            // with haibo (MDM team), removed this code.
            // CellEditor[] cellEditors = tableViewer.getCellEditors();
            // if (cellEditors.length == 9) {
            // cellEditors[7].setValue(StringUtils.EMPTY);
            // }
            }
        } else if (MatchAnalysisConstant.PARAMETER.equalsIgnoreCase(property)) {
            mkd.getSurvivorShipKey().getFunction().setAlgorithmParameters(newValue);
        } else if (MatchAnalysisConstant.TOKENIZATION_TYPE.equalsIgnoreCase(property)) {
            TokenizedResolutionMethod valueByIndex = TokenizedResolutionMethod.values()[Integer.valueOf(newValue)];
            if (StringUtils.equals(mkd.getMatchKey().getTokenizationType(), valueByIndex.getComponentValue())) {
                return;
            }
            mkd.getMatchKey().setTokenizationType(valueByIndex.getComponentValue());
        } else {
            return;
        }
        tableViewer.update(mkd, null);
    }
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) AttributeMatcherType(org.talend.dataquality.record.linkage.constant.AttributeMatcherType) TokenizedResolutionMethod(org.talend.dataquality.record.linkage.constant.TokenizedResolutionMethod) TableItem(org.eclipse.swt.widgets.TableItem) MatchKeyDefinition(org.talend.dataquality.rules.MatchKeyDefinition) SurvivorShipAlgorithmEnum(org.talend.dataquality.record.linkage.utils.SurvivorShipAlgorithmEnum) MatchKeyAndSurvivorDefinition(org.talend.dataquality.record.linkage.ui.composite.tableviewer.definition.MatchKeyAndSurvivorDefinition) HandleNullEnum(org.talend.dataquality.record.linkage.utils.HandleNullEnum)

Example 19 with MatchKeyDefinition

use of org.talend.dataquality.rules.MatchKeyDefinition in project tdq-studio-se by Talend.

the class MatchRuleElementTreeSelectionDialog method getMatchRulesFromRules.

private List<Map<String, String>> getMatchRulesFromRules(MatchRuleDefinition matchRuleDefinition, boolean retrieveDisplayValue) {
    if (matchRuleDefinition != null) {
        List<Map<String, String>> ruleValues = new ArrayList<Map<String, String>>();
        for (MatchRule matchRule : matchRuleDefinition.getMatchRules()) {
            for (MatchKeyDefinition matchKey : matchRule.getMatchKeys()) {
                Map<String, String> pr = new HashMap<String, String>();
                pr.put(MatchRulesTableLabelProvider.MATCH_KEY_NAME, null == matchKey.getName() ? StringUtils.EMPTY : matchKey.getName());
                String matchedColumnName = matchExistingColumnForKey(matchKey);
                pr.put(MatchRulesTableLabelProvider.INPUT_COLUMN, null == matchedColumnName ? StringUtils.EMPTY : matchedColumnName);
                if (getLookupColumnNames().size() > 0) {
                    for (String lookupColumnName : getLookupColumnNames()) {
                        if (isColumnNameEqualsWithKey(matchKey, lookupColumnName)) {
                            // $NON-NLS-1$
                            pr.put("LOOKUP_COLUMN", null == matchKey.getColumn() ? StringUtils.EMPTY : lookupColumnName);
                            break;
                        }
                    }
                }
                String algorithmType = matchKey.getAlgorithm().getAlgorithmType();
                if (retrieveDisplayValue) {
                    pr.put(MatchRulesTableLabelProvider.MATCHING_TYPE, null == algorithmType ? StringUtils.EMPTY : AttributeMatcherType.valueOf(algorithmType).getLabel());
                } else {
                    pr.put(MatchRulesTableLabelProvider.MATCHING_TYPE, null == algorithmType ? StringUtils.EMPTY : AttributeMatcherType.valueOf(algorithmType).getComponentValue());
                }
                // MOD sizhaoliu TDQ-8431 split the value by "||" and take the second part as custom class value
                String algoParams = matchKey.getAlgorithm().getAlgorithmParameters();
                if (algoParams != null) {
                    // $NON-NLS-1$
                    int idxSeparator = algoParams.indexOf("||");
                    if (idxSeparator > 0 && algoParams.length() > idxSeparator + 2) {
                        // $NON-NLS-1$ //$NON-NLS-2$
                        algoParams = "\"" + algoParams.substring(idxSeparator + 2) + "\"";
                    }
                }
                pr.put(MatchRulesTableLabelProvider.CUSTOM_MATCHER, null == algoParams ? StringUtils.EMPTY : algoParams);
                pr.put(MatchRulesTableLabelProvider.CONFIDENCE_WEIGHT, String.valueOf(matchKey.getConfidenceWeight()));
                if (retrieveDisplayValue) {
                    pr.put(MatchRulesTableLabelProvider.HANDLE_NULL, null == matchKey.getHandleNull() ? StringUtils.EMPTY : HandleNullEnum.getTypeByValue(matchKey.getHandleNull()).getLabel());
                } else {
                    pr.put(MatchRulesTableLabelProvider.HANDLE_NULL, null == matchKey.getHandleNull() ? StringUtils.EMPTY : matchKey.getHandleNull());
                }
                // set threshold
                pr.put(MatchRulesTableLabelProvider.THRESHOLD, String.valueOf(matchKey.getThreshold()));
                pr.put(MatchRulesTableLabelProvider.TOKENIZATION_TYPE, String.valueOf(matchKey.getTokenizationType()));
                // set survivorship function and parameter
                AlgorithmDefinition algorithmDefinition = getSurvivorshipFunctionAlgorithm(matchKey, matchRuleDefinition);
                pr.put(MatchRulesTableLabelProvider.SURVIVORSHIP_FUNCTION, algorithmDefinition != null && algorithmDefinition.getAlgorithmType() != null ? algorithmDefinition.getAlgorithmType() : StringUtils.EMPTY);
                pr.put(MatchRulesTableLabelProvider.PARAMETER, algorithmDefinition != null && algorithmDefinition.getAlgorithmParameters() != null ? algorithmDefinition.getAlgorithmParameters() : StringUtils.EMPTY);
                ruleValues.add(pr);
            }
        }
        return ruleValues;
    }
    return null;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MatchKeyDefinition(org.talend.dataquality.rules.MatchKeyDefinition) AlgorithmDefinition(org.talend.dataquality.rules.AlgorithmDefinition) MatchRule(org.talend.dataquality.rules.MatchRule) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

MatchKeyDefinition (org.talend.dataquality.rules.MatchKeyDefinition)19 MatchRule (org.talend.dataquality.rules.MatchRule)12 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)7 AlgorithmDefinition (org.talend.dataquality.rules.AlgorithmDefinition)7 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)6 MatchRuleDefinition (org.talend.dataquality.rules.MatchRuleDefinition)6 RecordMatchingIndicator (org.talend.dataquality.indicators.columnset.RecordMatchingIndicator)5 Test (org.junit.Test)4 BlockKeyIndicator (org.talend.dataquality.indicators.columnset.BlockKeyIndicator)4 MatchGroupResultConsumer (org.talend.dataquality.record.linkage.grouping.MatchGroupResultConsumer)4 BlockKeyDefinition (org.talend.dataquality.rules.BlockKeyDefinition)4 ExecuteMatchRuleHandler (org.talend.dq.analysis.match.ExecuteMatchRuleHandler)4 Map (java.util.Map)2 TableItem (org.eclipse.swt.widgets.TableItem)2 AttributeMatcherType (org.talend.dataquality.record.linkage.constant.AttributeMatcherType)2 TokenizedResolutionMethod (org.talend.dataquality.record.linkage.constant.TokenizedResolutionMethod)2 MatchKeyAndSurvivorDefinition (org.talend.dataquality.record.linkage.ui.composite.tableviewer.definition.MatchKeyAndSurvivorDefinition)2 HandleNullEnum (org.talend.dataquality.record.linkage.utils.HandleNullEnum)2 SurvivorshipKeyDefinition (org.talend.dataquality.rules.SurvivorshipKeyDefinition)2