/// <summary> /// Gets server based TUs which contains PI /// </summary> /// <param name="translationProvider">Translation provider</param> /// <param name="tmPath">Translation memory path</param> /// <param name="sourceSearchResult">Regex search result</param> /// <param name="selectedRules">Selected rules from the grid</param> /// <returns>An object which has Tm path and a list of trasnlation units which contains PI</returns> public static AnonymizeTranslationMemory ServerBasedTmGetTranslationUnits(TranslationProviderServer translationProvider, string tmPath, ObservableCollection <SourceSearchResult> sourceSearchResult, List <Rule> selectedRules) { var allTusForLanguageDirections = new List <TranslationUnit>(); System.Windows.Application.Current.Dispatcher.Invoke(delegate { var translationMemory = translationProvider.GetTranslationMemory(tmPath, TranslationMemoryProperties.All); var languageDirections = translationMemory.LanguageDirections; var pi = new PersonalInformation(selectedRules); foreach (var languageDirection in languageDirections) { var unitsCount = languageDirection.GetTranslationUnitCount(); var tmIterator = new RegularIterator(unitsCount); var translationUnits = languageDirection.GetTranslationUnits(ref tmIterator); if (translationUnits != null) { allTusForLanguageDirections.AddRange(translationUnits); foreach (var translationUnit in translationUnits) { var sourceText = translationUnit.SourceSegment.ToPlain(); var targetText = translationUnit.TargetSegment.ToPlain(); var sourceContainsPi = pi.ContainsPi(sourceText); var targetContainsPi = pi.ContainsPi(targetText); if (sourceContainsPi || targetContainsPi) { var searchResult = new SourceSearchResult { Id = translationUnit.ResourceId.Guid.ToString(), SourceText = sourceText, TargetText = targetText, TmFilePath = tmPath, IsServer = true, SegmentNumber = translationUnit.ResourceId.Id.ToString(), SelectedWordsDetails = new List <WordDetails>(), DeSelectedWordsDetails = new List <WordDetails>(), TargetDeSelectedWordsDetails = new List <WordDetails>(), TargetSelectedWordsDetails = new List <WordDetails>() }; if (sourceContainsPi) { searchResult.IsSourceMatch = true; searchResult.MatchResult = new MatchResult { Positions = pi.GetPersonalDataPositions(sourceText) }; } if (targetContainsPi) { searchResult.IsTargetMatch = true; searchResult.TargetMatchResult = new MatchResult { Positions = pi.GetPersonalDataPositions(targetText) }; } sourceSearchResult.Add(searchResult); } //if (pi.ContainsPi(sourceText)) //{ // var searchResult = new SourceSearchResult // { // Id = translationUnit.ResourceId.Guid.ToString(), // SourceText = sourceText, // MatchResult = new MatchResult // { // Positions = pi.GetPersonalDataPositions(sourceText) // }, // TmFilePath = tmPath, // IsServer = true, // SegmentNumber = translationUnit.ResourceId.Id.ToString(), // SelectedWordsDetails = new List<WordDetails>(), // DeSelectedWordsDetails = new List<WordDetails>(), // TargetDeSelectedWordsDetails = new List<WordDetails>(), // TargetSelectedWordsDetails = new List<WordDetails>(), // IsSourceMatch = true // }; // if (pi.ContainsPi(targetText)) // { // searchResult.TargetText = targetText; // searchResult.IsTargetMatch = true; // searchResult.TargetMatchResult = new MatchResult // { // Positions = pi.GetPersonalDataPositions(targetText) // }; // } // sourceSearchResult.Add(searchResult); //} } } } }); return(new AnonymizeTranslationMemory { TmPath = tmPath, TranslationUnits = allTusForLanguageDirections, TranslationUnitDetails = new List <TranslationUnitDetails>() }); }
/// <summary> /// Gets TUs which contains PI /// </summary> /// <param name="tmPath"></param> /// <param name="sourceSearchResult">Regex search result</param> /// <param name="selectedRules">Selected rules from the grid</param> /// <returns>An object which has Tm path and a list of trasnlation units which contains PI</returns> public static AnonymizeTranslationMemory FileBaseTmGetTranslationUnits(string tmPath, ObservableCollection <SourceSearchResult> sourceSearchResult, List <Rule> selectedRules) { var tm = new FileBasedTranslationMemory(tmPath); var unitsCount = tm.LanguageDirection.GetTranslationUnitCount(); var tmIterator = new RegularIterator(unitsCount); var tus = tm.LanguageDirection.GetTranslationUnits(ref tmIterator); System.Windows.Application.Current.Dispatcher.Invoke(delegate { var pi = new PersonalInformation(selectedRules); foreach (var translationUnit in tus) { var sourceText = translationUnit.SourceSegment.ToPlain(); var targetText = translationUnit.TargetSegment.ToPlain(); var sourceContainsPi = pi.ContainsPi(sourceText); var targetContainsPi = pi.ContainsPi(targetText); if (sourceContainsPi || targetContainsPi) { var searchResult = new SourceSearchResult { Id = translationUnit.ResourceId.Guid.ToString(), SourceText = sourceText, TargetText = targetText, TmFilePath = tmPath, IsServer = false, SegmentNumber = translationUnit.ResourceId.Id.ToString(), SelectedWordsDetails = new List <WordDetails>(), DeSelectedWordsDetails = new List <WordDetails>(), TargetDeSelectedWordsDetails = new List <WordDetails>(), TargetSelectedWordsDetails = new List <WordDetails>() }; if (sourceContainsPi) { searchResult.IsSourceMatch = true; searchResult.MatchResult = new MatchResult { Positions = pi.GetPersonalDataPositions(sourceText) }; } if (targetContainsPi) { searchResult.IsTargetMatch = true; searchResult.TargetMatchResult = new MatchResult { Positions = pi.GetPersonalDataPositions(targetText) }; } sourceSearchResult.Add(searchResult); } } }); return(new AnonymizeTranslationMemory { TmPath = tmPath, TranslationUnits = tus.ToList(), TranslationUnitDetails = new List <TranslationUnitDetails>() }); }