/*public void checkExistenceOfFiles()
         * {
         *  if (this.Options.RegexFileName !="" && !File.Exists(this.Options.RegexFileName) ||
         *      this.Options.TMFileName != "" && !File.Exists(this.Options.TMFileName) ||
         *      this.Options.GlossaryFileName != "" && !File.Exists(this.Options.GlossaryFileName))
         *  {
         *      MessageBox.Show("TermInjector settings refer to files that do not exist. Check that the glossary files (if defined) and the TM have correct paths.");
         *      TermInjectorTranslationProviderConfDialog dialog = new TermInjectorTranslationProviderConfDialog(this.Options, this);
         *      if (dialog.ShowDialog() == DialogResult.OK)
         *      {
         *          this.Options = dialog.Options;
         *      }
         *      if (dialog.ShowDialog() == DialogResult.Cancel)
         *      {
         *          throw new Exception();
         *      }
         *  }
         *
         * }
         */


        public TermInjectorTranslationProvider(TermInjectorTranslationOptions options)
        {
            this.Options = options;

            //Initialize regex building objects
            this.regexTrieFactory = new RegexTrieFactory <TranslationAndReplacement>();

            this.determiniser = new Determiniser <TranslationAndReplacement>();
            this.trieLoader   = new TrieLoader(regexTrieFactory, determiniser);

            //Check that the files specified in the options exist
            //this.checkExistenceOfFiles();

            //Load tries and TM
            try
            {
                this.loadTries();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            this.loadTM();

            //Initialize the segment visitors
            this.initializeVisitors();
        }
 public TermInjectorTranslationProviderConfDialog(TermInjectorTranslationOptions options, IWin32Window owner)
 {
     this.provider = null;
     this.Options  = options;
     this.owner    = owner;
     InitializeComponent();
     UpdateDialog();
 }
예제 #3
0
 public TermInjectorTranslationProviderLanguageDirection(TermInjectorTranslationProvider provider, LanguagePair languages)
 {
     #region "Instantiate"
     _provider          = provider;
     _languageDirection = languages;
     _options           = _provider.Options;
     _matchCase         = _options.MatchCase == "true" ? true : false;
     #endregion
 }
예제 #4
0
 public TermInjectorTranslationProviderElementTermReplacementVisitor(
     TermInjectorTranslationOptions options)
 {
     _options = options;
     _segment = new Segment();
     //Create a new trie processor
     _trieProcessor = new TrieProcessing();
     //Initialize the dictionary which will contain the positions and translations
     //of terms
     _positionAndTranslationOfTerms = new List <PositionAndTranslation>();
 }
        /// <summary>
        /// Show the plug-in settings form when the user is adding the translation provider plug-in
        /// through the GUI of SDL Trados Studio
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="languagePairs"></param>
        /// <param name="credentialStore"></param>
        /// <returns></returns>
        #region "Browse"
        public ITranslationProvider[] Browse(IWin32Window owner, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            TermInjectorTranslationOptions defaultTranslationOptions = new TermInjectorTranslationOptions();

            //These are the default advanced settings, they can be changed in the dialog
            defaultTranslationOptions.TokenBoundaryCharacters = " .,!?\"'-;:(){}<>|";
            defaultTranslationOptions.TermAdditionSeparator   = "¤";
            defaultTranslationOptions.Delimiter             = "Tab";
            defaultTranslationOptions.UseBoundaryCharacters = "true";

            TermInjectorTranslationProviderConfDialog dialog = new TermInjectorTranslationProviderConfDialog(defaultTranslationOptions, owner);

            if (dialog.ShowDialog(owner) == DialogResult.OK)
            {
                if (dialog.Options.TMFileName == "")
                {
                    MessageBox.Show("Translation memory field was empty. TermInjector translation provider was not added, as it requires an underlying translation memory to function.");
                    return(null);
                }

                if (!File.Exists(dialog.Options.TMFileName))
                {
                    MessageBox.Show("Specified translation memory does not exist", "TermInjector");
                    return(null);
                }

                if (languagePairs.Length > 1)
                {
                    MessageBox.Show("TermInjector should not be used with multiple language pairs. If there are several language pairs in the project, select a language pair, select \"Use different translation providers for this language pair\" and add TermInjector as a translation provider only for the selected language pair.", "TermInjector");
                    return(null);
                }

                //Assign GUID to prevent duplicate instances
                dialog.Options.InstanceGUID = Guid.NewGuid().ToString();

                TermInjectorTranslationProvider testProvider = new TermInjectorTranslationProvider(dialog.Options);

                if (!testProvider.FileTM.SupportsLanguageDirection(languagePairs[0]))
                {
                    MessageBox.Show("Selected translation memory does not support the selected language direction ("
                                    + languagePairs[0] + "). TermInjector will not function unless a TM supporting the selected language direction is selected in the options", "TermInjector");
                    return(null);
                }


                return(new ITranslationProvider[] { testProvider });
            }



            return(null);
        }
예제 #6
0
        public TermInjectorTranslationProviderElementTermExtractionVisitor(
            TermInjectorTranslationOptions options,
            Trie glossaryTrie,
            RegexTrie <TranslationAndReplacement> regexTrie)
        {
            _options       = options;
            _trieProcessor = new TrieProcessing();
            _trie          = glossaryTrie;

            //Initialize the regex trie
            _regexTrie = regexTrie;

            _TermList = new List <PositionAndTranslation>();
        }
 private void btn_reload_Click(object sender, EventArgs e)
 {
     //Reload the tries
     if (this.provider != null)
     {
         this.provider.Options = this.Options;
         //this.provider.checkExistenceOfFiles();
         try
         {
             this.provider.loadTries();
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
         this.provider.initializeVisitors();
     }
 }
예제 #8
0
 public TermInjectorTranslationProviderElementTermReplacementVisitor(
     TermInjectorTranslationOptions options,
     Trie glossaryTrie,
     RegexTrie <TranslationAndReplacement> regexTrie)
 {
     _options = options;
     _segment = new Segment();
     //Initialize the glossary trie
     _trie = glossaryTrie;
     //Initialize the regex trie
     _regexTrie = regexTrie;
     //Create a new trie processor
     _trieProcessor = new TrieProcessing();
     //Initialize the dictionary which will contain the positions and translations
     //of terms
     _positionAndTranslationOfTerms = new List <PositionAndTranslation>();
     //Boolean for indicating whether the original segment has been changed
     _originalSegmentChanged = false;
 }
예제 #9
0
        public ITranslationProvider CreateTranslationProvider(Uri translationProviderUri, string translationProviderState, ITranslationProviderCredentialStore credentialStore)
        {
            var createOptions = new TermInjectorTranslationOptions(translationProviderUri);

            if (createOptions.UseBoundaryCharacters == null)
            {
                createOptions.UseBoundaryCharacters = "true";
            }
            if (createOptions.InstanceGUID == null)
            {
                createOptions.InstanceGUID = Guid.NewGuid().ToString();
            }
            TermInjectorTranslationProvider tp;

            //Don't create the provider if it is already active
            if (activeProviders.ContainsKey(createOptions.InstanceGUID))
            {
                if (activeProviders[createOptions.InstanceGUID] != null)
                {
                    return(activeProviders[createOptions.InstanceGUID]);
                }
                else
                {
                    tp = new TermInjectorTranslationProvider(new TermInjectorTranslationOptions(translationProviderUri));
                    activeProviders[createOptions.InstanceGUID] = tp;
                    return(tp);
                }
            }
            if (!SupportsTranslationProviderUri(translationProviderUri))
            {
                throw new Exception("Cannot handle URI.");
            }
            //if (TermInjectorTranslationProviderFactory.activeProviders.ContainsKey(translationProviderUri.

            //Uri has not been added
            tp = new TermInjectorTranslationProvider(new TermInjectorTranslationOptions(translationProviderUri));
            activeProviders.Add(createOptions.InstanceGUID, tp);
            return(tp);
        }