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); }
private string GetConsequentJsonByRule(KB.Rule rule) { string json = ""; Judgment j = rule.Consequent; json += String.Format(@"""{0} — {1}""", j.Title, j.FuzzyValue); return(json); }
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 { } }
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); }
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 { } }
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 { } }
public override void AddChildRule(Rule rule) { this.childRules.Add(rule); }