/// <summary>
        /// Translates multiple segments, possibly using a fuzzy TM hit for improvement
        /// </summary>
        public TranslationResult[] TranslateCorrectSegment(Segment[] segs, Segment[] tmSources, Segment[] tmTargets)
        {
            TranslationResult[] results = new TranslationResult[segs.Length];
            for (int i = 0; i < segs.Length; i++)
            {
                results[i] = new TranslationResult();
            }

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

            return(results);
        }
        private async Task <LanguageDomainSupport> updateConfig(string url, string auth)
        {
            var config = new LanguageDomainSupport();

            try
            {
                // try to get Configuration
                // Do not call any blocking service in the user interface thread; it has to use background threads.
                var engineConf = await Task.Run(() => TartuNLPServiceHelper.getConfig(url, auth));

                if (engineConf == null)
                {
                    //invalid user name or password
                    config.UpdateSuccessful = false;
                }
                else
                {
                    config = loadEngineConf(engineConf);
                }
            }
            catch (Exception ex)
            {
                config.Exception = ex;
            }

            return(config);
        }
 public void StoreTranslation(TranslationUnit transunit)
 {
     try
     {
         TartuNLPServiceHelper.StoreTranslation(options, transunit.Source.PlainText, transunit.Target.PlainText, this.srcLangCode, this.trgLangCode);
     }
     catch (Exception e)
     {
         // Use the MTException class is to wrap the original exceptions occurred during the translation.
         string localizedMessage = LocalizationHelper.Instance.GetResourceString("NetworkError");
         throw new MTException(string.Format(localizedMessage, e.Message), string.Format("A network error occured ({0}).", e.Message), e);
     }
 }
        /// <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);
        }
예제 #5
0
        private async Task <LanguageDomainSupport> updateConfig(string url, string auth)
        {
            var languageDomainSupport = new LanguageDomainSupport()
            {
                URL  = url,
                Auth = auth
            };

            try
            {
                // try to get Configuration
                // Do not call any blocking service in the user interface thread; it has to use background threads.
                languageDomainSupport.JSON = await Task.Run(() => TartuNLPServiceHelper.getConfig(url, auth));

                if (languageDomainSupport.JSON == null)
                {
                    //invalid user name or password
                    languageDomainSupport.UpdateSuccessful = false;
                }
                else
                {
                    //successful login
                    languageDomainSupport.UpdateSuccessful = true;

                    //try to get the list of the Domain in the background
                    languageDomainSupport.SupportedDomains   = new Dictionary <string, string>();
                    languageDomainSupport.SupportedLanguages = new Dictionary <string, string[]>();
                    foreach (string key in languageDomainSupport.JSON.Keys)
                    {
                        languageDomainSupport.SupportedDomains.Add(languageDomainSupport.JSON[key][0], key);
                        languageDomainSupport.SupportedLanguages.Add(languageDomainSupport.JSON[key][0], languageDomainSupport.JSON[key]);
                    }
                }
            }
            catch (Exception ex)
            {
                languageDomainSupport.Exception = ex;
            }

            return(languageDomainSupport);
        }