Beispiel #1
0
        /// <summary>
        /// The following member performs the actual verification. It traverses the segment pairs of the current document,
        /// and checks whether a particular segment has any context information (count > 0). It then determines whether
        /// the display code is identical to the display code entered in the plug-in settings.
        /// If this is the case, it determines whether the target segment is actually identical to the source segment.
        /// If not, a warning message will be generated, which is then displayed between the source and target segments,
        /// and in the Messages window of SDL Trados Studio.
        /// </summary>
        /// <param name="paragraphUnit"></param>
        #region "verify"
        private void CheckParagraphUnit(IParagraphUnit paragraphUnit)
        {
            // Declare and reset target segment text.
            string completeTextTarget = "";

            // loop through the whole paragraph unit
            foreach (ISegmentPair segmentPair in paragraphUnit.SegmentPairs)
            {
                // Determine if context information is available,
                // and if the context equals the one specified in the user interface.
                if (paragraphUnit.Properties.Contexts.Contexts.Count > 0 &&
                    paragraphUnit.Properties.Contexts.Contexts[0].DisplayCode == VerificationSettings.CheckContext.Value)
                {
                    // Check whether target differs from source.
                    // If this is the case, then output a warning message
                    if (segmentPair.Source.ToString() != segmentPair.Target.ToString())
                    {
                        // Generate the plain text information if ConsiderTags is not true.
                        #region "GetPlainText"
                        completeTextTarget += TextGeneratorProcessor.GetPlainText(segmentPair.Target, VerificationSettings.ConsiderTags.Value);
                        #endregion

                        #region ReportingMessage
                        if (MessageReporter is IBilingualContentMessageReporterWithExtendedData)
                        {
                            #region CreateExtendedData
                            string context = paragraphUnit.Properties.Contexts.Contexts[0].DisplayCode;
                            IdenticalVerifierMessageData extendedData = new IdenticalVerifierMessageData(completeTextTarget +
                                                                                                         " - must be identical to source because the paragraph has context " + context + ".", segmentPair.Source);
                            #endregion

                            #region ReportingMessageWithExtendedData
                            IBilingualContentMessageReporterWithExtendedData extendedMessageReporter = (IBilingualContentMessageReporterWithExtendedData)MessageReporter;
                            extendedMessageReporter.ReportMessage(this, PluginResources.Plugin_Name,
                                                                  ErrorLevel.Warning, PluginResources.Error_NotIdentical,
                                                                  new TextLocation(new Location(segmentPair.Target, true), 0),
                                                                  new TextLocation(new Location(segmentPair.Target, false), segmentPair.Target.ToString().Length - 1),
                                                                  extendedData);
                            #endregion
                        }
                        else
                        {
                            #region ReportingMessageWithoutExtendedData
                            MessageReporter.ReportMessage(this, PluginResources.Plugin_Name,
                                                          ErrorLevel.Warning, PluginResources.Error_NotIdentical,
                                                          new TextLocation(new Location(segmentPair.Target, true), 0),
                                                          new TextLocation(new Location(segmentPair.Target, false), segmentPair.Target.ToString().Length - 1));
                            #endregion
                        }
                        #endregion
                    }
                }
            }
        }
        /// <summary>
        /// The following member performs the actual verification. It traverses the segment pairs of the current document,
        /// and checks whether a particular segment has any context information (count > 0). It then determines whether
        /// the display code is identical to the display code entered in the plug-in settings.
        /// If this is the case, it determines whether the target segment is actually identical to the source segment.
        /// If not, a warning message will be generated, which is then displayed between the source and target segments,
        /// and in the Messages window of SDL Trados Studio.
        /// </summary>
        /// <param name="paragraphUnit"></param>
        #region "verify"
        private void CheckParagraphUnit(IParagraphUnit paragraphUnit)
        {
            if (paragraphUnit.Properties.Contexts is null)
            {
                return;
            }
            // Declare and reset target segment text.
            var completeTextTarget = string.Empty;

            // loop through the whole paragraph unit
            foreach (var segmentPair in paragraphUnit.SegmentPairs)
            {
                var paragraphContexts = paragraphUnit.Properties.Contexts.Contexts;
                if (paragraphContexts is null)
                {
                    return;
                }

                // Determine if context information is available,
                // and if the context contains the one specified in the user interface.
                var paragraphContainsCheckContext =
                    paragraphContexts.Any(c => c.DisplayCode != null && c.DisplayCode.Contains(VerificationSettings.CheckContext.Value));

                if (!paragraphContainsCheckContext)
                {
                    continue;
                }
                if (segmentPair.Source.ToString() != segmentPair.Target.ToString())
                {
                    // Generate the plain text information if ConsiderTags is not true.
                    #region "GetPlainText"
                    completeTextTarget += TextGeneratorProcessor.GetPlainText(segmentPair.Target, VerificationSettings.ConsiderTags.Value);
                    #endregion

                    #region ReportingMessage
                    if (MessageReporter is IBilingualContentMessageReporterWithExtendedData)
                    {
                        #region CreateExtendedData
                        var context      = paragraphUnit.Properties.Contexts.Contexts[0].DisplayCode;
                        var extendedData = new IdenticalVerifierMessageData(completeTextTarget +
                                                                            " - must be identical to source because the paragraph has context " + context + ".", segmentPair.Source);
                        #endregion

                        #region ReportingMessageWithExtendedData
                        var extendedMessageReporter = (IBilingualContentMessageReporterWithExtendedData)MessageReporter;
                        extendedMessageReporter.ReportMessage(this, PluginResources.Plugin_Name,
                                                              ErrorLevel.Warning, PluginResources.Error_NotIdentical,
                                                              new TextLocation(new Location(segmentPair.Target, true), 0),
                                                              new TextLocation(new Location(segmentPair.Target, false), segmentPair.Target.ToString().Length - 1),
                                                              extendedData);
                        #endregion
                    }
                    else
                    {
                        #region ReportingMessageWithoutExtendedData
                        MessageReporter.ReportMessage(this, PluginResources.Plugin_Name,
                                                      ErrorLevel.Warning, PluginResources.Error_NotIdentical,
                                                      new TextLocation(new Location(segmentPair.Target, true), 0),
                                                      new TextLocation(new Location(segmentPair.Target, false), segmentPair.Target.ToString().Length - 1));
                        #endregion
                    }
                    #endregion
                }
            }
        }
Beispiel #3
0
 private string GetSegmentText(ISegment segment)
 {
     return(VerificationSettings.ExcludeTagText.Value == false?segment.ToString() : TextGeneratorProcessor.GetPlainText(segment, false));
 }
Beispiel #4
0
        /// <summary>
        /// The following member performs the actual verification. It traverses the segment pairs of the current document,
        /// and checks whether a particular segment has any numbers. It then determines whether
        /// the target and the source contains the same numbers.
        /// If not, a warning message will be generated, which is then displayed between the source and target segments,
        /// and in the Messages window of SDL Trados Studio.
        /// </summary>
        /// <param name="paragraphUnit"></param>
        private void CheckParagraphUnit(IParagraphUnit paragraphUnit)
        {
            var sourceNumberList           = new List <string>();
            var targetNumberList           = new List <string>();
            var sourceNormalizedNumberList = new List <string>();
            var targetNormalizedNumberList = new List <string>();

            // loop through the whole paragraph unit
            foreach (var segmentPair in paragraphUnit.SegmentPairs.Where(FilterSegmentPairs))
            {
                var sourceText = GetSegmentText(segmentPair.Source);
                var targetText = GetSegmentText(segmentPair.Target);


                // find all alphanumeric names in source and add to list
                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);

                // find all numbers in source and add to list
                sourceNumberList.Clear();
                sourceNormalizedNumberList.Clear();
                NormalizeAlphanumerics(sourceText, sourceNumberList, sourceNormalizedNumberList, _sourceThousandSeparators, _sourceDecimalSeparators, VerificationSettings.SourceNoSeparator);

                // find all numbers in target and add to list
                targetNumberList.Clear();
                targetNormalizedNumberList.Clear();
                NormalizeAlphanumerics(targetText, targetNumberList, targetNormalizedNumberList, _targetThousandSeparators, _targetDecimalSeparators, VerificationSettings.TargetNoSeparator);

                // 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 errorLevel           = ErrorLevel.Unspecified;
                var errorMessage         = String.Empty;
                var extendedErrorMessage = String.Empty;

                // check if numbers have been modified and should be reported
                if (sourceNumberList.Count > 0 && targetNumberList.Count > 0 && VerificationSettings.ReportModifiedNumbers.Value)
                {
                    switch (VerificationSettings.ModifiedNumbersErrorType.Value)
                    {
                    case "Error":
                        errorLevel = ErrorLevel.Error;
                        break;

                    case "Warning":
                        errorLevel = ErrorLevel.Warning;
                        break;

                    default:
                        errorLevel = ErrorLevel.Note;
                        break;
                    }
                    errorMessage = errorMessage + PluginResources.Error_NumbersNotIdentical;
                }

                // check if numbers have been added and should be reported
                if (sourceNumberList.Count < targetNumberList.Count && VerificationSettings.ReportAddedNumbers.Value)
                {
                    if (VerificationSettings.AddedNumbersErrorType.Value == "Error")
                    {
                        errorLevel = ErrorLevel.Error;
                    }
                    else if (VerificationSettings.AddedNumbersErrorType.Value == "Warning" && errorLevel != ErrorLevel.Error)
                    {
                        errorLevel = ErrorLevel.Warning;
                    }
                    else if (errorLevel != ErrorLevel.Error && errorLevel != ErrorLevel.Warning)
                    {
                        errorLevel = ErrorLevel.Note;
                    }
                    errorMessage = errorMessage + PluginResources.Error_NumbersAdded;
                }

                // check if numbers have been removed and should be reported
                if (sourceNumberList.Count > targetNumberList.Count && VerificationSettings.ReportRemovedNumbers.Value)
                {
                    if (VerificationSettings.RemovedNumbersErrorType.Value == "Error")
                    {
                        errorLevel = ErrorLevel.Error;
                    }
                    else if (VerificationSettings.RemovedNumbersErrorType.Value == "Warning" && errorLevel != ErrorLevel.Error)
                    {
                        errorLevel = ErrorLevel.Warning;
                    }
                    else if (errorLevel != ErrorLevel.Error && errorLevel != ErrorLevel.Warning)
                    {
                        errorLevel = ErrorLevel.Note;
                    }
                    errorMessage = errorMessage + PluginResources.Error_NumbersRemoved;
                }

                // check if alphanumeric names are mismatched and should be reported
                if ((targetAlphanumericsList.Count > 0 || sourceAlphanumericsList.Count > 0) && VerificationSettings.ReportModifiedAlphanumerics.Value)
                {
                    if (VerificationSettings.ModifiedAlphanumericsErrorType.Value == "Error")
                    {
                        errorLevel = ErrorLevel.Error;
                    }
                    else if (VerificationSettings.ModifiedAlphanumericsErrorType.Value == "Warning" && errorLevel != ErrorLevel.Error)
                    {
                        errorLevel = ErrorLevel.Warning;
                    }
                    else if (errorLevel != ErrorLevel.Error && errorLevel != ErrorLevel.Warning)
                    {
                        errorLevel = ErrorLevel.Note;
                    }
                    errorMessage = errorMessage + PluginResources.Error_AlphanumericsModified;
                }


                // if there are any mismatched numbers or alphanumerics to report, output a warning message
                if (errorMessage == String.Empty)
                {
                    continue;
                }

                // collate remaining numbers and put into string variables for reporting of details
                var sourceNumberIssues = String.Empty;
                if (sourceNumberList.Count > 0 && (VerificationSettings.ReportAddedNumbers.Value || VerificationSettings.ReportRemovedNumbers.Value || VerificationSettings.ReportModifiedNumbers.Value))
                {
                    sourceNumberIssues = sourceNumberList.Aggregate(sourceNumberIssues, (current, t) => current + (t + " \r\n"));
                }

                if (sourceAlphanumericsList.Count > 0 && VerificationSettings.ReportModifiedAlphanumerics.Value)
                {
                    sourceNumberIssues = sourceAlphanumericsList.Aggregate(sourceNumberIssues, (current, t) => current + (t + " \r\n"));
                }

                var targetNumberIssues = String.Empty;
                if (targetNumberList.Count > 0 && (VerificationSettings.ReportAddedNumbers.Value || VerificationSettings.ReportRemovedNumbers.Value || VerificationSettings.ReportModifiedNumbers.Value))
                {
                    targetNumberIssues = targetNumberList.Aggregate(targetNumberIssues, (current, t) => current + (t + " \r\n"));
                }

                if (targetAlphanumericsList.Count > 0 && VerificationSettings.ReportModifiedAlphanumerics.Value)
                {
                    targetNumberIssues = targetAlphanumericsList.Aggregate(targetNumberIssues, (current, t) => current + (t + " \r\n"));
                }


                if (VerificationSettings.ReportExtendedMessages == true)
                {
                    extendedErrorMessage = "\r\n SOURCE: " + TextGeneratorProcessor.GetPlainText(segmentPair.Source, !VerificationSettings.ExcludeTagText.Value) + " \r\n TARGET: " + TextGeneratorProcessor.GetPlainText(segmentPair.Target, !VerificationSettings.ExcludeTagText.Value);
                }


                #region ReportingMessage

                var extendedMessageReporter = MessageReporter as IBilingualContentMessageReporterWithExtendedData;
                if (extendedMessageReporter != null)
                {
                    #region CreateExtendedData
                    var extendedData = new NumberVerifierMessageData(sourceNumberIssues, targetNumberIssues, segmentPair.Target);
                    #endregion

                    #region ReportingMessageWithExtendedData
                    extendedMessageReporter.ReportMessage(this, PluginResources.Plugin_Name,
                                                          errorLevel, errorMessage + extendedErrorMessage,
                                                          new TextLocation(new Location(segmentPair.Target, true), 0),
                                                          new TextLocation(new Location(segmentPair.Target, false), segmentPair.Target.ToString().Length - 1),
                                                          extendedData);
                    #endregion
                }
                else
                {
                    #region ReportingMessageWithoutExtendedData
                    MessageReporter.ReportMessage(this, PluginResources.Plugin_Name,
                                                  errorLevel, errorMessage + extendedErrorMessage,
                                                  new TextLocation(new Location(segmentPair.Target, true), 0),
                                                  new TextLocation(new Location(segmentPair.Target, false), segmentPair.Target.ToString().Length - 1));
                    #endregion
                }
            }
        }