Exemple #1
0
        /// <summary>
        /// Translates multiple segments, possibly using a fuzzy TM hit for improvement
        /// </summary>
        public TranslationResult[] TranslateCorrectSegment(Segment[] segments, Segment[] tmSources, Segment[] tmTargets)
        {
            var results = new TranslationResult[segments.Length];

            for (var i = 0; i < segments.Length; i++)
            {
                results[i] = new TranslationResult();
            }

            try
            {
                var texts = segments.Select(s => createTextFromSegment(s, options.GeneralSettings.FormattingAndTagUsage)).ToList();
                var i     = 0;
                foreach (var translation in TartuNLPServiceHelper.Translate(options, texts, srcLangCode, trgLangCode))
                {
                    results[i].Translation = createSegmentFromResult(segments[i], translation, options.GeneralSettings.FormattingAndTagUsage);
                    i++;
                }
            }
            catch (Exception e)
            {
                // Use the MTException class is to wrap the original exceptions occurred during the translation.
                foreach (var result in results)
                {
                    result.Exception = new MTException(e.Message, e.Message, e);
                }
            }

            return(results);
        }
        /// <summary>
        /// Translates a single segment, possibly using a fuzzy TM hit for improvement
        /// </summary>
        public TranslationResult TranslateCorrectSegment(Segment segm, Segment tmSource, Segment tmTarget)
        {
            TranslationResult result = new TranslationResult();

            try
            {
                string textToTranslate = createTextFromSegment(segm, options.GeneralSettings.FormattingAndTagUsage);
                string translation     = TartuNLPServiceHelper.Translate(options, textToTranslate, this.srcLangCode, this.trgLangCode);
                result.Translation = createSegmentFromResult(segm, translation, options.GeneralSettings.FormattingAndTagUsage);
            }
            catch (Exception e)
            {
                // Use the MTException class is to wrap the original exceptions occurred during the translation.
                string localizedMessage = LocalizationHelper.Instance.GetResourceString("NetworkError");
                result.Exception = new MTException(string.Format(localizedMessage, e.Message), string.Format("A network error occured ({0}).", e.Message), e);
            }

            return(result);
        }