Search in sources :

Example 6 with BlockKeyDefinition

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

the class BlockingKeySection method getSelectedColumnAsBlockKeys.

/**
 * get all columns which is selected as blocking key
 *
 * @return
 */
public List<String> getSelectedColumnAsBlockKeys() {
    List<String> keyColumns = new ArrayList<String>();
    RecordMatchingIndicator recordMatchingIndicator = MatchRuleAnlaysisUtils.getRecordMatchIndicatorFromAna(analysis);
    List<BlockKeyDefinition> keyDefs = recordMatchingIndicator.getBuiltInMatchRuleDefinition().getBlockKeys();
    if (keyDefs.size() > 0) {
        for (KeyDefinition keydef : keyDefs) {
            keyColumns.add(keydef.getColumn());
        }
    }
    return keyColumns;
}
Also used : ArrayList(java.util.ArrayList) BlockKeyDefinition(org.talend.dataquality.rules.BlockKeyDefinition) RecordMatchingIndicator(org.talend.dataquality.indicators.columnset.RecordMatchingIndicator) BlockKeyDefinition(org.talend.dataquality.rules.BlockKeyDefinition) KeyDefinition(org.talend.dataquality.rules.KeyDefinition)

Example 7 with BlockKeyDefinition

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

the class BlockingKeyTableLabelProvider method getBackground.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.viewers.ITableColorProvider#getBackground(java.lang.Object, int)
     */
@Override
public Color getBackground(Object element, int columnIndex) {
    if (element instanceof BlockKeyDefinition) {
        BlockKeyDefinition bkd = (BlockKeyDefinition) element;
        boolean takeParameter = true;
        switch(columnIndex) {
            case 3:
                takeParameter = BlockingKeyPreAlgorithmEnum.getTypeBySavedValue(bkd.getPreAlgorithm().getAlgorithmType()).isTakeParameter();
                break;
            case 5:
                takeParameter = BlockingKeyAlgorithmEnum.getTypeBySavedValue(bkd.getAlgorithm().getAlgorithmType()).isTakeParameter();
                break;
            case 7:
                takeParameter = BlockingKeyPostAlgorithmEnum.getTypeBySavedValue(bkd.getPostAlgorithm().getAlgorithmType()).isTakeParameter();
                break;
        }
        return getCellColor(takeParameter);
    }
    return null;
}
Also used : BlockKeyDefinition(org.talend.dataquality.rules.BlockKeyDefinition)

Example 8 with BlockKeyDefinition

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

the class MatchRuleElementTreeSelectionDialog method getBlockingKeysFromRules.

private List<Map<String, String>> getBlockingKeysFromRules(MatchRuleDefinition matchRuleDefinition, boolean retrieveDisplayValue) {
    if (matchRuleDefinition != null) {
        List<Map<String, String>> ruleValues = new ArrayList<Map<String, String>>();
        for (BlockKeyDefinition bkDefinition : matchRuleDefinition.getBlockKeys()) {
            Map<String, String> pr = new HashMap<String, String>();
            pr.put(BlockingKeysTableLabelProvider.BLOCKING_KEY_NAME, null == bkDefinition.getName() ? StringUtils.EMPTY : bkDefinition.getName());
            String matchedColumnName = matchExistingColumnForKey(bkDefinition);
            pr.put(BlockingKeysTableLabelProvider.PRECOLUMN, null == matchedColumnName ? StringUtils.EMPTY : matchedColumnName);
            pr.put(BlockingKeysTableLabelProvider.PRE_ALGO, null == bkDefinition.getPreAlgorithm() ? StringUtils.EMPTY : bkDefinition.getPreAlgorithm().getAlgorithmType());
            pr.put(BlockingKeysTableLabelProvider.PRE_VALUE, null == bkDefinition.getPreAlgorithm() ? StringUtils.EMPTY : bkDefinition.getPreAlgorithm().getAlgorithmParameters());
            pr.put(BlockingKeysTableLabelProvider.KEY_ALGO, null == bkDefinition.getAlgorithm() ? StringUtils.EMPTY : bkDefinition.getAlgorithm().getAlgorithmType());
            pr.put(BlockingKeysTableLabelProvider.KEY_VALUE, null == bkDefinition.getAlgorithm() ? StringUtils.EMPTY : bkDefinition.getAlgorithm().getAlgorithmParameters());
            pr.put(BlockingKeysTableLabelProvider.POST_ALGO, null == bkDefinition.getPostAlgorithm() ? StringUtils.EMPTY : bkDefinition.getPostAlgorithm().getAlgorithmType());
            pr.put(BlockingKeysTableLabelProvider.POST_VALUE, null == bkDefinition.getPostAlgorithm() ? StringUtils.EMPTY : bkDefinition.getPostAlgorithm().getAlgorithmParameters());
            ruleValues.add(pr);
        }
        return ruleValues;
    }
    return null;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BlockKeyDefinition(org.talend.dataquality.rules.BlockKeyDefinition) Map(java.util.Map) HashMap(java.util.HashMap)

Example 9 with BlockKeyDefinition

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

the class BlockingKeyCellModeifier 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) {
        BlockKeyDefinition bkd = (BlockKeyDefinition) ((TableItem) element).getData();
        String newValue = String.valueOf(value);
        if (MatchAnalysisConstant.PRE_ALGO.equalsIgnoreCase(property)) {
            BlockingKeyPreAlgorithmEnum valueByIndex = BlockingKeyPreAlgorithmEnum.getTypeByIndex(Integer.valueOf(newValue).intValue());
            if (StringUtils.equals(bkd.getPreAlgorithm().getAlgorithmType(), valueByIndex.getComponentValueName())) {
                return;
            }
            bkd.getPreAlgorithm().setAlgorithmType(valueByIndex.getComponentValueName());
            bkd.getPreAlgorithm().setAlgorithmParameters(valueByIndex.getDefaultValue());
        } else if (MatchAnalysisConstant.PRE_VALUE.equalsIgnoreCase(property)) {
            if (StringUtils.equals(bkd.getPreAlgorithm().getAlgorithmParameters(), newValue)) {
                return;
            }
            BlockingKeyPreAlgorithmEnum valueBySavedValue = BlockingKeyPreAlgorithmEnum.getTypeBySavedValue(bkd.getPreAlgorithm().getAlgorithmType());
            if (isParameterInValid(valueBySavedValue.getDefaultValue(), newValue)) {
                return;
            }
            bkd.getPreAlgorithm().setAlgorithmParameters(String.valueOf(value));
        } else if (MatchAnalysisConstant.KEY_ALGO.equalsIgnoreCase(property)) {
            BlockingKeyAlgorithmEnum valueByIndex = BlockingKeyAlgorithmEnum.getTypeByIndex(Integer.valueOf(newValue).intValue());
            if (StringUtils.equals(bkd.getAlgorithm().getAlgorithmType(), valueByIndex.getComponentValueName())) {
                return;
            }
            bkd.getAlgorithm().setAlgorithmType(valueByIndex.getComponentValueName());
            bkd.getAlgorithm().setAlgorithmParameters(valueByIndex.getDefaultValue());
        } else if (MatchAnalysisConstant.KEY_VALUE.equalsIgnoreCase(property)) {
            if (StringUtils.equals(bkd.getAlgorithm().getAlgorithmParameters(), newValue)) {
                return;
            }
            BlockingKeyAlgorithmEnum valueBySavedValue = BlockingKeyAlgorithmEnum.getTypeBySavedValue(bkd.getAlgorithm().getAlgorithmType());
            if (isParameterInValid(valueBySavedValue.getDefaultValue(), newValue)) {
                return;
            }
            bkd.getAlgorithm().setAlgorithmParameters(newValue);
        } else if (MatchAnalysisConstant.POST_ALGO.equalsIgnoreCase(property)) {
            BlockingKeyPostAlgorithmEnum valueByIndex = BlockingKeyPostAlgorithmEnum.getTypeByIndex(Integer.valueOf(newValue).intValue());
            if (StringUtils.equals(bkd.getPostAlgorithm().getAlgorithmType(), valueByIndex.getComponentValueName())) {
                return;
            }
            bkd.getPostAlgorithm().setAlgorithmType(valueByIndex.getComponentValueName());
            bkd.getPostAlgorithm().setAlgorithmParameters(valueByIndex.getDefaultValue());
        } else if (MatchAnalysisConstant.POST_VALUE.equalsIgnoreCase(property)) {
            if (StringUtils.equals(bkd.getPostAlgorithm().getAlgorithmParameters(), newValue)) {
                return;
            }
            BlockingKeyPostAlgorithmEnum valueBySavedValue = BlockingKeyPostAlgorithmEnum.getTypeBySavedValue(bkd.getPostAlgorithm().getAlgorithmType());
            if (isParameterInValid(valueBySavedValue.getDefaultValue(), newValue)) {
                return;
            }
            bkd.getPostAlgorithm().setAlgorithmParameters(newValue);
        } else if (MatchAnalysisConstant.PRECOLUMN.equalsIgnoreCase(property)) {
            if (Integer.parseInt(newValue) == -1) {
                return;
            }
            String columnName = columnList.get(Integer.parseInt(newValue)).getName();
            if (StringUtils.equals(bkd.getColumn(), columnName)) {
                return;
            }
            bkd.setColumn(columnName);
            tableViewer.noticeColumnSelectChange();
        } else if (MatchAnalysisConstant.BLOCKING_KEY_NAME.equalsIgnoreCase(property)) {
            if (StringUtils.equals(bkd.getName(), newValue)) {
                return;
            }
            bkd.setName(newValue);
        } else {
            return;
        }
        tableViewer.update(bkd, null);
    }
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) BlockKeyDefinition(org.talend.dataquality.rules.BlockKeyDefinition) BlockingKeyPreAlgorithmEnum(org.talend.dataquality.record.linkage.utils.BlockingKeyPreAlgorithmEnum) BlockingKeyPostAlgorithmEnum(org.talend.dataquality.record.linkage.utils.BlockingKeyPostAlgorithmEnum) BlockingKeyAlgorithmEnum(org.talend.dataquality.record.linkage.utils.BlockingKeyAlgorithmEnum)

Example 10 with BlockKeyDefinition

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

the class MatchAnalysisExecutorTest method assertScenario4.

/**
 * DOC zhao Comment method "assertScenario3".
 *
 * @param matchAnalysisExecutor
 * @param analysis
 * @param name
 * @param nameVar
 */
@SuppressWarnings("nls")
private void assertScenario4(MatchAnalysisExecutor matchAnalysisExecutor, Analysis analysis, MetadataColumn name, String nameVar, double groupQualityThreshold, double matchInterval) {
    // Set indicators into analysis result.
    RecordMatchingIndicator matchIndicator = ColumnsetPackage.eINSTANCE.getColumnsetFactory().createRecordMatchingIndicator();
    // Match key: name, no block key, levenshtein attribute algorithm.
    matchIndicator.setAnalyzedElement(name);
    createMatchIndicatorWithOneMathRule(nameVar, matchIndicator, groupQualityThreshold, matchInterval);
    // Add a blocking key: country
    BlockKeyDefinition blockKeyDef = RulesPackage.eINSTANCE.getRulesFactory().createBlockKeyDefinition();
    AlgorithmDefinition algoDef = RulesPackage.eINSTANCE.getRulesFactory().createAlgorithmDefinition();
    algoDef.setAlgorithmType(AttributeMatcherType.EXACT.name());
    blockKeyDef.setAlgorithm(algoDef);
    blockKeyDef.setColumn("country");
    blockKeyDef.setName("country");
    AlgorithmDefinition dummyAlgoPre = RulesPackage.eINSTANCE.getRulesFactory().createAlgorithmDefinition();
    dummyAlgoPre.setAlgorithmType(BlockingKeyPreAlgorithmEnum.NON_ALGO.getComponentValueName());
    blockKeyDef.setPreAlgorithm(dummyAlgoPre);
    AlgorithmDefinition dummyAlgoPost = RulesPackage.eINSTANCE.getRulesFactory().createAlgorithmDefinition();
    dummyAlgoPost.setAlgorithmType(BlockingKeyPreAlgorithmEnum.NON_ALGO.getComponentValueName());
    blockKeyDef.setPostAlgorithm(dummyAlgoPost);
    matchIndicator.getBuiltInMatchRuleDefinition().getBlockKeys().add(blockKeyDef);
    executeAnalysis(matchAnalysisExecutor, analysis, matchIndicator);
    // Assert group size and frequency.
    Map<Object, Long> size2Frequency = matchIndicator.getGroupSize2groupFrequency();
    // For 1 -> FR(4)"babass","SebastiĆ£o","nicolas","nigula"
    assertTrue(size2Frequency.get(String.valueOf(1)) == 6l);
    // CN(2)"nigula","nico"
    // For 2 -> FR(1)"sebas", CN(1)"nicolas"("nicola")
    assertTrue(size2Frequency.get(String.valueOf(2)) == 2l);
    // For 4 -> FR(4)"seb"
    assertTrue(size2Frequency.get(String.valueOf(4)) == 1l);
    // Assert row count, unique records, matched records and suspect records.
    assertTrue(matchIndicator.getCount() == 14);
    // For 6 -> FR 4*"seb", FR 2 *"sebas"
    assertTrue(matchIndicator.getMatchedRecordCount() == 6);
    // For 2 -> CN "nicolas"("nicola"), group score: 0.9 <
    assertTrue(matchIndicator.getSuspectRecordCount() == 2);
// 0.95
}
Also used : BlockKeyDefinition(org.talend.dataquality.rules.BlockKeyDefinition) AlgorithmDefinition(org.talend.dataquality.rules.AlgorithmDefinition) RecordMatchingIndicator(org.talend.dataquality.indicators.columnset.RecordMatchingIndicator)

Aggregations

BlockKeyDefinition (org.talend.dataquality.rules.BlockKeyDefinition)21 ArrayList (java.util.ArrayList)11 RecordMatchingIndicator (org.talend.dataquality.indicators.columnset.RecordMatchingIndicator)7 HashMap (java.util.HashMap)6 MatchKeyDefinition (org.talend.dataquality.rules.MatchKeyDefinition)6 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)5 AlgorithmDefinition (org.talend.dataquality.rules.AlgorithmDefinition)5 MatchRule (org.talend.dataquality.rules.MatchRule)5 KeyDefinition (org.talend.dataquality.rules.KeyDefinition)4 MatchRuleDefinition (org.talend.dataquality.rules.MatchRuleDefinition)4 Map (java.util.Map)3 ISelection (org.eclipse.jface.viewers.ISelection)3 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)3 Test (org.junit.Test)3 BlockKeyIndicator (org.talend.dataquality.indicators.columnset.BlockKeyIndicator)3 MatchGroupResultConsumer (org.talend.dataquality.record.linkage.grouping.MatchGroupResultConsumer)3 ExecuteMatchRuleHandler (org.talend.dq.analysis.match.ExecuteMatchRuleHandler)3 AppliedBlockKey (org.talend.dataquality.rules.AppliedBlockKey)2 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1