Esempio n. 1
0
        /// <summary>
        /// Returns a errors list after numbers are normalized
        /// </summary>
        /// <param name="sourceText"></param>
        /// <param name="targetText"></param>
        /// <returns></returns>
        public IEnumerable <ErrorReporting> CheckNumbers(string sourceText, string targetText)
        {
            var sourceDecimalExtractComposer   = new SourceDecimalSeparatorsExtractComposer().Compose();
            var sourceThousandsExtractComposer = new SourceThousandSeparatorsExtractComposer().Compose();

            var sourceDecimalSeparators  = sourceDecimalExtractComposer.Extract(new ExtractData(VerificationSettings, new [] { sourceText }));
            var sourceThousandSeparators = sourceThousandsExtractComposer.Extract(new ExtractData(VerificationSettings, new[] { sourceText }));

            var sourceList = GetNumbersTuple(sourceText, string.Concat(sourceDecimalSeparators),
                                             string.Concat(sourceThousandSeparators), VerificationSettings.SourceNoSeparator,
                                             VerificationSettings.SourceOmitLeadingZero);

            var targetDecimalExtractComposer   = new TargetDecimalSeparatorsExtractComposer().Compose();
            var targetThousandsExtractComposer = new TargetThousandSeparatorsExtractComposer().Compose();

            var targetDecimalSeparators  = targetDecimalExtractComposer.Extract(new ExtractData(VerificationSettings, new[] { targetText }));
            var targetThousandSeparators = targetThousandsExtractComposer.Extract(new ExtractData(VerificationSettings, new[] { targetText }));

            var targetList = GetNumbersTuple(targetText, string.Concat(targetDecimalSeparators),
                                             string.Concat(targetThousandSeparators), VerificationSettings.TargetNoSeparator,
                                             VerificationSettings.TargetOmitLeadingZero);

            var sourceNumberList           = sourceList.Item1;
            var sourceNormalizedNumberList = sourceList.Item2;

            var targetNumberList           = targetList.Item1;
            var targetNormalizedNumberList = targetList.Item2;

            // remove identical numbers found both in source and target from respective list
            RemoveIdenticalNumbers(sourceNumberList, targetNumberList, targetNormalizedNumberList,
                                   sourceNormalizedNumberList);

            // remove numbers found both in source and target from respective list disregarding difference in thousands and decimal separators
            RemoveNumbersIgnoreThousandsAndDecimalSeparators(sourceNumberList, targetNormalizedNumberList,
                                                             sourceNormalizedNumberList, targetNumberList);

            // remove numbers found both in source and target from respective list disregarding difference when thousands and decimal separators are undefined due to ambiguity
            RemoveNumbersUndefinedThousandsAndDecimalSeparator(targetNumberList, sourceNumberList,
                                                               sourceNormalizedNumberList, targetNormalizedNumberList);


            var numberResults = new NumberResults(VerificationSettings,
                                                  sourceNumberList,
                                                  targetNumberList, sourceText, targetText);

            var numberErrorComposer = new NumberErrorComposer();
            var verifyProcessor     = numberErrorComposer.Compose();

            return(verifyProcessor.Verify(numberResults));
        }
Esempio n. 2
0
        /// <summary>
        /// Returns a list of errors after checking the alphanumerics
        /// e.g: AB12
        /// </summary>
        /// <param name="sourceText"></param>
        /// <param name="targetText"></param>
        /// <returns></returns>
        public IEnumerable <ErrorReporting> CheckAlphanumerics(string sourceText, string targetText)
        {
            var sourceAlphanumericsList = GetAlphanumericList(sourceText);

            // find all alphanumeric names in target and add to list
            var targetAlphanumericsList = GetAlphanumericList(targetText);

            // remove alphanumeric names found both in source and target from respective list
            RemoveMatchingAlphanumerics(sourceAlphanumericsList, targetAlphanumericsList);

            var numberResults = new NumberResults(VerificationSettings,
                                                  sourceAlphanumericsList,
                                                  targetAlphanumericsList);

            var alphanumericErrorComposer = new AlphanumericErrorComposer();
            var verifyProcessor           = alphanumericErrorComposer.Compose();

            return(verifyProcessor.Verify(numberResults));
        }
Esempio n. 3
0
        /// <summary>
        /// Returns a list of errors after checking the alphanumerics
        /// e.g: AB12
        /// </summary>
        /// <param name="sourceText"></param>
        /// <param name="targetText"></param>
        /// <param name="sourceExcludedRanges"></param>
        /// <param name="targetExcludedRanges"></param>
        /// <returns></returns>
        public IEnumerable <ErrorReporting> CheckAlphanumerics(string sourceText, string targetText, List <ExcludedRange> sourceExcludedRanges = null, List <ExcludedRange> targetExcludedRanges = null)
        {
            if (!_verificationSettings.CustomsSeparatorsAlphanumerics && !_verificationSettings.ReportModifiedAlphanumerics)
            {
                return(Enumerable.Empty <ErrorReporting>());
            }
            try
            {
                var sourceAlphanumericsList = GetAlphanumericList(sourceText, true, sourceExcludedRanges);

                // find all alphanumeric names in target and add to list
                var targetAlphanumericsList = GetAlphanumericList(targetText, false, targetExcludedRanges);

                // remove alphanumeric names found both in source and target from respective list
                RemoveMatchingAlphanumerics(sourceAlphanumericsList.Item2, targetAlphanumericsList.Item2);
                var numberModel = new NumberModel
                {
                    Settings             = VerificationSettings,
                    SourceNumbers        = sourceAlphanumericsList.Item2,
                    TargetNumbers        = targetAlphanumericsList.Item2,
                    InitialSourceNumbers = sourceAlphanumericsList.Item1,
                    InitialTargetNumbers = targetAlphanumericsList.Item1,
                    SourceText           = sourceText,
                    TargetText           = targetText
                };
                var numberResults = new NumberResults(numberModel);

                var alphanumericErrorComposer = new AlphanumericErrorComposer();
                var verifyProcessor           = alphanumericErrorComposer.Compose();

                return(verifyProcessor.Verify(numberResults));
            }
            catch (Exception ex)
            {
                _logger.Error($"{MethodBase.GetCurrentMethod().Name} \n {ex}");
                return(new List <ErrorReporting>());
            }
        }