public FiskmoConfDialog(FiskmoOptions options, Sdl.LanguagePlatform.Core.LanguagePair[] languagePairs) { string sourceLang = languagePairs[0].SourceCulture.TwoLetterISOLanguageName.ToLower(); string targetLang = languagePairs[0].TargetCulture.TwoLetterISOLanguageName.ToLower(); this.modelManager = new ModelManager(); Options = options; InitializeComponent(); string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); this.aboutBox.LoadFile(Path.Combine(assemblyFolder, "LICENSE.rtf")); /*Add code for disabling form if language pair is not correct, in case it's needed. * if (!((sSourceCulture == "fi" || sSourceCulture == "sv") && (sSourceCulture == "fi" || sSourceCulture == "sv")))) * { * this.DisableAll(); * }*/ //If no model is loaded, deactivate Save button var existingModel = this.modelManager.GetLatestModelDir(sourceLang, targetLang); if (existingModel == null) { this.infoBox.AppendText($"No local model for language pair {sourceLang}-{targetLang}."); this.Save_btn.Enabled = false; } else { var existingModelName = new DirectoryInfo(existingModel).Name; this.infoBox.AppendText($"Local model for the language pair {sourceLang}-{targetLang} is "); this.infoBox.SelectionFont = new System.Drawing.Font(this.infoBox.Font, System.Drawing.FontStyle.Bold); this.infoBox.AppendText(existingModelName); this.infoBox.SelectionFont = new System.Drawing.Font(this.infoBox.Font, System.Drawing.FontStyle.Regular); this.infoBox.AppendText("." + Environment.NewLine); this.Save_btn.Enabled = true; } this.newerModel = this.modelManager.CheckForNewerModel(sourceLang, targetLang); if (this.newerModel != null) { //Activate the Load model button this.LoadModel_btn.Visible = true; this.LoadModel_btn.Enabled = true; var newModelName = new DirectoryInfo(newerModel).Name; this.infoBox.AppendText("New model "); this.infoBox.SelectionFont = new System.Drawing.Font(this.infoBox.Font, System.Drawing.FontStyle.Bold); this.infoBox.AppendText(newModelName); this.infoBox.SelectionFont = new System.Drawing.Font(this.infoBox.Font, System.Drawing.FontStyle.Regular); this.infoBox.AppendText(" can be downloaded from the Fiskmö repository."); } if (existingModel == null && this.newerModel == null) { this.infoBox.Text = "No model available for the language pair"; } }
/// <summary> /// Stores a single string pair as translation with the help of the dummy MT service. /// </summary> /// <param name="tokenCode">The token code.</param> /// <param name="source">The source string.</param> /// <param name="target">The target string.</param> /// <param name="srcLangCode">The source language code.</param> /// <param name="trgLangCode">The target language code.</param> public static void StoreTranslation(FiskmoOptions options, string source, string target, string srcLangCode, string trgLangCode) { // Always dispose allocated resources var proxy = getNewProxy(options.mtServiceAddress, options.mtServicePort); using (proxy as IDisposable) { proxy.StoreTranslation(GetTokenCode(options), source, target, srcLangCode, trgLangCode); } }
/// <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(FiskmoOptions options, List <string> sources, List <string> targets, string srcLangCode, string trgLangCode) { // Always dispose allocated resources var proxy = getNewProxy(options.mtServiceAddress, options.mtServicePort); using (proxy as IDisposable) { return(proxy.BatchStoreTranslation(GetTokenCode(options), sources, targets, srcLangCode, trgLangCode)); } }
/// <summary> /// Translates a single string with the help of the dummy MT service. /// </summary> /// <param name="tokenCode">The token code.</param> /// <param name="input">The string to translate.</param> /// <param name="srcLangCode">The source language code.</param> /// <param name="trgLangCode">The target language code.</param> /// <returns>The translated string.</returns> public static string Translate(FiskmoOptions options, string input, string srcLangCode, string trgLangCode, string modelTag) { // Always dispose allocated resources var proxy = getNewProxy(options.mtServiceAddress, options.mtServicePort); using (proxy as IDisposable) { string result = proxy.Translate(GetTokenCode(options), input, srcLangCode, trgLangCode, modelTag); return(result); } }
/// <summary> /// Translates multiple strings with the help of the dummy MT service. /// </summary> /// <param name="tokenCode">The token code.</param> /// <param name="input">The strings to translate.</param> /// <param name="srcLangCode">The source language code.</param> /// <param name="trgLangCode">The target language code.</param> /// <returns>The translated strings.</returns> public static List <string> BatchTranslate(FiskmoOptions options, List <string> input, string srcLangCode, string trgLangCode, string modelTag) { // Always dispose allocated resources var proxy = getNewProxy(options.mtServiceAddress, options.mtServicePort); using (proxy as IDisposable) { string[] result = proxy.BatchTranslate(GetTokenCode(options), input, srcLangCode, trgLangCode, modelTag).ToArray(); return(result.ToList()); } }
public FiskmoProvider(FiskmoOptions options) { Options = options; if (options.pregenerateMt) { EditorController editorController = SdlTradosStudio.Application.GetController <EditorController>(); editorController.ActiveDocumentChanged -= FiskmoProvider.DocChanged; editorController.ActiveDocumentChanged += FiskmoProvider.DocChanged; } }
public FiskmoOptionControl(FiskmoOptionsFormWPF hostForm, FiskmoOptions 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; }
/// <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 FiskmoProviderLanguageDirection(FiskmoProvider provider, LanguagePair languages) { #region "Instantiate" // UT.LogMessageToFile("Init ListTranslationProviderLanguageDirection"); _provider = provider; _languageDirection = languages; _options = _provider.Options; if (Boolean.Parse(_options.pregenerateMt)) { EditorController editorController = SdlTradosStudio.Application.GetController <EditorController>(); editorController.ActiveDocumentChanged += DocChanged; } _visitor = new FiskmoProviderElementVisitor(_options); var sourceCode = this._languageDirection.SourceCulture.TwoLetterISOLanguageName; var targetCode = this._languageDirection.TargetCulture.TwoLetterISOLanguageName; this.langpair = $"{sourceCode}-{targetCode}"; if (!FiskmoProviderLanguageDirection.processedDocuments.ContainsKey(this.langpair)) { FiskmoProviderLanguageDirection.processedDocuments[this.langpair] = new ConcurrentBag <Document>(); } var modelManager = new ModelManager(); //Start a marian instance if one has not been started or the previous one has exited //for some reason. if (!FiskmoProviderLanguageDirection._marianProcesses.ContainsKey(this.langpair) || FiskmoProviderLanguageDirection._marianProcesses[this.langpair].MtPipe.HasExited) { //if ((sourceCode == "sv" && targetCode == "fi") || (sourceCode == "fi" && targetCode == "sv")) if (true) { var latestModelDir = modelManager.GetLatestModelDir(sourceCode, targetCode); FiskmoProviderLanguageDirection._marianProcesses[this.langpair] = new MarianProcess(latestModelDir, sourceCode, targetCode); } } #endregion }
/// <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 FiskmoProviderLanguageDirection(FiskmoProvider provider, LanguagePair languages) { #region "Instantiate" // UT.LogMessageToFile("Init ListTranslationProviderLanguageDirection"); _provider = provider; _languageDirection = languages; _options = _provider.Options; _visitor = new FiskmoProviderElementVisitor(); var sourceCode = this._languageDirection.SourceCulture.TwoLetterISOLanguageName; var targetCode = this._languageDirection.TargetCulture.TwoLetterISOLanguageName; this.langpair = $"{sourceCode}-{targetCode}"; #endregion }
protected override void OnInitializeTask() { this.collectedSentencePairCount = 0; this.settings = GetSetting <FinetuneBatchTaskSettings>(); this.fiskmoOptions = new FiskmoOptions(new Uri(this.settings.ProviderOptions)); //Use project guid in case no model tag specified if (this.fiskmoOptions.modelTag == "") { this.fiskmoOptions.modelTag = this.Project.GetProjectInfo().Id.ToString(); } 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 FiskmoProviderElementVisitor(); this.targetVisitor = new FiskmoProviderElementVisitor(); base.OnInitializeTask(); }
//Whenever doc changes, start translating the segments and caching translations private static void DocChanged(object sender, DocumentEventArgs e) { if (e.Document == null) { return; } var project = e.Document.Project; var projectInfo = project.GetProjectInfo(); //Make sure that the project has an active Fiskmö translation provider included in it. var projectTpConfig = project.GetTranslationProviderConfiguration(); var tpEntries = projectTpConfig.Entries; var activeFiskmoTp = tpEntries.SingleOrDefault( x => x.MainTranslationProvider.Enabled && x.MainTranslationProvider.Uri.OriginalString.Contains(FiskmoTranslationProviderScheme) ); if (e.Document.Files.Count() > 0 && activeFiskmoTp != null) { var activeFiskmoOptions = new FiskmoOptions(activeFiskmoTp.MainTranslationProvider.Uri); var langPair = e.Document.Files.First().GetLanguageDirection(); if (!FiskmoProvider.processedDocuments.ContainsKey(langPair)) { FiskmoProvider.processedDocuments.Add(langPair, new ConcurrentBag <Document>()); } if (activeFiskmoTp != null && activeFiskmoOptions.pregenerateMt && !FiskmoProvider.processedDocuments[langPair].Contains(e.Document)) { Task t = Task.Run(() => TranslateDocumentSegments(e.Document, langPair, activeFiskmoOptions)); } } else { return; } }
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 FiskmoOptions object (the shared properties //with the translation provider settings). this.Options = new FiskmoOptions(); //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>" }; }
public static string GetTokenCode(FiskmoOptions options) { return(FiskmöMTServiceHelper.GetTokenCode(options.mtServiceAddress, options.mtServicePort)); }
public static List <string> GetLanguagePairModelTags(FiskmoOptions options, string languagePair) { return(FiskmöMTServiceHelper.GetLanguagePairModelTags(options.mtServiceAddress, options.mtServicePort, languagePair)); }
public FiskmoProviderElementVisitor(FiskmoOptions options) { _options = options; }
public FiskmoProvider(FiskmoOptions options) { Options = options; }
//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 //this feature 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, FiskmoOptions options) { var visitor = new FiskmoMarkupDataVisitor(); 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 FiskmöMTServiceHelper.Translate(options, sourceText, sourceCode, targetCode, options.modelTag); } } processedDocuments[langPair].Add(doc); }
public static List <string> ListSupportedLanguages(FiskmoOptions options) { return(ListSupportedLanguages(GetTokenCode(options), options.mtServiceAddress, options.mtServicePort)); }
public FiskmoOptionsFormWPF(FiskmoOptions options, Sdl.LanguagePlatform.Core.LanguagePair[] languagePairs) { this.Options = options; InitializeComponent(); this.wpfHost.Child = new FiskmoOptionControl(this, options, languagePairs); }