コード例 #1
0
        private string getSelectedProfileId()
        {
            ListItem sourceLanguageItem = sourceSelectComboBox.SelectedItem as ListItem;
            ListItem targetLanguageItem = targetSelectComboBox.SelectedItem as ListItem;

            if (sourceLanguageItem == null || targetLanguageItem == null)
            {
                return(null);
            }
            string sourceLanguageId = sourceLanguageItem.Value;
            string targetLanguageId = targetLanguageItem.Value;

            return(CMtProfile.GenerateProfileId(sourceLanguageId, targetLanguageId));
        }
コード例 #2
0
        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);
            }
        }