private static void AnonymizeSegmentsWithoutTags(TranslationUnit translationUnit, List <SegmentElement> sourceTranslationElements, bool isSource) { foreach (var element in sourceTranslationElements) { var visitor = new SegmentElementVisitor(); element.AcceptSegmentElementVisitor(visitor); var segmentColection = visitor.SegmentColection; if (segmentColection?.Count > 0) { translationUnit.SourceSegment.Elements.Clear(); foreach (var segment in segmentColection) { var text = segment as Text; var tag = segment as Tag; if (text != null) { translationUnit.SourceSegment.Elements.Add(text); } if (tag != null) { translationUnit.SourceSegment.Elements.Add(tag); } } } } }
private static void AnonymizeSegmentsWithTags(TranslationUnit translationUnit, List <SegmentElement> translationElements, bool isSource) { for (var i = 0; i < translationElements.Count; i++) { if (!translationElements[i].GetType().UnderlyingSystemType.Name.Equals("Text")) { continue; } var visitor = new SegmentElementVisitor(); translationElements[i].AcceptSegmentElementVisitor(visitor); var segmentColection = visitor.SegmentColection; if (segmentColection?.Count > 0) { if (isSource) { var segmentElements = new List <SegmentElement>(); foreach (var segment in segmentColection) { var text = segment as Text; var tag = segment as Tag; if (text != null) { segmentElements.Add(text); } if (tag != null) { segmentElements.Add(tag); } } translationUnit.SourceSegment.Elements.RemoveAt(i); translationUnit.SourceSegment.Elements.InsertRange(i, segmentElements); } } } }
/// <summary> /// Anonymize segments with tags /// </summary> /// <param name="translationUnitDetails"></param> /// <param name="isSource"></param> private static void AnonymizeSegmentsWithTags(TranslationUnitDetails translationUnitDetails, bool isSource) { var translationUnitElements = new List <SegmentElement>(); if (isSource) { translationUnitElements = translationUnitDetails.TranslationUnit.SourceSegment.Elements.ToList(); } else { translationUnitElements = translationUnitDetails.TranslationUnit.TargetSegment.Elements.ToList(); } for (var i = 0; i < translationUnitElements.Count; i++) { if (isSource) { if (!translationUnitDetails.TranslationUnit.SourceSegment.Elements[i].GetType().UnderlyingSystemType.Name .Equals("Text")) { continue; } var visitor = new SegmentElementVisitor(translationUnitDetails.RemovedWordsFromMatches); //check for PI in each element from the list translationUnitDetails.TranslationUnit.SourceSegment.Elements[i].AcceptSegmentElementVisitor(visitor); var segmentColection = visitor.SegmentColection; if (segmentColection?.Count > 0) { var segmentElements = new List <SegmentElement>(); //if element contains PI add it to a list of Segment Elements foreach (var segment in segmentColection) { var text = segment as Text; var tag = segment as Tag; if (text != null) { segmentElements.Add(text); } if (tag != null) { segmentElements.Add(tag); } } //remove from the list original element at position translationUnitDetails.TranslationUnit.SourceSegment.Elements.RemoveAt(i); //to the same position add the new list with elements (Text + Tag) translationUnitDetails.TranslationUnit.SourceSegment.Elements.InsertRange(i, segmentElements); } } else { if (!translationUnitDetails.TranslationUnit.TargetSegment.Elements[i].GetType().UnderlyingSystemType.Name .Equals("Text")) { continue; } var visitor = new SegmentElementVisitor(translationUnitDetails.TargetRemovedWordsFromMatches); //check for PI in each element from the list translationUnitDetails.TranslationUnit.TargetSegment.Elements[i].AcceptSegmentElementVisitor(visitor); var segmentColection = visitor.SegmentColection; if (segmentColection?.Count > 0) { var segmentElements = new List <SegmentElement>(); //if element contains PI add it to a list of Segment Elements foreach (var segment in segmentColection) { var text = segment as Text; var tag = segment as Tag; if (text != null) { segmentElements.Add(text); } if (tag != null) { segmentElements.Add(tag); } } //remove from the list original element at position translationUnitDetails.TranslationUnit.TargetSegment.Elements.RemoveAt(i); //to the same position add the new list with elements (Text + Tag) translationUnitDetails.TranslationUnit.TargetSegment.Elements.InsertRange(i, segmentElements); } } } }
/// <summary> /// Anonymize segments without tags /// </summary> /// <param name="translationUnitDetails">Translation unit details</param> /// <param name="isSource"> Is source parameter</param> private static void AnonymizeSegmentsWithoutTags(TranslationUnitDetails translationUnitDetails, bool isSource) { var finalList = new List <SegmentElement>(); var elementsList = new List <SegmentElement>(); if (isSource) { elementsList = translationUnitDetails.TranslationUnit.SourceSegment.Elements.ToList(); } else { elementsList = translationUnitDetails.TranslationUnit.TargetSegment.Elements.ToList(); } foreach (var element in elementsList) { SegmentElementVisitor visitor; if (isSource) { visitor = new SegmentElementVisitor(translationUnitDetails.RemovedWordsFromMatches); } else { visitor = new SegmentElementVisitor(translationUnitDetails.TargetRemovedWordsFromMatches); } element.AcceptSegmentElementVisitor(visitor); var segmentColection = visitor.SegmentColection; if (segmentColection?.Count > 0) { foreach (var segment in segmentColection) { var text = segment as Text; var tag = segment as Tag; if (text != null) { finalList.Add(text); } if (tag != null) { finalList.Add(tag); } } } else { //add remaining words var text = element as Text; var tag = element as Tag; if (text != null) { finalList.Add(text); } if (tag != null) { finalList.Add(tag); } } } if (isSource) { //clear initial list translationUnitDetails.TranslationUnit.SourceSegment.Elements.Clear(); //add new elements list to Translation Unit translationUnitDetails.TranslationUnit.SourceSegment.Elements = finalList; } else { //clear initial list translationUnitDetails.TranslationUnit.TargetSegment.Elements.Clear(); //add new elements list to Translation Unit translationUnitDetails.TranslationUnit.TargetSegment.Elements = finalList; } }