private SearchResult CreateSearchResult(Segment segment, Segment translation) { var tu = new TranslationUnit { SourceSegment = segment.Duplicate(), //this makes the original source segment, with tags, appear in the search window TargetSegment = translation }; tu.ResourceId = new PersistentObjectToken(tu.GetHashCode(), Guid.Empty); const int score = 0; //score to 0...change if needed to support scoring tu.Origin = TranslationUnitOrigin.MachineTranslation; var searchResult = new SearchResult(tu) { ScoringResult = new ScoringResult { BaseScore = score } }; tu.ConfirmationLevel = ConfirmationLevel.Draft; return(searchResult); }
public SearchResult CreateSearchResult(WordItem word, string sourceSegmentText) { var searchSegment = new Segment(_sourceLanguage); searchSegment.Add(sourceSegmentText); var translationSegment = new Segment(_targetLanguage); translationSegment.Add(word.Word); var unit = new TranslationUnit { SourceSegment = searchSegment, TargetSegment = translationSegment, ConfirmationLevel = ConfirmationLevel.Translated, Origin = TranslationUnitOrigin.MachineTranslation }; unit.ResourceId = new PersistentObjectToken(unit.GetHashCode(), Guid.Empty); var searchResult = new SearchResult(unit); // We do not currently support scoring, so always say that we're 25% sure on this translation. searchResult.ScoringResult = new ScoringResult() { BaseScore = 25 }; return(searchResult); }
private SearchResult CreateSearchResult(Segment segment, Segment translation) { #region "TranslationUnit" var tu = new TranslationUnit { SourceSegment = segment.Duplicate(), //this makes the original source segment, with tags, appear in the search window TargetSegment = translation }; #endregion "TranslationUnit" tu.ResourceId = new PersistentObjectToken(tu.GetHashCode(), Guid.Empty); //maybe this we need to add the score which Christine requested // var score = 0; //score to 0...change if needed to support scoring tu.Origin = TranslationUnitOrigin.Nmt; var searchResult = new SearchResult(tu) { TranslationProposal = new TranslationUnit(tu), ScoringResult = new ScoringResult { BaseScore = score } }; tu.ConfirmationLevel = ConfirmationLevel.Draft; return(searchResult); }
private SearchResult CreateSearchResult(Segment segment, TartuNLPTagPlacer tagPlacer, string translation) { var targetSegment = tagPlacer.GetTaggedSegment(translation); // handle cases where input and output tags did not match if (targetSegment == null) { var sourceStrings = new List <string> { segment.ToPlain() }; translation = SearchInServer(sourceStrings)[0]; targetSegment = new Segment(_languageDirection.TargetCulture); targetSegment.Add(translation); } var translationUnit = new TranslationUnit { SourceSegment = segment.Duplicate(), TargetSegment = targetSegment }; translationUnit.ResourceId = new PersistentObjectToken(translationUnit.GetHashCode(), Guid.Empty); translationUnit.Origin = TranslationUnitOrigin.MachineTranslation; var searchResult = new SearchResult(translationUnit) { ScoringResult = new ScoringResult() }; return(searchResult); }
/// Creates the translation unit as it is later shown in the Translation Results /// window of SDL Trados Studio. #region "CreateSearchResult" private SearchResult CreateSearchResult(Segment searchSegment, Segment translation) { #region "TranslationUnit" TranslationUnit tu = new TranslationUnit(); Segment orgSegment = searchSegment; tu.SourceSegment = orgSegment; tu.TargetSegment = translation; #endregion tu.ResourceId = new PersistentObjectToken(tu.GetHashCode(), Guid.Empty); #region "TuProperties" int score = _options.NewSegmentPercentage; tu.Origin = TranslationUnitOrigin.TM; SearchResult searchResult = new SearchResult(tu); searchResult.TranslationProposal = tu; searchResult.ScoringResult = new ScoringResult(); searchResult.ScoringResult.BaseScore = score; tu.ConfirmationLevel = ConfirmationLevel.Unspecified; #endregion return(searchResult); }
private SearchResult CreateSearchResult(TmxMallSegmenter segmenter, TranslationResult result, bool formattingPenalty) { TranslationUnit translationUnit = new TranslationUnit(); //付加 测试 //result.Source = "<g id=\"149\">▶</g>前三句点明了时间、地点和特定环境,抒情主人公在深秋时节,独自一人伫立在橘子洲头,望着湘江水向北奔流不息。"; //result.Translation = "<g id=\"149\">▶</g>The first three sentences clarify the time, place and specific environment. In the late autumn, the lyrical protagonist stands alone in the head of Orange Island and looks at the Xiangjiang River running northward."; translationUnit.SourceSegment = segmenter.AsSegment(result.Source); translationUnit.SourceSegment.Culture = this._languages.SourceCulture; translationUnit.TargetSegment = segmenter.AsSegment(result.Translation.Replace("\\\"", "\"")); translationUnit.TargetSegment.Culture = this._languages.TargetCulture; translationUnit.ResourceId = new PersistentObjectToken(translationUnit.GetHashCode(), Guid.Empty); translationUnit.Origin = TranslationUnitOrigin.TM; bool flag = !string.IsNullOrEmpty(result.Createdby); if (flag) { translationUnit.FieldValues.Add(new SingleStringFieldValue(result.Createdby, result.TmName)); } bool isMTMatch = result.IsMTMatch; if (isMTMatch) { translationUnit.Origin = TranslationUnitOrigin.MachineTranslation; } else { translationUnit.Origin = TranslationUnitOrigin.TM; } translationUnit.SystemFields.CreationDate = DateTime.Now; translationUnit.SystemFields.CreationUser = result.Createdby; translationUnit.SystemFields.ChangeDate = DateTime.Now; translationUnit.SystemFields.ChangeUser = result.Createdby; translationUnit.SystemFields.UseCount = 1; translationUnit.SystemFields.UseDate = DateTime.Now; translationUnit.SystemFields.UseUser = result.Createdby; SearchResult searchResult = new SearchResult(translationUnit); searchResult.ScoringResult = new ScoringResult(); searchResult.ScoringResult.BaseScore = (int)(result.Match * 100f); if (formattingPenalty) { translationUnit.ConfirmationLevel = ConfirmationLevel.Translated; Penalty penalty = new Penalty(PenaltyType.TagMismatch, 1); searchResult.ScoringResult.ApplyPenalty(penalty); } else { translationUnit.ConfirmationLevel = ConfirmationLevel.Translated; } searchResult.TranslationProposal = translationUnit; return(searchResult); }
private SearchResult CreateSearchResult(Segment segment, Segment translation) { TranslationUnit tu = new TranslationUnit(); tu.SourceSegment = segment.Duplicate(); tu.TargetSegment = translation; tu.ResourceId = new PersistentObjectToken(tu.GetHashCode(), Guid.Empty); tu.Origin = TranslationUnitOrigin.MachineTranslation; SearchResult searchResult = new SearchResult(tu); searchResult.ScoringResult = new ScoringResult(); return(searchResult); }
/// <summary> /// Creates the translation unit as it is later shown in the Translation Results /// window of SDL Trados Studio. /// </summary> /// <param name="searchSegment"></param> /// <param name="translation"></param> /// <param name="sourceSegment"></param> /// <param name="formattingPenalty"></param> /// <returns></returns> #region "CreateSearchResult" private SearchResult CreateSearchResult(Segment searchSegment, Segment translation, bool formattingPenalty, string mtSystem) { TranslationUnit tu = new TranslationUnit(); tu.SourceSegment = searchSegment; tu.TargetSegment = translation; //There might be some problematic tags after the tag stack treatment, this should //handle those. //TODO: Ideally the tag issues would be resolved already in the NMT decoder, i.e. only //insertion of matched tags would be allowed. var error = tu.Validate(Segment.ValidationMode.ReportAllErrors); //This is a fallback for tag errors if (!error.HasFlag(ErrorCode.OK)) { tu.TargetSegment.DeleteTags(); } OpusCatProviderLanguageDirection.CurrentTranslation = tu.TargetSegment; tu.ResourceId = new PersistentObjectToken(tu.GetHashCode(), Guid.Empty); tu.FieldValues.Add(new SingleStringFieldValue("mtSystem", mtSystem)); if (this._options.showMtAsOrigin) { #if TRADOS21 tu.Origin = TranslationUnitOrigin.Nmt; #else tu.Origin = TranslationUnitOrigin.MachineTranslation; #endif } else { tu.Origin = TranslationUnitOrigin.Unknown; } SearchResult searchResult = new SearchResult(tu); searchResult.ScoringResult = new ScoringResult(); return(searchResult); }
private SearchResult CreateSearchResult(Segment segment, Segment translation, string v) { #region "TranslationUnit" var tu = new TranslationUnit(); tu.SourceSegment = segment.Duplicate();//this makes the original source segment, with tags, appear in the search window tu.TargetSegment = translation; #endregion tu.ResourceId = new PersistentObjectToken(tu.GetHashCode(), Guid.Empty); var score = 0; //score to 0...change if needed to support scoring tu.Origin = TranslationUnitOrigin.MachineTranslation; var searchResult = new SearchResult(tu); searchResult.ScoringResult = new ScoringResult(); searchResult.ScoringResult.BaseScore = score; tu.ConfirmationLevel = ConfirmationLevel.Draft; return searchResult; }
/// <summary> /// Creates the translation unit as it is later shown in the Translation Results /// window of SDL Trados Studio. This member also determines the match score /// (in our implementation always 100%, as only exact matches are supported) /// as well as the confirmation level, i.e. Translated. /// </summary> /// <param name="searchSegment"></param> /// <param name="translation"></param> /// <param name="sourceSegment"></param> /// <returns></returns> #region "CreateSearchResult" private SearchResult CreateSearchResult(Segment searchSegment, Segment translation, string sourceSegment, bool formattingPenalty) { #region "TranslationUnit" TranslationUnit tu = new TranslationUnit(); Segment orgSegment = new Segment(); orgSegment.Add(sourceSegment); tu.SourceSegment = orgSegment; tu.TargetSegment = translation; #endregion tu.ResourceId = new PersistentObjectToken(tu.GetHashCode(), Guid.Empty); #region "TuProperties" int score = 100; tu.Origin = TranslationUnitOrigin.TM; SearchResult searchResult = new SearchResult(tu) { ScoringResult = new ScoringResult() }; searchResult.ScoringResult.BaseScore = score; if (formattingPenalty) { #region "Draft" tu.ConfirmationLevel = ConfirmationLevel.Draft; #endregion #region "FormattingPenalty" Penalty penalty = new Penalty(PenaltyType.TagMismatch, 1); searchResult.ScoringResult.ApplyPenalty(penalty); #endregion } else { tu.ConfirmationLevel = ConfirmationLevel.Translated; } #endregion return(searchResult); }
private SearchResult CreateSearchResult(Segment segment, TartuNLPTagPlacer tagPlacer, string translation) { var targetSegment = tagPlacer.GetTaggedSegment(translation); var translationUnit = new TranslationUnit { SourceSegment = segment.Duplicate(), TargetSegment = targetSegment }; translationUnit.ResourceId = new PersistentObjectToken(translationUnit.GetHashCode(), Guid.Empty); translationUnit.Origin = TranslationUnitOrigin.MachineTranslation; var searchResult = new SearchResult(translationUnit) { ScoringResult = new ScoringResult() }; return(searchResult); }
/// <summary> /// Creates a consumable SearchResult using the source segment and translated segment /// </summary> /// <param name="searchSegment"></param> /// <param name="translation"></param> /// <param name="sourceSegment"></param> /// <returns></returns> private static SearchResult CreateSearchResult(Segment searchSegment, Segment translation) { Log.logger.Trace(""); TranslationUnit unit = new TranslationUnit(); unit.SourceSegment = searchSegment; unit.TargetSegment = translation; unit.ConfirmationLevel = ConfirmationLevel.Translated; unit.ResourceId = new PersistentObjectToken(unit.GetHashCode(), Guid.Empty); unit.Origin = TranslationUnitOrigin.MachineTranslation; SearchResult searchResult = new SearchResult(unit); // We do not currently support scoring, so always say that we're 25% sure on this translation. searchResult.ScoringResult = new ScoringResult() { BaseScore = 25 }; return(searchResult); }
/// <summary> /// Creates the translation unit as it is later shown in the Translation Results /// window of SDL Trados Studio. /// </summary> /// <param name="searchSegment"></param> /// <param name="translation"></param> /// <param name="sourceSegment"></param> /// <returns></returns> #region "CreateSearchResult" private SearchResult CreateSearchResult(Segment searchSegment, Segment translation, int score) { TranslationUnit tu = new TranslationUnit(); tu.SourceSegment = searchSegment.Duplicate(); tu.TargetSegment = translation; tu.ResourceId = new PersistentObjectToken(tu.GetHashCode(), Guid.Empty); tu.Origin = TranslationUnitOrigin.MachineTranslation; //tu.SystemFields.CreationDate = DateTime.UtcNow; //tu.SystemFields.ChangeDate = tu.SystemFields.CreationDate; SearchResult searchResult = new SearchResult(tu); searchResult.ScoringResult = new ScoringResult(); searchResult.TranslationProposal = tu.Duplicate(); searchResult.ScoringResult.BaseScore = score; return(searchResult); }
public SearchResults[] SearchSegmentsMasked(SearchSettings settings, Segment[] segments, bool[] mask) { IEnumerable <Segment> toTranslate = mask != null?segments.Where((x, i) => mask[i]) : segments; List <string> sources = toTranslate.Select(x => x.ToHtml()).ToList(); List <string> translations; try { translations = _client.Translate(sources, src, trg).Result; } catch (AggregateException e) { var apiException = e.InnerException as SimpleHttpResponseException <GenericResponse> ?? throw e.InnerException; if (apiException.StatusCode == System.Net.HttpStatusCode.Unauthorized) { throw new TranslationProviderAuthenticationException("Invalid Consumer API Token", apiException); } throw new Exception($"{apiException.Content.Error.Message} ({apiException.Content.Error.Code})"); } IEnumerable <SearchResults> nonMaskedResults = toTranslate.Zip(translations, // Converting a translation string to SearchResults is quite involved (Segment sourceSegment, string translation) => { var targetSegment = translation.ToSegment(sourceSegment); var tu = new TranslationUnit(sourceSegment.Duplicate(), targetSegment); tu.Origin = TranslationUnitOrigin.MachineTranslation; tu.ResourceId = new PersistentObjectToken(tu.GetHashCode(), Guid.Empty); // TODO: is this needed? var res = new SearchResult(tu) { TranslationProposal = tu.Duplicate(), ScoringResult = new ScoringResult() { BaseScore = 85 } // Although we do not support scoring, returning some kind of a score is mandatory, else Trados freezes }; var results = new SearchResults { SourceSegment = sourceSegment.Duplicate() }; results.Add(res); return(results); }); IEnumerable <SearchResults> allResults() { var enumerator = nonMaskedResults.GetEnumerator(); foreach (var item in segments.Select((value, i) => new { i, value })) { if (mask == null || mask[item.i]) { enumerator.MoveNext(); yield return(enumerator.Current); continue; } yield return(null); } } var resArray = allResults().ToArray(); return(resArray); }
private SearchResult CreateSearchResult(Segment searchSegment, Segment translation, string sourceSegment) { #region "TranslationUnit" TranslationUnit tu = new TranslationUnit(); tu.SourceSegment = searchSegment.Duplicate();//this makes the original source segment, with tags, appear in the search window tu.TargetSegment = translation; #endregion tu.ResourceId = new PersistentObjectToken(tu.GetHashCode(), Guid.Empty); int score = 0; //score to 0...change if needed to support scoring tu.Origin = TranslationUnitOrigin.MachineTranslation; SearchResult searchResult = new SearchResult(tu); searchResult.ScoringResult = new ScoringResult(); searchResult.ScoringResult.BaseScore = score; tu.ConfirmationLevel = ConfirmationLevel.Draft; return searchResult; }
/// <summary> /// Creates the translation unit as it is later shown in the Translation Results /// window of SDL Trados Studio. This member also determines the match score /// (in our implementation always 100%, as only exact matches are supported) /// as well as the confirmation lelvel, i.e. Translated. /// </summary> /// <param name="settings"></param> /// <param name="searchSegment"></param> /// <param name="searchResultSegment"></param> /// <param name="sourceSegment"></param> /// <param name="formattingPenalty"></param> /// <returns></returns> #region "CreateSearchResult" private SearchResult CreateSearchResult(SearchSettings settings, Segment searchSegment, Sdl.Community.Taus.TM.Provider.Segment.Segment searchResultSegment, string sourceSegment, bool formattingPenalty) { #region "TranslationUnit" var tu = new TranslationUnit(); var searchSegmentSource = new Segment(); var searchSegmentTarget = new Segment(); searchSegmentSource.Add(searchResultSegment.SourceText); searchSegmentTarget.Add(searchResultSegment.TargetText); tu.SourceSegment = searchSegmentSource; tu.TargetSegment = searchSegmentTarget; tu.ResourceId = new PersistentObjectToken(tu.GetHashCode(), Guid.Empty); #endregion #region "TuProperties" var score = Convert.ToInt32(searchResultSegment.MatchPercentage); tu.Origin = TranslationUnitOrigin.TM; #region | properties | if (searchResultSegment.Industry.Name.Trim() != string.Empty) { var fieldValue = new MultiplePicklistFieldValue("industry"); fieldValue.Add(searchResultSegment.Industry.Name + " [" + searchResultSegment.Industry.Id + "]"); tu.FieldValues.Add(fieldValue); } if (searchResultSegment.ContentType.Name.Trim() != string.Empty) { var fieldValue = new MultiplePicklistFieldValue("contentType"); fieldValue.Add(searchResultSegment.ContentType.Name + " [" + searchResultSegment.ContentType.Id + "]"); tu.FieldValues.Add(fieldValue); } if (searchResultSegment.Owner.Name.Trim() != string.Empty) { var fieldValue = new MultiplePicklistFieldValue("owner"); fieldValue.Add(searchResultSegment.Owner.Name + " [" + searchResultSegment.Owner.Id + "]"); tu.FieldValues.Add(fieldValue); } if (searchResultSegment.Product.Name.Trim() != string.Empty) { var fieldValue = new MultiplePicklistFieldValue("product"); fieldValue.Add(searchResultSegment.Product.Name + " [" + searchResultSegment.Product.Id + "]"); tu.FieldValues.Add(fieldValue); } if (searchResultSegment.Provider.Name.Trim() != string.Empty) { var fieldValue = new MultiplePicklistFieldValue("provider"); fieldValue.Add(searchResultSegment.Provider.Name + " [" + searchResultSegment.Provider.Id + "]"); tu.FieldValues.Add(fieldValue); } #endregion var searchResult = new SearchResult(tu) { ScoringResult = new ScoringResult { BaseScore = score } }; if (settings.Mode == SearchMode.ConcordanceSearch) { searchSegmentSource.Tokens = Tokenize(searchSegmentSource); searchResult.ScoringResult.MatchingConcordanceRanges = CollectConcordanceMatchRanges(searchSegmentSource, _visitor.PlainText); } else if (settings.Mode == SearchMode.TargetConcordanceSearch) { searchSegmentTarget.Tokens = Tokenize(searchSegmentTarget); searchResult.ScoringResult.MatchingConcordanceRanges = CollectConcordanceMatchRanges(searchSegmentTarget, _visitor.PlainText); } var providerPenalty = settings.FindPenalty(PenaltyType.ProviderPenalty); if (providerPenalty != null && providerPenalty.Malus > 0) { var penalty = new Penalty(PenaltyType.ProviderPenalty, settings.FindPenalty(PenaltyType.ProviderPenalty).Malus); searchResult.ScoringResult.ApplyPenalty(penalty); } if (searchResult.ScoringResult.BaseScore >= settings.MinScore) { searchResult.TranslationProposal = searchResult.MemoryTranslationUnit; if (searchSegment.HasTags) { #region "Draft" tu.ConfirmationLevel = ConfirmationLevel.Draft; #endregion #region "FormattingPenalty" var penalty = new Penalty(PenaltyType.MemoryTagsDeleted, settings.FindPenalty(PenaltyType.MemoryTagsDeleted).Malus); searchResult.ScoringResult.ApplyPenalty(penalty); #endregion } else { tu.ConfirmationLevel = ConfirmationLevel.Translated; } } else { searchResult = null; } #endregion return(searchResult); }