public static TranslationResultDto CreateDto(this TranslationResult result, IReadOnlyList <string> sourceSegment) { return(new TranslationResultDto { Target = Enumerable.Range(0, result.TargetSegment.Count).Select(j => result.RecaseTargetWord(sourceSegment, j)).ToArray(), Confidences = result.TargetWordConfidences.Select(c => (float)c).ToArray(), Sources = result.TargetWordSources, Alignment = result.Alignment.CreateDto() }); }
private static TranslationResultDto CreateDto(TranslationResult result, IReadOnlyList <string> sourceSegment) { if (result == null) { return(null); } return(new TranslationResultDto { Target = Enumerable.Range(0, result.TargetSegment.Count) .Select(j => result.RecaseTargetWord(sourceSegment, j)).ToArray(), Confidences = result.WordConfidences.Select(c => (float)c).ToArray(), Sources = result.WordSources.ToArray(), Alignment = CreateDto(result.Alignment), Phrases = result.Phrases.Select(CreateDto).ToArray() }); }
public bool TryTranslate(string sourceLanguageTag, string targetLanguageTag, string projectId, IReadOnlyList <string> segment, out IReadOnlyList <string> result) { Engine engine; if (TryGetEngine(sourceLanguageTag, targetLanguageTag, projectId, out engine)) { lock (engine) { if (engine.IsDisposed) { result = null; return(false); } TranslationResult tr = engine.Translate(segment.Select(w => w.ToLowerInvariant()).ToArray()); result = Enumerable.Range(0, tr.TargetSegment.Count).Select(j => tr.RecaseTargetWord(segment, j)).ToArray(); return(true); } } result = null; return(false); }