Search in sources :

Example 11 with RegexpMatchingIndicator

use of org.talend.dataquality.indicators.RegexpMatchingIndicator in project tdq-studio-se by Talend.

the class ColumnSetAnalysisResultPage method getMatchColor.

/**
 * zshen Comment method "getMatchColor".
 *
 * @param element
 * @param columnIndex
 * @return get the color of the element.
 */
private Color getMatchColor(Object element, int columnIndex) {
    if (tableFilterResult.getTableFilterResult() != null) {
        for (Map<Integer, RegexpMatchingIndicator> tableItem : this.tableFilterResult.getTableFilterResult()) {
            RegexpMatchingIndicator regMatIndicator = tableItem.get(columnIndex);
            if (regMatIndicator == null) {
                continue;
            }
            String regex = regMatIndicator.getRegex();
            Pattern p = java.util.regex.Pattern.compile(regex);
            if (element instanceof Object[]) {
                Object theElement = ((Object[]) element)[columnIndex];
                if (theElement == null) {
                    // $NON-NLS-1$
                    theElement = "null";
                }
                Matcher m = p.matcher(String.valueOf(theElement));
                if (!m.find()) {
                    return new Color(null, 255, 0, 0);
                }
            }
        }
    }
    return new Color(null, 0, 0, 0);
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) Color(org.eclipse.swt.graphics.Color) RegexpMatchingIndicator(org.talend.dataquality.indicators.RegexpMatchingIndicator)

Example 12 with RegexpMatchingIndicator

use of org.talend.dataquality.indicators.RegexpMatchingIndicator in project tdq-studio-se by Talend.

the class PatternStatisticeStateUtilTest method testGetUnitValueCase4.

/**
 * Test method for
 * {@link org.talend.dataprofiler.core.ui.editor.preview.model.states.pattern.PatternStatisticeStateUtil#getUnitValue(org.talend.dataquality.indicators.Indicator, java.lang.Object)}
 * .
 * case4:Input value is PatternMatchingExt so that return directly
 */
@Test
public void testGetUnitValueCase4() {
    PatternMatchingExt pMatchExt = new PatternMatchingExt();
    pMatchExt.setMatchingValueCount(40l);
    pMatchExt.setNotMatchingValueCount(50l);
    RegexpMatchingIndicator regexpMatchingIndicator = IndicatorsFactoryImpl.eINSTANCE.createRegexpMatchingIndicator();
    regexpMatchingIndicator.setComputed(true);
    PatternMatchingExt unitValue = PatternStatisticeStateUtil.getUnitValue(regexpMatchingIndicator, pMatchExt);
    // $NON-NLS-1$
    Assert.assertEquals("Matching count value shoud be 40l", 40l, unitValue.getMatchingValueCount());
    // $NON-NLS-1$
    Assert.assertEquals("Not matching count value shoud be 50l", 50l, unitValue.getNotMatchingValueCount());
    // $NON-NLS-1$
    Assert.assertEquals("unitValue should same with pMatchExt but it is not now", pMatchExt, unitValue);
}
Also used : PatternMatchingExt(org.talend.dq.indicators.ext.PatternMatchingExt) RegexpMatchingIndicator(org.talend.dataquality.indicators.RegexpMatchingIndicator) Test(org.junit.Test)

Example 13 with RegexpMatchingIndicator

use of org.talend.dataquality.indicators.RegexpMatchingIndicator in project tdq-studio-se by Talend.

the class PatternStatisticsStateTest method setUp.

/**
 * init the state.
 *
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
    List<IndicatorUnit> units = new ArrayList<IndicatorUnit>();
    RegexpMatchingIndicator indicator = IndicatorsFactory.eINSTANCE.createRegexpMatchingIndicator();
    // $NON-NLS-1$
    indicator.setName("Blank text");
    indicator.setComputed(true);
    units.add(new ColumnSetIndicatorUnit(IndicatorEnum.AllMatchIndicatorEnum, indicator));
    patternStatisticsState = new PatternStatisticsState(units);
}
Also used : IndicatorUnit(org.talend.dataprofiler.core.ui.editor.preview.IndicatorUnit) ColumnSetIndicatorUnit(org.talend.dataprofiler.core.ui.editor.preview.ColumnSetIndicatorUnit) ArrayList(java.util.ArrayList) RegexpMatchingIndicator(org.talend.dataquality.indicators.RegexpMatchingIndicator) ColumnSetIndicatorUnit(org.talend.dataprofiler.core.ui.editor.preview.ColumnSetIndicatorUnit) Before(org.junit.Before)

Example 14 with RegexpMatchingIndicator

use of org.talend.dataquality.indicators.RegexpMatchingIndicator in project tdq-studio-se by Talend.

the class ColumnSetAnalysisExecutor method checkAllMatchIndicator.

protected boolean checkAllMatchIndicator(AllMatchIndicator indicator) {
    EList<RegexpMatchingIndicator> indicators = indicator.getCompositeRegexMatchingIndicators();
    String patternNames = PluginConstant.EMPTY_STRING;
    for (RegexpMatchingIndicator rmi : indicators) {
        if (null == rmi.getRegex()) {
            // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
            patternNames += System.getProperty("line.separator") + "\"" + rmi.getName() + "\"";
        } else if (rmi.getRegex().equals(rmi.getName())) {
            // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
            patternNames += System.getProperty("line.separator") + "\"" + rmi.getName() + "\"";
        }
    }
    if (PluginConstant.EMPTY_STRING != patternNames) {
        // $NON-NLS-1$
        traceError(Messages.getString("MultiColumnAnalysisExecutor.checkAllMatchIndicatorForDbType", patternNames));
        return false;
    }
    return true;
}
Also used : RegexpMatchingIndicator(org.talend.dataquality.indicators.RegexpMatchingIndicator)

Example 15 with RegexpMatchingIndicator

use of org.talend.dataquality.indicators.RegexpMatchingIndicator in project tdq-studio-se by Talend.

the class PatternsDataValidation method isValid.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.cwm.indicator.DataValidation#isValid(java.lang.Object)
     */
@Override
public boolean isValid(Object inputData) {
    if (tableFilterResult == null) {
        return true;
    }
    for (Map<Integer, RegexpMatchingIndicator> tableItem : tableFilterResult) {
        if (inputData instanceof ArrayList) {
            for (int index = 0; index < ((ArrayList<?>) inputData).size(); index++) {
                RegexpMatchingIndicator regMatIndicator = tableItem.get(index);
                if (regMatIndicator == null) {
                    continue;
                }
                String regex = regMatIndicator.getRegex();
                Pattern p = java.util.regex.Pattern.compile(regex);
                Object theElement = ((ArrayList<?>) inputData).get(index);
                if (theElement == null) {
                    // $NON-NLS-1$
                    theElement = "null";
                }
                Matcher m = p.matcher(String.valueOf(theElement));
                if (!m.find()) {
                    if (DataFilterType.MATCHES.equals(filterType)) {
                        return false;
                    } else if (DataFilterType.non_matches.equals(filterType)) {
                        return true;
                    }
                }
            }
        }
    }
    return DataFilterType.MATCHES.equals(filterType);
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) RegexpMatchingIndicator(org.talend.dataquality.indicators.RegexpMatchingIndicator)

Aggregations

RegexpMatchingIndicator (org.talend.dataquality.indicators.RegexpMatchingIndicator)18 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)7 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 Pattern (org.talend.dataquality.domain.pattern.Pattern)6 Domain (org.talend.dataquality.domain.Domain)5 Indicator (org.talend.dataquality.indicators.Indicator)5 AllMatchIndicator (org.talend.dataquality.indicators.columnset.AllMatchIndicator)5 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)4 TdExpression (org.talend.cwm.relational.TdExpression)3 PatternComponent (org.talend.dataquality.domain.pattern.PatternComponent)3 RegularExpression (org.talend.dataquality.domain.pattern.RegularExpression)3 PatternMatchingIndicator (org.talend.dataquality.indicators.PatternMatchingIndicator)3 HashMap (java.util.HashMap)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 ModelElementIndicator (org.talend.dataprofiler.core.model.ModelElementIndicator)2 Analysis (org.talend.dataquality.analysis.Analysis)2 CompositeIndicator (org.talend.dataquality.indicators.CompositeIndicator)2 SimpleStatIndicator (org.talend.dataquality.indicators.columnset.SimpleStatIndicator)2