Search in sources :

Example 1 with ParticularDefaultSurvivorshipDefinitions

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

the class AnalysisRecordGroupingUtilsTest method testCreateSurvivorShipAlgorithmParams.

/**
 * Test method for
 * {@link org.talend.dq.analysis.AnalysisRecordGroupingUtils#createSurvivorShipAlgorithmParams(org.talend.dataquality.record.linkage.grouping.AnalysisMatchRecordGrouping, org.talend.dataquality.indicators.columnset.RecordMatchingIndicator, Map)
 * .
 */
@Test
public void testCreateSurvivorShipAlgorithmParams() {
    // Survivorshipkey
    RecordMatchingIndicator recordMatchingIndicator = ColumnsetFactory.eINSTANCE.createRecordMatchingIndicator();
    MatchRuleDefinition createMatchRuleDefinition = RulesFactory.eINSTANCE.createMatchRuleDefinition();
    recordMatchingIndicator.setBuiltInMatchRuleDefinition(createMatchRuleDefinition);
    EList<SurvivorshipKeyDefinition> survivorshipKeys = createMatchRuleDefinition.getSurvivorshipKeys();
    AlgorithmDefinition createAlgorithmDefinition = RulesFactory.eINSTANCE.createAlgorithmDefinition();
    // $NON-NLS-1$
    createAlgorithmDefinition.setAlgorithmParameters("");
    // $NON-NLS-1$
    createAlgorithmDefinition.setAlgorithmType("Longest");
    // $NON-NLS-1$
    survivorshipKeys.add(createKeyDefinition("a1", createAlgorithmDefinition));
    createAlgorithmDefinition = RulesFactory.eINSTANCE.createAlgorithmDefinition();
    // $NON-NLS-1$
    createAlgorithmDefinition.setAlgorithmParameters("");
    // $NON-NLS-1$
    createAlgorithmDefinition.setAlgorithmType("Longest");
    // $NON-NLS-1$
    survivorshipKeys.add(createKeyDefinition("a2", createAlgorithmDefinition));
    // DefaultSurvivorship
    EList<DefaultSurvivorshipDefinition> defaultSurvivorshipDefinitions = createMatchRuleDefinition.getDefaultSurvivorshipDefinitions();
    createAlgorithmDefinition = RulesFactory.eINSTANCE.createAlgorithmDefinition();
    // $NON-NLS-1$
    createAlgorithmDefinition.setAlgorithmParameters("");
    // $NON-NLS-1$
    createAlgorithmDefinition.setAlgorithmType("MostCommon");
    // $NON-NLS-1$
    defaultSurvivorshipDefinitions.add(createDefaultsurvivShip("String", createAlgorithmDefinition));
    // DefaultSurvivorship
    EList<ParticularDefaultSurvivorshipDefinitions> particularDefaultSurvivorshipDefinitions = createMatchRuleDefinition.getParticularDefaultSurvivorshipDefinitions();
    createAlgorithmDefinition = RulesFactory.eINSTANCE.createAlgorithmDefinition();
    // $NON-NLS-1$
    createAlgorithmDefinition.setAlgorithmParameters("");
    // $NON-NLS-1$
    createAlgorithmDefinition.setAlgorithmType("Concatenate");
    particularDefaultSurvivorshipDefinitions.add(createParticularDefaultSurvivorshipDefinitions("a2", // $NON-NLS-1$
    createAlgorithmDefinition));
    // init columnMap
    Map<MetadataColumn, String> columnMap = new HashMap<MetadataColumn, String>();
    MetadataColumn col0 = ConnectionFactory.eINSTANCE.createMetadataColumn();
    // $NON-NLS-1$
    col0.setName("a1");
    // $NON-NLS-1$
    col0.setTalendType("id_String");
    // $NON-NLS-1$
    columnMap.put(col0, "0");
    MetadataColumn col1 = ConnectionFactory.eINSTANCE.createMetadataColumn();
    // $NON-NLS-1$
    col1.setTalendType("id_String");
    // $NON-NLS-1$
    col1.setName("a2");
    // $NON-NLS-1$
    columnMap.put(col1, "1");
    MetadataColumn col2 = ConnectionFactory.eINSTANCE.createMetadataColumn();
    // $NON-NLS-1$
    col2.setTalendType("id_String");
    // $NON-NLS-1$
    col2.setName("a3");
    // $NON-NLS-1$
    columnMap.put(col2, "2");
    MatchGroupResultConsumer matchGroupResultConsumer = new MatchGroupResultConsumer(true) {

        @Override
        public void handle(Object row) {
        // no need to implement
        }
    };
    AnalysisMatchRecordGrouping analysisMatchRecordGrouping = new AnalysisMatchRecordGrouping(matchGroupResultConsumer);
    CombinedRecordMatcher combinedRecordMatcher = analysisMatchRecordGrouping.getCombinedRecordMatcher();
    DQMFBRecordMatcher dqmfbRecordMatcher = new DQMFBRecordMatcher(0.9);
    combinedRecordMatcher.getMatchers().add(dqmfbRecordMatcher);
    List<List<Map<String, String>>> multiMatchRules = analysisMatchRecordGrouping.getMultiMatchRules();
    List<Map<String, String>> matchRuleList = new ArrayList<Map<String, String>>();
    Map<String, String> matchKeyMap1 = new HashMap<String, String>();
    Map<String, String> matchKeyMap2 = new HashMap<String, String>();
    Map<String, String> matchKeyMap3 = new HashMap<String, String>();
    matchKeyMap1.put(IRecordGrouping.MATCHING_TYPE, AttributeMatcherType.EXACT.name());
    // change by
    matchKeyMap2.put(IRecordGrouping.MATCHING_TYPE, AttributeMatcherType.DUMMY.name());
    // DefaultSurvivorshipDefinitions
    // change by
    matchKeyMap3.put(IRecordGrouping.MATCHING_TYPE, AttributeMatcherType.DUMMY.name());
    // ParticularDefaultSurvivorshipDefinitions
    matchRuleList.add(matchKeyMap1);
    matchRuleList.add(matchKeyMap2);
    matchRuleList.add(matchKeyMap3);
    // $NON-NLS-1$
    matchKeyMap1.put(IRecordGrouping.MATCH_KEY_NAME, "a1");
    // $NON-NLS-1$
    matchKeyMap2.put(IRecordGrouping.MATCH_KEY_NAME, "a2");
    // $NON-NLS-1$
    matchKeyMap3.put(IRecordGrouping.MATCH_KEY_NAME, "a3");
    // $NON-NLS-1$
    matchKeyMap1.put(IRecordGrouping.COLUMN_IDX, "0");
    // $NON-NLS-1$
    matchKeyMap2.put(IRecordGrouping.COLUMN_IDX, "1");
    // $NON-NLS-1$
    matchKeyMap3.put(IRecordGrouping.COLUMN_IDX, "2");
    multiMatchRules.add(matchRuleList);
    SurvivorShipAlgorithmParams createSurvivorShipAlgorithmParams = AnalysisRecordGroupingUtils.createSurvivorShipAlgorithmParams(analysisMatchRecordGrouping, recordMatchingIndicator, columnMap);
    // $NON-NLS-1$
    Assert.assertEquals(// $NON-NLS-1$
    "The size of SurvivorShipAlgos should be 2", // $NON-NLS-1$
    2, createSurvivorShipAlgorithmParams.getSurviorShipAlgos().length);
    // the size of default survivorshipRules is come from by (column size * default item size)
    Assert.assertEquals("The size of DefaultSurviorshipRules should be 3", 3, // $NON-NLS-1$
    createSurvivorShipAlgorithmParams.getDefaultSurviorshipRules().size());
    Map<IRecordMatcher, SurvivorshipFunction[]> survivorshipAlgosMap = createSurvivorShipAlgorithmParams.getSurvivorshipAlgosMap();
    // $NON-NLS-1$
    Assert.assertEquals("The size of survivorshipAlgosMap should be 1", 1, survivorshipAlgosMap.size());
    SurvivorshipFunction[] survivorshipFunctions = survivorshipAlgosMap.get(dqmfbRecordMatcher);
    // $NON-NLS-1$
    Assert.assertEquals("The size of survivorshipFunctions should be 3", 3, survivorshipFunctions.length);
    // $NON-NLS-1$
    Assert.assertEquals(// $NON-NLS-1$
    "The Algorithm of a1 function should be LONGEST", // $NON-NLS-1$
    SurvivorShipAlgorithmEnum.LONGEST, survivorshipFunctions[0].getSurvivorShipAlgoEnum());
    // $NON-NLS-1$
    Assert.assertEquals(// $NON-NLS-1$
    "The Algorithm of a2 function should be Concatenate", // $NON-NLS-1$
    SurvivorShipAlgorithmEnum.CONCATENATE, survivorshipFunctions[1].getSurvivorShipAlgoEnum());
    // $NON-NLS-1$
    Assert.assertEquals(// $NON-NLS-1$
    "The Algorithm of a3 function should be MostCommon", // $NON-NLS-1$
    SurvivorShipAlgorithmEnum.MOST_COMMON, survivorshipFunctions[2].getSurvivorShipAlgoEnum());
}
Also used : AnalysisMatchRecordGrouping(org.talend.dataquality.record.linkage.grouping.AnalysisMatchRecordGrouping) IRecordMatcher(org.talend.dataquality.record.linkage.record.IRecordMatcher) HashMap(java.util.HashMap) DefaultSurvivorshipDefinition(org.talend.dataquality.rules.DefaultSurvivorshipDefinition) SurvivorShipAlgorithmParams(org.talend.dataquality.record.linkage.grouping.swoosh.SurvivorShipAlgorithmParams) ArrayList(java.util.ArrayList) MatchRuleDefinition(org.talend.dataquality.rules.MatchRuleDefinition) DQMFBRecordMatcher(org.talend.dataquality.record.linkage.grouping.swoosh.DQMFBRecordMatcher) SurvivorshipFunction(org.talend.dataquality.record.linkage.grouping.swoosh.SurvivorShipAlgorithmParams.SurvivorshipFunction) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) AlgorithmDefinition(org.talend.dataquality.rules.AlgorithmDefinition) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) List(java.util.List) ParticularDefaultSurvivorshipDefinitions(org.talend.dataquality.rules.ParticularDefaultSurvivorshipDefinitions) SurvivorshipKeyDefinition(org.talend.dataquality.rules.SurvivorshipKeyDefinition) RecordMatchingIndicator(org.talend.dataquality.indicators.columnset.RecordMatchingIndicator) MatchGroupResultConsumer(org.talend.dataquality.record.linkage.grouping.MatchGroupResultConsumer) HashMap(java.util.HashMap) Map(java.util.Map) CombinedRecordMatcher(org.talend.dataquality.record.linkage.record.CombinedRecordMatcher) Test(org.junit.Test)

Example 2 with ParticularDefaultSurvivorshipDefinitions

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

the class AnalysisRecordGroupingUtilsTest method createParticularDefaultSurvivorshipDefinitions.

/**
 * Create ParticularDefaultSurvivorshipDefinitions
 *
 * @return
 */
private ParticularDefaultSurvivorshipDefinitions createParticularDefaultSurvivorshipDefinitions(String colName, AlgorithmDefinition algorDef) {
    ParticularDefaultSurvivorshipDefinitions createParticularDefaultSurvivorshipDefinition = RulesFactory.eINSTANCE.createParticularDefaultSurvivorshipDefinitions();
    createParticularDefaultSurvivorshipDefinition.setFunction(algorDef);
    createParticularDefaultSurvivorshipDefinition.setColumn(colName);
    return createParticularDefaultSurvivorshipDefinition;
}
Also used : ParticularDefaultSurvivorshipDefinitions(org.talend.dataquality.rules.ParticularDefaultSurvivorshipDefinitions)

Example 3 with ParticularDefaultSurvivorshipDefinitions

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

the class AnalysisMatchParameterAdapter method getDefaultSurviorShipRules.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dataquality.record.linkage.grouping.adapter.MatchParameterAdapter#getDefaultSurviorShipRules()
     */
@Override
public Map<Integer, SurvivorshipFunction> getDefaultSurviorShipRules() {
    Map<Integer, SurvivorshipFunction> defaultSurvRules = new HashMap<Integer, SurvivorshipFunction>();
    // Set default survivorship functions.
    List<DefaultSurvivorshipDefinition> defSurvDefs = recordMatchingIndicator.getBuiltInMatchRuleDefinition().getDefaultSurvivorshipDefinitions();
    // consisder ParticularDefaultSurvivorshipDefinitions too
    EList<ParticularDefaultSurvivorshipDefinitions> particularDefaultSurvivorshipDefinitions = recordMatchingIndicator.getBuiltInMatchRuleDefinition().getParticularDefaultSurvivorshipDefinitions();
    for (MetadataColumn metaColumn : columnMap.keySet()) {
        String dataTypeName = metaColumn.getTalendType();
        for (ParticularDefaultSurvivorshipDefinitions pdefaultSurvivdef : particularDefaultSurvivorshipDefinitions) {
            if (pdefaultSurvivdef.getColumn().equals(metaColumn.getName())) {
                putNewSurvFunc(columnMap, defaultSurvRules, metaColumn, pdefaultSurvivdef);
                break;
            }
        }
        // default survivorship has been handle by Particular
        if (defaultSurvRules.get(Integer.valueOf(columnMap.get(metaColumn))) != null) {
            continue;
        }
        for (DefaultSurvivorshipDefinition defSurvDef : defSurvDefs) {
            // type before judging if they are equal
            if (StringUtils.equals(dataTypeName, "id_" + defSurvDef.getDataType()) || StringUtils.equals(defSurvDef.getDataType(), "Number") && JavaTypesManager.isNumber(dataTypeName)) {
                // $NON-NLS-1$
                putNewSurvFunc(columnMap, defaultSurvRules, metaColumn, defSurvDef);
                break;
            }
        }
    // End for: if no func defined, then the value will be taken from one of the records in a group (1st
    // one ).
    }
    return defaultSurvRules;
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) ParticularDefaultSurvivorshipDefinitions(org.talend.dataquality.rules.ParticularDefaultSurvivorshipDefinitions) HashMap(java.util.HashMap) DefaultSurvivorshipDefinition(org.talend.dataquality.rules.DefaultSurvivorshipDefinition) SurvivorshipFunction(org.talend.dataquality.record.linkage.grouping.swoosh.SurvivorShipAlgorithmParams.SurvivorshipFunction)

Example 4 with ParticularDefaultSurvivorshipDefinitions

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

the class ParticularDefSurshipDefinitionSection method removeTableItem.

@Override
public void removeTableItem() {
    boolean success = false;
    ISelection selectItems = tableComposite.getSelectItems();
    if (selectItems instanceof StructuredSelection) {
        Iterator<ParticularDefaultSurvivorshipDefinitions> iterator = ((StructuredSelection) selectItems).iterator();
        while (iterator.hasNext()) {
            ParticularDefaultSurvivorshipDefinitions next = iterator.next();
            tableComposite.removeKeyDefinition(next, matchRuleDef.getParticularDefaultSurvivorshipDefinitions());
            success = true;
        }
        if (success) {
            listeners.firePropertyChange(MatchAnalysisConstant.ISDIRTY_PROPERTY, true, false);
        }
    }
}
Also used : ParticularDefaultSurvivorshipDefinitions(org.talend.dataquality.rules.ParticularDefaultSurvivorshipDefinitions) ISelection(org.eclipse.jface.viewers.ISelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection)

Example 5 with ParticularDefaultSurvivorshipDefinitions

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

the class ParticularDefSurshipDefinitionSection method importParticularSurvivorshipFunctions.

/**
 * import the DefaultSurvivorshipFunctions, if overwrite, clear the DefaultSurvivorshipFunctions before import.
 *
 * @param matchRuleDef
 * @param overwrite
 */
@SuppressWarnings("unchecked")
public void importParticularSurvivorshipFunctions(MatchRuleDefinition matchRuleDef, boolean overwrite) {
    EList<ParticularDefaultSurvivorshipDefinitions> functions = null;
    Object input = tableComposite.getInput();
    if (input != null) {
        functions = (EList<ParticularDefaultSurvivorshipDefinitions>) input;
    }
    if (functions == null) {
        functions = new BasicEList<ParticularDefaultSurvivorshipDefinitions>();
    }
    if (overwrite) {
        functions.clear();
    }
    for (ParticularDefaultSurvivorshipDefinitions def : matchRuleDef.getParticularDefaultSurvivorshipDefinitions()) {
        // note that here must copy first then modify it else will impact original element
        ParticularDefaultSurvivorshipDefinitions copyDef = EcoreUtil.copy(def);
        setColumnValueIfMatch(copyDef);
        boolean checkFunctionValid = checkFunctionValid(copyDef);
        if (!checkFunctionValid) {
            copyDef.getFunction().setAlgorithmType(SurvivorShipAlgorithmEnum.MOST_COMMON.getComponentValueName());
            copyDef.getFunction().setAlgorithmParameters(StringUtils.EMPTY);
        }
        functions.add(copyDef);
    }
    tableComposite.setInput(functions);
}
Also used : ParticularDefaultSurvivorshipDefinitions(org.talend.dataquality.rules.ParticularDefaultSurvivorshipDefinitions)

Aggregations

ParticularDefaultSurvivorshipDefinitions (org.talend.dataquality.rules.ParticularDefaultSurvivorshipDefinitions)20 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)4 ISelection (org.eclipse.jface.viewers.ISelection)3 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)3 SurvivorShipAlgorithmEnum (org.talend.dataquality.record.linkage.utils.SurvivorShipAlgorithmEnum)3 AlgorithmDefinition (org.talend.dataquality.rules.AlgorithmDefinition)3 Map (java.util.Map)2 ComboBoxCellEditor (org.eclipse.jface.viewers.ComboBoxCellEditor)2 TableItem (org.eclipse.swt.widgets.TableItem)2 RecordMatchingIndicator (org.talend.dataquality.indicators.columnset.RecordMatchingIndicator)2 SurvivorshipFunction (org.talend.dataquality.record.linkage.grouping.swoosh.SurvivorShipAlgorithmParams.SurvivorshipFunction)2 DefaultSurvivorshipDefinition (org.talend.dataquality.rules.DefaultSurvivorshipDefinition)2 MatchRuleDefinition (org.talend.dataquality.rules.MatchRuleDefinition)2 List (java.util.List)1 EList (org.eclipse.emf.common.util.EList)1 CellEditor (org.eclipse.jface.viewers.CellEditor)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1