Пример #1
0
        protected override void OnInitializeTask()
        {
            var fileLanguageDirections = TaskFiles.Select(x => x.GetLanguageDirection().TargetLanguage.IsoAbbreviation).Distinct();

            if (fileLanguageDirections.Count() > 1)
            {
                throw new Exception(
                          $"This batch task can only be applied to one language direction at a time. Select only files with same language direction and try again.");
            }
            else if (fileLanguageDirections.Count() == 0)
            {
                throw new Exception(
                          $"No target files selected.");
            }
            this.collectedSentencePairCount = 0;
            this.settings       = GetSetting <FinetuneBatchTaskSettings>();
            this.opusCatOptions = new OpusCatOptions(new Uri(this.settings.ProviderOptions));

            //Use project guid in case no model tag specified
            if (this.opusCatOptions.modelTag == "")
            {
                this.opusCatOptions.modelTag = this.Project.GetProjectInfo().Id.ToString();
            }

            //Get instances of the translation memories included in the project.
            this.tms = this.InstantiateProjectTms();

            this.ProjectTranslations = new Dictionary <Language, List <Tuple <string, string> > >();
            this.ProjectNewSegments  = new Dictionary <Language, List <string> >();
            this.ProjectFuzzies      = new Dictionary <Language, List <TranslationUnit> >();
            this.sourceVisitor       = new OpusCatProviderElementVisitor();
            this.targetVisitor       = new OpusCatProviderElementVisitor();
            base.OnInitializeTask();
        }
Пример #2
0
        /// <summary>
        /// Stores multiple string pairs as translation with the help of the dummy MT service.
        /// </summary>
        /// <param name="tokenCode">The token code.</param>
        /// <param name="sources">The source strings.</param>
        /// <param name="targets">The target strings.</param>
        /// <param name="srcLangCode">The source language code.</param>
        /// <param name="trgLangCode">The target language code.</param>
        /// <returns>The indices of the translation units that were succesfully stored.</returns>
        public static int[] BatchStoreTranslation(OpusCatOptions options, List <string> sources, List <string> targets, string srcLangCode, string trgLangCode)
        {
            // Always dispose allocated resources
            var proxy = getNewProxy(options.mtServiceAddress, options.mtServicePort);

            try
            {
                using (proxy as IDisposable)
                {
                    return(proxy.BatchStoreTranslation(GetTokenCode(options), sources, targets, srcLangCode, trgLangCode));
                }
            }
            catch (Exception ex) when(ex.InnerException is SocketException)
            {
                throw new OpusCatEngineConnectionException("OPUS-CAT MT Engine cannot be connected to. Check that the OPUS-CAT MT Engine has been installed and is running. See OPUS-CAT online help for details.", ex);
            }
            catch (Exception ex) when(ex is EndpointNotFoundException || ex is CommunicationObjectFaultedException)
            {
                throw new OpusCatEngineConnectionException("OPUS-CAT MT Engine cannot be connected to. Check that the OPUS-CAT MT Engine has been installed and is running. See OPUS-CAT online help for details.", ex);
            }
            catch (Exception ex)
            {
                //If the server throws an previously unseen exception, this will probably catch it.
                //This is here mainly for future debugging, no exceptions of this type are currently thrown.
                throw ex;
            }
        }
Пример #3
0
 private void ConnectionControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
 {
     if (e.NewValue is IHasOpusCatOptions)
     {
         this.options = ((IHasOpusCatOptions)e.NewValue).Options;
         PropertyChanged(this, new PropertyChangedEventArgs(null));
     }
 }
        /// <summary>
        /// Instantiates the variables and fills the list file content into
        /// a Dictionary collection object.
        /// </summary>
        /// <param name="provider"></param>
        /// <param name="languages"></param>
        #region "ListTranslationProviderLanguageDirection"
        public OpusCatProviderLanguageDirection(OpusCatProvider provider, LanguagePair languages)
        {
            #region "Instantiate"

            _provider          = provider;
            _languageDirection = languages;
            _options           = _provider.Options;

            _visitor = new OpusCatProviderElementVisitor();

            var sourceCode = this._languageDirection.SourceCulture.TwoLetterISOLanguageName;
            var targetCode = this._languageDirection.TargetCulture.TwoLetterISOLanguageName;
            this.langpair = $"{sourceCode}-{targetCode}";

            #endregion
        }
Пример #5
0
        public OpusCatOptionControl(OpusCatOptionsFormWPF hostForm, OpusCatOptions options, Sdl.LanguagePlatform.Core.LanguagePair[] languagePairs)
        {
            this.DataContext = this;

            this.Options = options;
            this.projectLanguagePairs = languagePairs.Select(
                x => $"{x.SourceCulture.TwoLetterISOLanguageName}-{x.TargetCulture.TwoLetterISOLanguageName}").ToList();

            InitializeComponent();
            this.ConnectionControl.LanguagePairs = this.projectLanguagePairs;

            //Null indicates that all properties have changed. Populates the WPF form
            PropertyChanged(this, new PropertyChangedEventArgs(null));

            this.hostForm = hostForm;
        }
Пример #6
0
        public OpusCatProvider(OpusCatOptions options)
        {
            //TODO: add some kind of throttling here or to Helper to prevent the service being overwhelmed by requests.
            //Just keep a count of open connections and prevent connections when there are more than 100 or so.
            Options = options;

            //If we create a provider with the pregenerate on, add a doc change handler to start preordering
            //MT when doc is changed
            if (options.pregenerateMt)
            {
                EditorController editorController = SdlTradosStudio.Application.GetController <EditorController>();
                //This should ensure the handler is only attached once, by always removing a possible previously
                //added handler before adding the new one
                editorController.ActiveDocumentChanged -= OpusCatProvider.DocChanged;
                editorController.ActiveDocumentChanged += OpusCatProvider.DocChanged;

                //If a document is open, check if the segment change handler should be added
                OpusCatProvider.UpdateSegmentHandler();
            }
        }
Пример #7
0
        public FinetuneWpfControl(FinetuneBatchTaskSettings Settings)
        {
            this.DataContext = this;

            //Settings is the object that is passed on to the batch task.
            this.Settings = Settings;
            //Mode defaults, changeable with radio buttons
            this.Settings.Finetune = true;
            this.Settings.PreOrderMtForNewSegments = true;
            //Some settings are initially held in a OpusCatOptions object (the shared properties
            //with the translation provider settings).
            this.Options = new OpusCatOptions();
            //Whenever the options change, also update the option URI string in settings
            this.Options.PropertyChanged += Options_PropertyChanged;
            InitializeComponent();
            this.TagBox.ItemsSource = new ObservableCollection <string>()
            {
                "<new tag>"
            };
        }
Пример #8
0
        public OpusCatProvider(OpusCatOptions options, ITranslationProviderCredentialStore credentialStore)
        {
            Options = options;

            //If we create a provider with the pregenerate on, add a doc change handler to start preordering
            //MT when doc is changed
            if (options.pregenerateMt && options.opusCatSource == OpusCatOptions.OpusCatSource.OpusCatMtEngine)
            {
                EditorController editorController = SdlTradosStudio.Application.GetController <EditorController>();
                //This should ensure the handler is only attached once, by always removing a possible previously
                //added handler before adding the new one
                editorController.ActiveDocumentChanged -= OpusCatProvider.DocChanged;
                editorController.ActiveDocumentChanged += OpusCatProvider.DocChanged;

                //If a document is open, check if the segment change handler should be added
                OpusCatProvider.UpdateSegmentHandler();
            }

            if (this.Options.opusCatSource == OpusCatOptions.OpusCatSource.Elg)
            {
                OpusCatProvider.ElgConnection = new ElgServiceConnection(new TradosElgCredentialWrapper(credentialStore));
            }
        }
Пример #9
0
        //THIS IS DEPRECATED, REPLACED WITH SEGMENT CHANGE HANDLER EVENT
        //This function starts translating all segments in the document once the document is opened,
        //so that the translator won't have to wait for the translation to finish when opening a segment.
        //Note that Studio contains a feature called LookAhead which attempts to do a similar thing, but
        //LookAhead appears to be buggy with TMs etc., so it's better to rely on a custom caching system.
        private static void TranslateDocumentSegments(Document doc, LanguageDirection langPair, OpusCatOptions options)
        {
            var visitor = new OpusCatMarkupDataVisitor();
            EditorController editorController = SdlTradosStudio.Application.GetController <EditorController>();

            foreach (var segmentPair in doc.SegmentPairs)
            {
                if (segmentPair.Properties.ConfirmationLevel == Sdl.Core.Globalization.ConfirmationLevel.Unspecified)
                {
                    visitor.Reset();
                    segmentPair.Source.AcceptVisitor(visitor);
                    var sourceText = visitor.PlainText;

                    var sourceCode = langPair.SourceLanguage.CultureInfo.TwoLetterISOLanguageName;
                    var targetCode = langPair.TargetLanguage.CultureInfo.TwoLetterISOLanguageName;
                    var langpair   = $"{sourceCode}-{targetCode}";

                    //This will generate the translation and cache it for later use
                    OpusCatMTServiceHelper.Translate(options, sourceText, sourceCode, targetCode, options.modelTag);
                }
            }

            //processedDocuments[langPair].Add(doc);
        }
Пример #10
0
 public OpusCatOptionsFormWPF(OpusCatOptions options, Sdl.LanguagePlatform.Core.LanguagePair[] languagePairs, Sdl.LanguagePlatform.TranslationMemoryApi.ITranslationProviderCredentialStore credentialStore)
 {
     this.Options = options;
     InitializeComponent();
     this.wpfHost.Child = new OpusCatOptionControl(this, options, languagePairs, credentialStore);
 }
Пример #11
0
 public OpusCatOptionsFormWPF(OpusCatOptions options, Sdl.LanguagePlatform.Core.LanguagePair[] languagePairs)
 {
     this.Options = options;
     InitializeComponent();
     this.wpfHost.Child = new OpusCatOptionControl(this, options, languagePairs);
 }
Пример #12
0
 public static List <string> GetLanguagePairModelTags(OpusCatOptions options, string srcLangCode, string trgLangCode)
 {
     return(OpusCatMTServiceHelper.GetLanguagePairModelTags(options.mtServiceAddress, options.mtServicePort, srcLangCode, trgLangCode));
 }
Пример #13
0
 public static List <string> ListSupportedLanguages(OpusCatOptions options)
 {
     return(ListSupportedLanguages(GetTokenCode(options), options.mtServiceAddress, options.mtServicePort));
 }
Пример #14
0
 public static string GetTokenCode(OpusCatOptions options)
 {
     return(OpusCatMTServiceHelper.GetTokenCode(options.mtServiceAddress, options.mtServicePort));
 }