コード例 #1
0
ファイル: MKB-parser.cs プロジェクト: KaryakinaEkaterina/Pars
        public MKB Clone()
        {
            MKB mkb_clone = new MKB();

            mkb_clone.Summary   = "" + Summary;
            mkb_clone.Objects   = new List <MKBObject>();
            mkb_clone.Questions = new List <string>();
            foreach (MKBObject o in Objects)
            {
                MKBObject oc = new MKBObject();
                oc.Name          = "" + o.Name;
                oc.Probabl       = o.Probabl;
                oc.QuestProbabls = new List <MKBQuest>();
                foreach (MKBQuest q in o.QuestProbabls)
                {
                    MKBQuest qc = new MKBQuest();
                    qc.ID       = q.ID;
                    qc.Probabl1 = q.Probabl1;
                    qc.Probabl2 = q.Probabl2;
                    oc.QuestProbabls.Add(qc);
                }
                mkb_clone.Objects.Add(oc);
            }
            foreach (string q in Questions)
            {
                mkb_clone.Questions.Add("" + q);
            }
            return(mkb_clone);
        }
コード例 #2
0
 private void sortBy(MKB mkb)
 {
     if (byABCrb.Checked)
     {
         mkb.Objects = mkb.Objects.OrderBy(o => o.Name).ToList();
     }
     else if (byPrb.Checked)
     {
         mkb.Objects = mkb.Objects.OrderByDescending(o => o.Probabl).ToList();
     }
     updateObjects(mkb);
 }
コード例 #3
0
 private void updateObjects(MKB mkb)
 {
     listObjectsView.Items.Clear();
     foreach (MKBObject o in mkb.Objects)
     {
         if (o.Probabl == 0 || o.Probabl == 1)
         {
             listObjectsView.Items.Add("(" + o.Probabl + ".000) " + o.Name);
         }
         else
         {
             listObjectsView.Items.Add("(" + Math.Round(o.Probabl, 3) + ") " + o.Name);
         }
     }
 }
コード例 #4
0
        private void openFileBut_Click(object sender, EventArgs e)
        {
            OpenFileDialog dOpen      = new OpenFileDialog();
            Stream         fileStream = null;

            dOpen.Title            = "Открыть файл";
            dOpen.Multiselect      = false;
            dOpen.Filter           = "mkb files (*.mkb)|*.mkb";
            dOpen.FilterIndex      = 1;
            dOpen.RestoreDirectory = true;

            if (dOpen.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((fileStream = dOpen.OpenFile()) != null)
                    {
                        string file         = "";
                        int    streamLength = (int)fileStream.Length;
                        byte[] buffer       = new byte[streamLength];
                        fileStream.Read(buffer, 0, streamLength);
                        fileStream.Close();
                        buffer = Encoding.Convert(Encoding.GetEncoding("Windows-1251"), Encoding.UTF8, buffer);
                        file   = Encoding.UTF8.GetString(buffer);
                        mkb    = MKB_parser.parseMKB(file);
                        sortBy(mkb);
                        Info.Text                    = "Свидетельств: " + mkb.Questions.Count + "\r\nИсходов: " + mkb.Objects.Count;
                        activeQuestion.Text          = "Можно начинать консультацию...";
                        startSimulationBut.Enabled   = true;
                        listObjectsView.Enabled      = true;
                        listActiveQuestions.Enabled  = true;
                        listPassiveQuestions.Enabled = true;
                        listResult.Enabled           = true;
                        orderByBox.Enabled           = true;
                        summaryView.Text             = mkb.Summary;
                        updateObjects(mkb);
                        foreach (string q in mkb.Questions)
                        {
                            listActiveQuestions.Items.Add(q);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Could not read file from disk. Original error: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
コード例 #5
0
ファイル: MKB-parser.cs プロジェクト: KaryakinaEkaterina/Pars
        public static MKB parseMKB(string file)
        {
            MKB  mkb = new MKB();// создаем объект
            bool summaryIsHere = false, questionsIsHere = true, probablsIsHere = true;
            int  begin = 0;

            string[] global_array = file.Split('\n'); // разбиваем строку
            for (int i = 0; i < global_array.Length; ++i)
            {
                if (!summaryIsHere && global_array[i].CompareTo("Признаки:\r") == 0)
                {
                    string summary = "";
                    for (int j = 0; j < i - 1; ++j) // проходимся по признакам
                    {
                        summary += global_array[j];
                    }
                    mkb.Summary     = "" + summary;
                    summaryIsHere   = true;
                    questionsIsHere = false;
                    begin           = i + 1;
                    continue;
                }

                if (!questionsIsHere && global_array[i].CompareTo("\r") == 0)
                {
                    mkb.Questions = new List <string>();
                    for (int j = 0, k = begin; k < i; ++j, ++k)// проходимся по вопросам
                    {
                        mkb.Questions.Add(global_array[k]);
                    }
                    questionsIsHere = true;
                    probablsIsHere  = false;
                    begin           = i + 1;
                    continue;
                }

                if (!probablsIsHere)
                {
                    mkb.Objects = new List <MKBObject>();
                    for (int j = 0, k = begin; k < global_array.Length; ++j, ++k)
                    {
                        string[]  line_array = global_array[k].Split(',');
                        MKBObject mkb_obj    = new MKBObject();
                        mkb_obj.Name          = line_array[0];
                        mkb_obj.Probabl       = double.Parse(line_array[1], CultureInfo.InvariantCulture);
                        mkb_obj.QuestProbabls = new List <MKBQuest>();
                        for (int r = 2; r < line_array.Length; r += 3)
                        {
                            MKBQuest mkb_quest = new MKBQuest();
                            mkb_quest.ID       = int.Parse(line_array[r]) - 1;
                            mkb_quest.Probabl1 = double.Parse(line_array[r + 1], CultureInfo.InvariantCulture);
                            mkb_quest.Probabl2 = double.Parse(line_array[r + 2], CultureInfo.InvariantCulture);
                            mkb_obj.QuestProbabls.Add(mkb_quest);
                        }
                        mkb.Objects.Add(mkb_obj);
                    }
                    probablsIsHere = true;
                }
            }
            return(mkb);
        }