예제 #1
0
        private string GetAntecedentJsonByRule(KB.Rule rule)
        {
            string json = "{ ";

            foreach (IList <Judgment> judgments in rule.Antecedent.JudgmentDictionary.Values)
            {
                if (judgments.Count == 1)
                {
                    Judgment j = judgments.First();
                    json += String.Format(@"""AND"": [ ""{0} — {1}"" ], ", j.Title, j.FuzzyValue);
                }
                else
                {
                    json += "\"OR\": [";
                    foreach (Judgment j in judgments)
                    {
                        json += String.Format(@" ""{0} — {1}"",", j.Title, j.FuzzyValue);
                    }
                    json = json.TrimEnd(',');

                    json += " ], ";
                }
            }
            json  = json.TrimEnd(new char[] { ' ', ',' });
            json += " }";

            return(json);
        }
예제 #2
0
        private string GetConsequentJsonByRule(KB.Rule rule)
        {
            string   json = "";
            Judgment j    = rule.Consequent;

            json += String.Format(@"""{0} — {1}""", j.Title, j.FuzzyValue);

            return(json);
        }
예제 #3
0
 public void InsertRule(KB.Rule rule)
 {
     try
     {
         string commandString =
             "Insert Into Rules (Antecedent, Consequent)" +
             $"Values ('{GetAntecedentJsonByRule(rule)}', '{GetConsequentJsonByRule(rule)}')";
         SqlCommand command = new SqlCommand(commandString, connection);
         command.ExecuteNonQuery();
     }
     catch { }
 }
예제 #4
0
        private IList <KB.Rule> GetRulesFromDataTable(DataTable dataTable)
        {
            IList <KB.Rule> rules = new List <KB.Rule>();

            for (int rowIndex = 0; rowIndex < dataTable.Rows.Count; rowIndex++)
            {
                KB.Rule rule = GetRuleFromDataTableRow(dataTable.Columns, dataTable.Rows[rowIndex]);

                rules.Add(new SimpleRule(rule.LinguisticVariable, rule.Antecedent, rule.Consequent));
            }

            return(rules);
        }
예제 #5
0
 public void UpdateRule(KB.Rule beforeRule, KB.Rule afterRule)
 {
     try
     {
         string commandString =
             "Update Rules " +
             $"Set Antecedent = '{GetAntecedentJsonByRule(afterRule)}', Consequent = '{GetConsequentJsonByRule(afterRule)}' " +
             $"Where Antecedent = '{GetAntecedentJsonByRule(beforeRule)}'";
         SqlCommand command = new SqlCommand(commandString, connection);
         command.ExecuteNonQuery();
     }
     catch { }
 }
예제 #6
0
 public void DeleteRule(KB.Rule rule)
 {
     try
     {
         string commandString =
             "Delete Rules " +
             $"WHERE Antecedent = '{GetAntecedentJsonByRule(rule)}' " +
             $"AND Consequent = '{GetConsequentJsonByRule(rule)}'";
         SqlCommand command = new SqlCommand(commandString, connection);
         command.ExecuteNonQuery();
     }
     catch { }
 }
예제 #7
0
 public override void AddChildRule(Rule rule)
 {
     this.childRules.Add(rule);
 }