public void LoadModelFromFile(string fileName)
        {
            StreamReader reader = new StreamReader(fileName);
            int numRule = int.Parse(reader.ReadLine());

            for (int i = 0; i < numRule; i++)
            {
                // Đọc chuỗi luật
                Rule rule = new Rule();
                rule.SetRule(reader.ReadLine());

                // Đọc sô thuộc tính điều kiện
                int numAttributeCondition = int.Parse(reader.ReadLine());

                // Đọc giá trị thuộc tính làm điều kiện
                for (int j = 0; j < numAttributeCondition; j++)
                {
                    rule.AttributeConditions.Add(reader.ReadLine());
                    rule.AttributeConditionValues.Add(reader.ReadLine());
                }

                // Đọc sô thuộc tính đích
                int numAttributeTarget = int.Parse(reader.ReadLine());
                for (int j = 0; j < numAttributeTarget; j++)
                {
                    rule.AttributeTargets.Add(reader.ReadLine());
                    rule.AttributeTargetValues.Add(reader.ReadLine());
                }

                // Thêm một luật mới
                ListRules.Add(rule);
            }
            reader.Close();
        }
        private bool isMatchCondition(int[] example, Rule rule, Dataset testData)
        {
            for (int i = 0; i < rule.AttributeConditions.Count; i++)
            {
                string attributeCondition = (string)rule.AttributeConditions[i];
                string ConditionValue = (string)rule.AttributeConditionValues[i];

                int attributePosition = testData.getAttributePosition(attributeCondition);
                int valuesAtPositionExample = example[attributePosition];

                string exampleAttributeValuesAtPosition = testData.Attributes[attributePosition].getAttributeValueByNum(valuesAtPositionExample);

                if (ConditionValue != exampleAttributeValuesAtPosition)
                {
                    return false;
                }
            }
            return true;
        }
        private void BackTrackRule(DecisionTreeNode currentNode)
        {
            string rule;
            string[] Temp = {"IF", "AND","THEN"};

            DecisionTreeNode tempParentNode = currentNode;
            DecisionTreeNode tempCurrentNode = currentNode;

            Rule newRule = new Rule();

            // Xây dựng luật
            rule = Temp[2] + " \"" + DatasetUse.Attributes[0].Name + "\" = " + "\'"+ currentNode.NodeLabel +"\'";
            newRule.AddAttributeTarget(DatasetUse.Attributes[0].Name, currentNode.NodeLabel);
            while (tempCurrentNode.Parent != null)
            {
                tempParentNode = tempCurrentNode.Parent;

                // Kiểm tra đúng cha con
                int i;
                for( i = 0 ; i < tempParentNode.Children.Length; i++)
                {
                    if(tempParentNode.Children[i] == tempCurrentNode)
                    {
                        break;
                    }
                }

                rule = Temp[1] + " \"" + tempParentNode.NodeLabel
                    + "\" = \'" + tempParentNode.ArcLabels[i] + "\' " + rule;
                newRule.AddAttributeCondition(tempParentNode.NodeLabel , tempParentNode.ArcLabels[i].ToString());
                tempCurrentNode = tempParentNode;
            }
            rule = rule.Substring(rule.IndexOf(Temp[1]) + Temp[1].Length);
            rule = Temp[0] + rule;
            newRule.SetRule(rule);

            newRule.AttributeConditions.Reverse();
            newRule.AttributeConditionValues.Reverse();
            newRule.AttributeTargets.Reverse();
            newRule.AttributeTargetValues.Reverse();

            // Thêm một luật mới vào danh sách các luật rút ra
            ListRules.ListRules.Add(newRule);
        }