bool ToSolvePolishNotation(Rule rule) { Stack <Fact> stack = new Stack <Fact>(); rule.visited = true; if (rule.left.Length == 1 || (rule.left.Length == 2 && rule.left[0] == '!')) { Fact fact; if (rule.left[0] == '!') { fact = new Fact(dict[rule.left[1]], rule.left[1], true); } else { fact = new Fact(dict[rule.left[0]], rule.left[0]); } if (fact.value == null) { fact.value = Recursion(fact.name); dict[fact.name] = fact.value; } return((bool)(fact.negative ? !fact.value : fact.value)); } for (int i = 0; i < rule.left.Length; i++) { if (rule.left[i] == '!') { stack.Push(new Fact(dict[rule.left[i + 1]], rule.left[i + 1], true)); i++; } else if (char.IsUpper(rule.left[i])) { stack.Push(new Fact(dict[rule.left[i]], rule.left[i])); } else { var s1 = stack.Pop(); var s2 = stack.Pop(); if (s1.value == null) { s1.value = Recursion(s1.name); dict[s1.name] = s1.value; } if (s2.value == null) { s2.value = Recursion(s2.name); dict[s2.name] = s2.value; } s1.value = s1.negative ? !s1.value : s1.value; s2.value = s2.negative ? !s2.value : s2.value; stack.Push(new Fact(MakeOperation((bool)s1.value, (bool)s2.value, rule.left[i]))); } } if (stack.Count > 1) { throw new System.IO.InvalidDataException("The expression is not correct"); } rule.visited = false; return((bool)stack.Pop().value); }
private void LoadFactsFromXML() { string id; string desc = ""; bool portable = false; bool gaming = false; bool expensive = false; bool backlit = false; string hardware = ""; AddHardwareToPC(); foreach (XmlNode xmlNode in xmlDoc.DocumentElement) { id = xmlNode.Attributes[0].InnerText; foreach (XmlNode xmlNode1 in xmlNode) { if (xmlNode1.LocalName == "Description") { desc = xmlNode1.Attributes["value"].Value; } foreach (XmlNode xmlNode2 in xmlNode1) { if (xmlNode2.Attributes["id"].Value == "portable") { if (xmlNode2.InnerText == "false") { portable = false; } else { portable = true; } } else if (xmlNode2.Attributes["id"].Value == "gaming") { if (xmlNode2.InnerText == "false") { gaming = false; } else { gaming = true; } } else if (xmlNode2.Attributes["id"].Value == "expensive") { if (xmlNode2.InnerText == "false") { expensive = false; } else { expensive = true; } } else if (xmlNode2.Attributes["id"].Value == "hardware") { foreach (var key in HardwareOfPCs.Keys) { if (HardwareOfPCs.ContainsKey(id)) { hardware = HardwareOfPCs.GetValueOrDefault(key); } } } else if (xmlNode2.Attributes["id"].Value == "backlit keyboard") { if (xmlNode2.InnerText == "false") { backlit = false; } else { backlit = true; } } } } Fact fact = new Fact(id, desc, hardware); fact.SetFactValueByID("portable", portable); fact.SetFactValueByID("gaming", gaming); fact.SetFactValueByID("expensive", expensive); fact.SetFactValueByID("backlit keyboard", backlit); factRepository.AddFact(fact); } }
public void AddFact(Fact fact) { factList.Add(fact); }
public void AddFact(Fact fact) { this.facts.Add(fact); }
public void AddFact(Fact fact) { Facts.Add(fact); }