private void isANameLoaded(object sender, RoutedEventArgs e)
        {
            var domains = FrameContainer.GetDomains();

            var frame = FrameContainer.GetAllFrames();

            List <string> isA = new List <string>();

            foreach (var f in frame)
            {
                foreach (var d in domains)
                {
                    foreach (var v in d.values)
                    {
                        if (v == f.name && !isA.Contains(f.name))
                        {
                            isA.Add(f.name);
                        }

                        if (f.isA != "null" && !isA.Contains(f.isA))
                        {
                            isA.Add(f.isA);
                        }
                    }
                }
            }

            isA.Add("");

            IsANames.ItemsSource = isA;
        }
        private void isASelected(object sender, SelectionChangedEventArgs e)
        {
            var isA = IsANames.SelectedItem.ToString();

            if (isA != "")
            {
                _frame = new ObservableCollection <string>();
                _frame.Add("Список слотов");

                var fr = FrameContainer.GetAllFrames();

                foreach (var f in fr)
                {
                    if (isA == f.name)
                    {
                        foreach (var slot in f.slots)
                        {
                            _frame.Add(slot.name + ":" + slot.value);
                        }
                        break;
                    }
                }
                frameList.ItemsSource = _frame;
            }
        }
Ejemplo n.º 3
0
        public void SaveInFile(string name, FrameContainer frameContainer)
        {
            List <List <string> > domainsInFile = new List <List <string> >();
            List <List <string> > framesInFile  = new List <List <string> >();

            foreach (var domain in frameContainer.GetDomains())
            {
                List <string> str = new List <string>();

                str.Add("name:" + domain.name);

                foreach (var v in domain.values)
                {
                    str.Add(v);
                }

                domainsInFile.Add(str);
            }

            foreach (var frame in frameContainer.GetAllFrames())
            {
                List <string> str = new List <string>();

                str.Add("name:" + frame.name);
                str.Add("is_a:" + frame.isA);
                str.Add("ID:" + frame.Id);

                foreach (var slot in frame.slots)
                {
                    str.Add(slot.name + ":" + slot.value);
                }

                framesInFile.Add(str);
            }

            SerializeData serialize = new SerializeData {
                Frames = framesInFile, Domains = domainsInFile
            };

            string jsonString = JsonConvert.SerializeObject(serialize, Formatting.Indented);

            File.WriteAllText(name, jsonString);
        }
Ejemplo n.º 4
0
        private void MenuItem_Change(object sender, RoutedEventArgs e)
        {
            try
            {
                ViewModelFramesHierarchy selectedNode = (ViewModelFramesHierarchy)existingSituationsTreeView.SelectedItem;

                FrameContainer  frameContainer  = selectedNode.GetFrameContainer();
                InputMessageBox inputMessageBox = new InputMessageBox();

                switch (selectedNode.kbEntity)
                {
                case ViewModelFramesHierarchy.KBEntity.FRAME:
                    foreach (var frame in frameContainer.GetAllFrames())
                    {
                        inputMessageBox.comboBox.Items.Add(frame.name);
                    }
                    inputMessageBox.comboBox.Items.Remove(selectedNode.Name);
                    break;

                case ViewModelFramesHierarchy.KBEntity.SLOT_VALUE:
                    foreach (var domain in frameContainer.GetDomains())
                    {
                        if (domain.name == selectedNode.ParentalNode.Name)
                        {
                            foreach (var domainValue in domain.values)
                            {
                                inputMessageBox.comboBox.Items.Add(domainValue);
                            }
                        }
                    }
                    break;

                case ViewModelFramesHierarchy.KBEntity.SLOT_NAME:
                    foreach (var domain in frameContainer.GetDomains())
                    {
                        inputMessageBox.comboBox.Items.Add(domain.name);
                    }
                    break;

                case ViewModelFramesHierarchy.KBEntity.IS_A:
                    foreach (var frame in frameContainer.GetAllFrames())
                    {
                        inputMessageBox.comboBox.Items.Add(frame.name);
                    }
                    inputMessageBox.comboBox.Items.Remove(selectedNode.ParentalNode.Name);
                    break;

                default:
                    break;
                }

                inputMessageBox.Owner = this;

                inputMessageBox.Title          = "Поменять имя";
                inputMessageBox.textBlock.Text = "Изменить имя " + selectedNode.Name + " на:";
                System.Windows.Media.Effects.BlurEffect objBlur = new System.Windows.Media.Effects.BlurEffect();
                objBlur.Radius = 5;
                this.Effect    = objBlur;

                if (inputMessageBox.ShowDialog() == true)
                {
                }
                this.Effect = null;

                if (inputMessageBox.NewFrameOrSlotName != null && inputMessageBox.NewFrameOrSlotName != "")
                {
                    selectedNode.ChangeSelectedNodeName = inputMessageBox.NewFrameOrSlotName;
                }
            }
            catch (Exception E)
            {
                MessageBox.Show("Неверныe аргументы");
            }
        }
        void BC_GetAnswer(object sender, RoutedEventArgs e)
        {
            if (frameContainer.GetAllFrames().Count < 1 || frameContainer.GetDomains().Count < 1)
            {
                MessageBox.Show("Загрузите или создайте БЗ.");
                this.Close();
                return;
            }

            listSlots             = new ObservableCollection <string>();
            SlotsList.ItemsSource = listSlots;

            var aFrame = frameContainer.GetAnswer(BigBoy);

            for (int i = aFrame.Count - 1; i >= 0; i--)
            {
                var f = new Frame();

                for (int j = 0; j < aFrame[i].slots.Count; j++)
                {
                    bool isFind = false;

                    foreach (var s in AnswerFrame.slots)
                    {
                        if (s.name == aFrame[i].slots[j].name)
                        {
                            isFind = true;
                            break;
                        }
                    }

                    if (!isFind)
                    {
                        var slot = new Slot();
                        slot.name = aFrame[i].slots[j].name;

                        f.slots.Add(slot);
                    }
                }

                QuestionWindow question = new QuestionWindow(frameContainer, f);
                question.ShowDialog();

                if (i != 0)
                {
                    var frame = frameContainer.GetAnswer(PreAnswer);

                    if (frame == null || PreAnswer.slots.Count < 1)
                    {
                        MessageBox.Show("Системе не удалось найти. Проверте правильность и повоторите ввод или обратитесь к другой экспертной системе.");
                        PreAnswer = new Frame();
                        break;
                    }
                    else
                    {
                        foreach (var d in frameContainer.GetDomains())
                        {
                            foreach (var v in d.values)
                            {
                                if (v == frame[0].name)
                                {
                                    var slot = new Slot();
                                    slot.name  = d.name;
                                    slot.value = v;

                                    AnswerFrame.slots.Add(slot);
                                }
                            }
                        }
                        PreAnswer = new Frame();
                    }
                }
                else
                {
                    foreach (var slot in PreAnswer.slots)
                    {
                        AnswerFrame.slots.Add(slot);
                    }

                    PreAnswer    = new Frame();
                    IsAnswerGive = true;

                    this.Close();
                }
            }
        }