public override KnowledgeBase Load() { string Content = (new StreamReader(FileName, Encoding.Default)).ReadToEnd(); char[] sep1 = { '#' }; char[] sep2 = { '\n', '\r' }; string[] sep3 = { ":-" }; string[] Knowledges = Content.Split(sep1, StringSplitOptions.RemoveEmptyEntries); string[] Facts = Knowledges[0].Split(sep2, StringSplitOptions.RemoveEmptyEntries); string[] Rules = Knowledges[1].Split(sep2, StringSplitOptions.RemoveEmptyEntries); string[] OneRule; KnowledgeBase KB = new KnowledgeBase(); foreach (string StrFact in Facts) { KB.AddFact(Translator.StringToFact(StrFact)); } foreach (string StrRule in Rules) { OneRule = StrRule.Split(sep3, StringSplitOptions.RemoveEmptyEntries); KB.AddRule(Translator.StringsToRule(OneRule[0], OneRule[1])); } return(KB); }
private void loadVariables() { listRules = new List <StrRule>(); Double value = 0; bool exists = false; StrRule index; XmlDocument doc = new XmlDocument(); doc.Load(FrmPrincipal.PATHRULESXML); foreach (XmlNode root in doc.SelectNodes("configuracao/regra")) { StrRule strRule = new StrRule(); foreach (XmlNode node in root.ChildNodes) { if (node.LocalName == "ID") { strRule.id = Convert.ToInt32(node.InnerText); } else if (node.LocalName == "RESULTADO") { strRule.variable = getVariable(node.InnerText.Split('=')[0]); strRule.term = getTerm(strRule.variable, node.InnerText.Split('=')[1]); } else if (node.LocalName == "VALOR") { strRule.valor = Convert.ToDouble(node.InnerText); } } foreach (StrRule rule in listRules) { if (rule.term.name == strRule.term.name) { exists = true; if (rule.valor < strRule.valor) { value = strRule.valor; index = rule; } } } if (!exists) { listRules.Add(strRule); } else { index.valor = strRule.valor; } exists = false; } }