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); }
public SearchResults SearchSegment(SearchSettings settings, Segment segment) { SearchResults result; try { string plainTextFromSegment = this.GetPlainTextFromSegment(segment, false); List <TranslationResult> list = this._translationClient.Translate(plainTextFromSegment); SearchResults searchResults = new SearchResults(); searchResults.SourceSegment = segment.Duplicate(); TmxMallSegmenter segmenter = new TmxMallSegmenter(segment); foreach (TranslationResult current in list) { searchResults.Add(this.CreateSearchResult(segmenter, current, segment.HasTags)); } result = searchResults; } catch { result = null; } return(result); }