//Adds a system to available system list for this profile, returns reference to the system public CMtSystem AddSystem(string strSystemId, string strFriendlyName, string strFriendlyDescription, string strOnlineStatus, bool qeAvailable) { CMtSystem system = new CMtSystem(strSystemId, strFriendlyName, strFriendlyDescription, strOnlineStatus, qeAvailable); m_availableSystems.Add(system); //if (m_defaultSystem == "") //m_defaultSystem = strSystemId; return(system); }
//On selected system, fill the textbox with systems description etc... private void wndProfileProperties_SelectedIndexChanged(object sender, EventArgs e) { if (wndProfileProperties.SelectedIndex != -1) { ListItem item = wndProfileProperties.SelectedItem as ListItem; string systemId = item.Value.ToString(); string profileId = getSelectedProfileId(); CMtSystem selectedSystem = m_translationProvider.m_profileCollection.GetSystemById(systemId); bool qeAvailable = selectedSystem.GetQeAvailability(); qualityEstimateCheckBox.Enabled = qeAvailable; qualityEstimateTextBox.Enabled = qeAvailable; qeCheckedProgrammatically = true; qualityEstimateCheckBox.Checked = qeAvailable && qeWasCheckedWhenAvailable; qeCheckedProgrammatically = false; termCorporaSelectComboBox.Items.Clear(); termCorporaSelectComboBox.Text = ""; Func <LetsMTAPI.TermCorpus[]> getTerms = () => m_translationProvider.m_service.GetSystemTermCorpora(systemId); getTerms.BeginInvoke(x => { AsyncResult result = x as AsyncResult; LetsMTAPI.TermCorpus[] termCorpora; try { termCorpora = getTerms.EndInvoke(result); } catch { return; } // This callback is executed on a ThreadPool thraed. Filling the term corpora list must be done on the UI thread. this.BeginInvoke(new Action(() => { FillTermCorporaList(profileId, systemId, termCorpora); })); }, null); } }
public CMtProfileCollection(LetsMTAPI.MTSystem[] mtSystems) { //Empty lists initialized m_profileList = new List <CMtProfile>(); m_systemList = new List <CMtSystem>(); //Fill the lists with data from web service foreach (LetsMTAPI.MTSystem system in mtSystems) { string strProfileId = CMtProfile.GenerateProfileId(system.SourceLanguage.Code, system.TargetLanguage.Code); //Reference to profile which has to be filled with system CMtProfile refProfile = null; foreach (CMtProfile existingProfile in m_profileList) { //We already have a profile if (existingProfile.IsProfile(strProfileId)) { //Set the reference to an existing profile refProfile = existingProfile; break; } } //No profile, create new and fill the fields if (refProfile == null) { string strFriendlyName; strFriendlyName = string.Format("{0} - {1}", system.SourceLanguage.Name.Text, system.TargetLanguage.Name.Text); //Set the reference to new profile refProfile = new CMtProfile(system.SourceLanguage.Code, system.SourceLanguage.Name.Text, system.TargetLanguage.Code, system.TargetLanguage.Name.Text); m_profileList.Add(refProfile); } //Add a system to profile through profile reference string strSysId = system.ID; string strSysFriendlyName = system.Title.Text; string strSysDescription = system.Description.Text; // string strSysDescription = system.Metadata[0]. string strSysOnlineStatus = "unknown"; strSysDescription += ""; bool qeTrained = false; bool qeEnabled = false; //Fill description field and find out whether QE is available foreach (LetsMTAPI.ObjectProperty meta in system.Metadata) { if (meta.Key == "description") { strSysDescription += "Description: " + meta.Value + "\n"; } else if (meta.Key.StartsWith("score") && !(meta.Key.Contains("-c"))) { try { double x; if (double.TryParse(meta.Value, NumberStyles.Any, CultureInfo.GetCultureInfoByIetfLanguageTag("EN-US"), out x)) { double score = x; score = Math.Round(score, 4); if (meta.Key.Contains("bleu")) { score = score * 100; } strSysDescription += meta.Key.Replace("score-", "").ToUpper() + ":" + score.ToString() + ", "; } else { strSysDescription += meta.Key.Replace("score-", "").ToUpper() + ":" + meta.Value + ", "; } } catch { continue; } } else if (meta.Key == "train-qe-model" && meta.Value == "true") { qeTrained = true; } else if (meta.Key == "enable-qe" && meta.Value == "true") { qeEnabled = true; } } bool qeAvailable = qeTrained && qeEnabled; char[] charsToTrim = { ',', ' ' }; strSysDescription = strSysDescription.TrimEnd(charsToTrim); System.Collections.IEnumerator metaEnum = system.Metadata.GetEnumerator(); while (metaEnum.MoveNext()) { Nullable <LetsMTAPI.ObjectProperty> nullableProp = metaEnum.Current as Nullable <LetsMTAPI.ObjectProperty>; LetsMTAPI.ObjectProperty prop = nullableProp.Value; if (prop.Key == "status") { switch (prop.Value) { case "running": strSysOnlineStatus = "Running"; break; case "queuingtransl": strSysOnlineStatus = "Queuing"; break; case "notstarted": strSysOnlineStatus = "Not Started"; break; case "nottrained": strSysOnlineStatus = "Not Trained"; break; case "error": strSysOnlineStatus = "Not Trained"; break; case "training": strSysOnlineStatus = "Training"; break; case "standby": strSysOnlineStatus = "Standby"; break; default: strSysOnlineStatus = prop.Value; break; } //strSysOnlineStatus = prop.Value; break; } } CMtSystem refSystem = refProfile.AddSystem(strSysId, strSysFriendlyName, strSysDescription, strSysOnlineStatus, qeAvailable); m_systemList.Add(refSystem); } }