public void ProcessParagraphUnit(IParagraphUnit paragraphUnit)
        {
            #region  |  for comments that were added at the paragraph level  |

            var paragraphComments = new List <Comment>();

            if (paragraphUnit.Properties.Comments != null && paragraphUnit.Properties.Comments.Count > 0)
            {
                foreach (var comment in paragraphUnit.Properties.Comments.Comments)
                {
                    var item = new Comment
                    {
                        Author   = comment.Author,
                        Severity = comment.Severity.ToString(),
                        Text     = comment.Text,
                        Version  = comment.Version
                    };

                    if (comment.DateSpecified)
                    {
                        item.Date = comment.Date;
                    }

                    paragraphComments.Add(item);
                }
            }
            #endregion

            var index = -1;
            foreach (var segmentPair in paragraphUnit.SegmentPairs)
            {
                index++;

                #region  |  initialize and assign values to xSegmentPair  |

                var pair = new SegmentPair();

                ContentGeneratorProcessor.ProcessSegment(segmentPair.Source, IncludeTagText);
                pair.Source         = ContentGeneratorProcessor.PlainText.ToString();
                pair.SourceSections = ContentGeneratorProcessor.SegmentSections;


                ContentGeneratorProcessor.ProcessSegment(segmentPair.Target, IncludeTagText);
                pair.Target         = ContentGeneratorProcessor.PlainText.ToString();
                pair.TargetSections = ContentGeneratorProcessor.SegmentSections;
                pair.Id             = segmentPair.Properties.Id.Id;
                pair.SegmentStatus  = segmentPair.Properties.ConfirmationLevel.ToString();
                pair.IsLocked       = segmentPair.Properties.IsLocked;
                pair.Comments       = ContentGeneratorProcessor.Comments;

                #region  |  for comments that were added at the paragraph level  |

                if (paragraphComments.Count > 0 && index == 0)
                {
                    if (pair.Comments.Count > 0)
                    {
                        foreach (var commentParagraph in paragraphComments)
                        {
                            var foundComment = pair.Comments.Any(xCommentSegmentPair
                                                                 => string.CompareOrdinal(commentParagraph.Text.Trim(), xCommentSegmentPair.Text.Trim()) == 0);


                            if (!foundComment)
                            {
                                pair.Comments.Add(commentParagraph);
                            }
                        }
                    }
                    else
                    {
                        foreach (var comment in paragraphComments)
                        {
                            pair.Comments.Add(comment);
                        }
                    }
                }
                #endregion


                if (segmentPair.Properties.TranslationOrigin != null)
                {
                    pair.TranslationOrigin.IsRepeated = segmentPair.Properties.TranslationOrigin.IsRepeated;
                    pair.TranslationOrigin.IsStructureContextMatch = segmentPair.Properties.TranslationOrigin.IsStructureContextMatch;
                    pair.TranslationOrigin.MatchPercentage         = segmentPair.Properties.TranslationOrigin.MatchPercent;
                    pair.TranslationOrigin.OriginSystem            = segmentPair.Properties.TranslationOrigin.OriginSystem;
                    pair.TranslationOrigin.OriginType            = segmentPair.Properties.TranslationOrigin.OriginType;
                    pair.TranslationOrigin.RepetitionTableId     = segmentPair.Properties.TranslationOrigin.RepetitionTableId.Id;
                    pair.TranslationOrigin.TextContextMatchLevel = segmentPair.Properties.TranslationOrigin.TextContextMatchLevel.ToString();
                }

                #endregion

                #region  |  add the SegmentPair to the xParagraphs dictionary  |

                if (ParagraphUnits.ContainsKey(paragraphUnit.Properties.ParagraphUnitId.Id))
                {
                    var unit = ParagraphUnits[paragraphUnit.Properties.ParagraphUnitId.Id];
                    unit.SegmentPairs.Add(pair);
                    ParagraphUnits[paragraphUnit.Properties.ParagraphUnitId.Id] = unit;
                }
                else
                {
                    var segmentPairs = new List <SegmentPair> {
                        pair
                    };
                    ParagraphUnits.Add(paragraphUnit.Properties.ParagraphUnitId.Id, new ParagraphUnit(paragraphUnit.Properties.ParagraphUnitId.Id, segmentPairs));
                }
                #endregion
            }
        }
        public void ProcessParagraphUnit(IParagraphUnit paragraphUnit)
        {
            #region  |  for comments that were added at the paragraph level  |

            var paragraphComments = new List <Comment>();

            if (paragraphUnit.Properties.Comments != null && paragraphUnit.Properties.Comments.Count > 0)
            {
                foreach (var commmentItem in paragraphUnit.Properties.Comments.Comments)
                {
                    var comment    = commmentItem;
                    var commentNew = new Comment {
                        Author = comment.Author
                    };
                    if (comment.DateSpecified)
                    {
                        commentNew.Date = comment.Date;
                    }
                    commentNew.Severity = comment.Severity.ToString();
                    commentNew.Text     = comment.Text;
                    commentNew.Version  = comment.Version;

                    paragraphComments.Add(commentNew);
                }
            }
            #endregion



            var index = -1;
            foreach (var segmentPair in paragraphUnit.SegmentPairs)
            {
                index++;


                var pair = new SegmentPair();

                ContentGeneratorProcessor.ProcessSegment(segmentPair.Source, IncludeTagText);
                ContentGeneratorProcessor.Segment.Culture = new CultureInfo(SourceLanguageId);

                try
                {
                    var results = Tokenizer.TokenizeSegment(segmentPair);
                    if (results != null)
                    {
                        pair.SourceWords      = results.SourceWordCounts.Words;
                        pair.SourceChars      = results.SourceWordCounts.Characters;
                        pair.SourcePlaceables = results.SourceWordCounts.Placeables;
                        pair.SourceTags       = results.SourceWordCounts.Tags;
                    }
                }
                catch
                {
                    // catch all
                }

                pair.Source         = ContentGeneratorProcessor.PlainText.ToString();
                pair.SourceSections = ContentGeneratorProcessor.SegmentSections;

                ContentGeneratorProcessor.ProcessSegment(segmentPair.Target, IncludeTagText);
                pair.Target         = ContentGeneratorProcessor.PlainText.ToString();
                pair.TargetSections = ContentGeneratorProcessor.SegmentSections;
                pair.Id             = segmentPair.Properties.Id.Id;
                pair.SegmentStatus  = segmentPair.Properties.ConfirmationLevel.ToString();
                pair.IsLocked       = segmentPair.Properties.IsLocked;
                pair.Comments       = ContentGeneratorProcessor.Comments;

                #region  |  for comments that were added at the paragraph level  |

                if (paragraphComments.Count > 0 && index == 0)
                {
                    if (pair.Comments.Count > 0)
                    {
                        foreach (var commentParagraph in paragraphComments)
                        {
                            var foundComment = pair.Comments.Any(commentSegmentPair => string.CompareOrdinal(commentParagraph.Text.Trim(), commentSegmentPair.Text.Trim()) == 0);


                            if (!foundComment)
                            {
                                pair.Comments.Add(commentParagraph);
                            }
                        }
                    }
                    else
                    {
                        foreach (var comment in paragraphComments)
                        {
                            pair.Comments.Add(comment);
                        }
                    }
                }
                #endregion


                if (segmentPair.Properties.TranslationOrigin != null)
                {
                    pair.TranslationOrigin.IsRepeated = segmentPair.Properties.TranslationOrigin.IsRepeated;
                    pair.TranslationOrigin.IsStructureContextMatch = segmentPair.Properties.TranslationOrigin.IsStructureContextMatch;
                    pair.TranslationOrigin.MatchPercentage         = segmentPair.Properties.TranslationOrigin.MatchPercent;
                    pair.TranslationOrigin.OriginSystem            = segmentPair.Properties.TranslationOrigin.OriginSystem;
                    pair.TranslationOrigin.OriginType            = segmentPair.Properties.TranslationOrigin.OriginType;
                    pair.TranslationOrigin.RepetitionTableId     = segmentPair.Properties.TranslationOrigin.RepetitionTableId.Id;
                    pair.TranslationOrigin.TextContextMatchLevel = segmentPair.Properties.TranslationOrigin.TextContextMatchLevel.ToString();
                }


                #region  |  add the SegmentPair to the xParagraphs dictionary  |

                if (ParagraphUnits.ContainsKey(paragraphUnit.Properties.ParagraphUnitId.Id))
                {
                    var unit = ParagraphUnits[paragraphUnit.Properties.ParagraphUnitId.Id];
                    unit.SegmentPairs.Add(pair);
                    ParagraphUnits[paragraphUnit.Properties.ParagraphUnitId.Id] = unit;
                }
                else
                {
                    var segmentPairs = new List <SegmentPair> {
                        pair
                    };
                    ParagraphUnits.Add(paragraphUnit.Properties.ParagraphUnitId.Id, new ParagraphUnit(paragraphUnit.Properties.ParagraphUnitId.Id, segmentPairs));
                }
                #endregion
            }
        }
Esempio n. 3
0
        public void ProcessParagraphUnit(IParagraphUnit paragraphUnit)
        {
            #region  |  for comments that were added at the paragraph level  |

            var paragraphComments = new List <Comment>();

            if (paragraphUnit.Properties.Comments != null && paragraphUnit.Properties.Comments.Count > 0)
            {
                foreach (var comment in paragraphUnit.Properties.Comments.Comments)
                {
                    var xComment = new Comment {
                        Author = comment.Author
                    };
                    if (comment.DateSpecified)
                    {
                        xComment.Date = comment.Date;
                    }
                    xComment.Severity = comment.Severity.ToString();
                    xComment.Text     = comment.Text;
                    xComment.Version  = comment.Version;

                    paragraphComments.Add(xComment);
                }
            }
            #endregion



            var index = -1;
            foreach (var segmentPair in paragraphUnit.SegmentPairs)
            {
                index++;

                #region  |  initialize and assign values to xSegmentPair  |

                var pair = new SegmentPair();

                ContentGeneratorProcessor.ProcessSegment(segmentPair.Source, IncludeTagText);
                pair.Source         = ContentGeneratorProcessor.PlainText.ToString();
                pair.SourceSections = ContentGeneratorProcessor.SegmentSections;


                ContentGeneratorProcessor.ProcessSegment(segmentPair.Target, IncludeTagText);
                pair.Target         = ContentGeneratorProcessor.PlainText.ToString();
                pair.TargetSections = ContentGeneratorProcessor.SegmentSections;

                if (pair.SourceSections.Count > 0 && pair.TargetSections.Count == 0)
                {
                    if (Processor.ProcessorSettings.CopySourceToTargetEmptyTranslations)
                    {
                        pair.Target         = pair.Source;
                        pair.TargetSections = pair.SourceSections;
                    }
                }

                pair.Id            = segmentPair.Properties.Id.Id;
                pair.SegmentStatus = segmentPair.Properties.ConfirmationLevel.ToString();
                pair.IsLocked      = segmentPair.Properties.IsLocked;
                pair.Comments      = ContentGeneratorProcessor.Comments;

                #region  |  for comments that were added at the paragraph level  |

                if (paragraphComments.Count > 0 && index == 0)
                {
                    if (pair.Comments.Count > 0)
                    {
                        foreach (var xCommentParagraph in paragraphComments)
                        {
                            var foundComment = pair.Comments.Any(xCommentSegmentPair => string.CompareOrdinal(xCommentParagraph.Text.Trim(), xCommentSegmentPair.Text.Trim()) == 0);
                            if (!foundComment)
                            {
                                pair.Comments.Add(xCommentParagraph);
                            }
                        }
                    }
                    else
                    {
                        foreach (var xComment in paragraphComments)
                        {
                            pair.Comments.Add(xComment);
                        }
                    }
                }
                #endregion


                if (segmentPair.Properties.TranslationOrigin != null)
                {
                    pair.TranslationOrigin.IsRepeated = segmentPair.Properties.TranslationOrigin.IsRepeated;
                    pair.TranslationOrigin.IsStructureContextMatch = segmentPair.Properties.TranslationOrigin.IsStructureContextMatch;
                    pair.TranslationOrigin.MatchPercentage         = segmentPair.Properties.TranslationOrigin.MatchPercent;
                    pair.TranslationOrigin.OriginSystem            = segmentPair.Properties.TranslationOrigin.OriginSystem;
                    pair.TranslationOrigin.OriginType            = segmentPair.Properties.TranslationOrigin.OriginType;
                    pair.TranslationOrigin.RepetitionTableId     = segmentPair.Properties.TranslationOrigin.RepetitionTableId.Id;
                    pair.TranslationOrigin.TextContextMatchLevel = segmentPair.Properties.TranslationOrigin.TextContextMatchLevel.ToString();

                    pair.TranslationOrigin.OriginalTranslationHash       = segmentPair.Properties.TranslationOrigin.OriginalTranslationHash;
                    pair.TranslationOrigin.OriginalTranslationHashSource = segmentPair.Source.Properties.TranslationOrigin.OriginalTranslationHash;
                    pair.TranslationOrigin.OriginalTranslationHashTarget = segmentPair.Target.Properties.TranslationOrigin.OriginalTranslationHash;
                }

                #endregion


                #region  |  add the SegmentPair to the xParagraphs dictionary  |

                if (ParagraphUnits.ContainsKey(paragraphUnit.Properties.ParagraphUnitId.Id))
                {
                    var xParagraphUnit = ParagraphUnits[paragraphUnit.Properties.ParagraphUnitId.Id];
                    xParagraphUnit.SegmentPairs.Add(pair);
                    ParagraphUnits[paragraphUnit.Properties.ParagraphUnitId.Id] = xParagraphUnit;
                }
                else
                {
                    var pairItem = new List <SegmentPair> {
                        pair
                    };
                    ParagraphUnits.Add(paragraphUnit.Properties.ParagraphUnitId.Id, new ParagraphUnit(paragraphUnit.Properties.ParagraphUnitId.Id, pairItem, CurrentFileProperties.FileConversionProperties.OriginalFilePath));
                }
                #endregion

                if (segmentPair.Target.Count != 0 || !Processor.ProcessorSettings.CopySourceToTargetEmptyTranslations)
                {
                    continue;
                }
                foreach (var item in segmentPair.Source)
                {
                    segmentPair.Target.Add((IAbstractMarkupData)item.Clone());
                }
            }
        }