/// <summary> /// Find fact about element /// </summary> /// <param name="element"></param> /// <param name="ruleArgument"></param> /// <returns></returns> private FactAboutElement FindFactAboutElementWhichIsRuleArgument(Element element, RuleArgument ruleArgument) { return element.Facts.Find(fae => fae.Id == ruleArgument.Id); }
/// <summary> /// SearchForAnswer /// </summary> /// <param name="element"></param> /// <param name="question"></param> /// <param name="value"></param> /// <returns></returns> private bool SearchForAnswer(Element element, Question question, bool value) { foreach (RuleArgument ruleArgument in question.Rule.Arguments) { Fact fact = Facts.Find(f => ruleArgument.Id == f.Id); logger.CheckingForArgument(fact); FactAboutElement factAboutElement = FindFactAboutElementWhichIsRuleArgument(element, ruleArgument); if (factAboutElement == null) { Question answeringQuestion = FindQuestionForGivenFact(ruleArgument.Id); if (answeringQuestion == null) { return false; } logger.SearchingForAnswer(element, answeringQuestion); if (SearchForAnswer(element, answeringQuestion, ruleArgument.RequiredValue)) { factAboutElement = FindFactAboutElementWhichIsRuleArgument(element, ruleArgument); } } if (factAboutElement.Value != ruleArgument.RequiredValue) { logger.ArgumentDoesNotMatch(ruleArgument); return false; } logger.ArgumentMatch(ruleArgument); } FactAboutElement factAboutElementNew = new FactAboutElement { Id = question.Rule.Target.Id, Name = question.Rule.Target.Name, Value = value }; logger.AddingFact(factAboutElementNew); element.Facts.Add(factAboutElementNew); logger.EnfOfCheckingIfFactCanBeAdded(); return true; }
/// <summary> /// Check if element is good for a given answer to a question /// </summary> /// <param name="element"></param> /// <param name="question"></param> /// <param name="value"></param> /// <returns></returns> private bool Answer(Element element, Question question, bool value) { logger.LookingForFact(question); var factAboutElement = FindFactAboutElementWhichIsQuestionSubject(element, question); if (factAboutElement != default(FactAboutElement)) { logger.ElementHasAnswer(element, question); return value == factAboutElement.Value; } logger.ElementDoesnotHaveAnswer(element, question); logger.CheckingIfElementCanBeCreated(); return SearchForAnswer(element, question, value); }
/// <summary> /// finds fact about element /// </summary> /// <param name="element"></param> /// <param name="question"></param> /// <returns></returns> private FactAboutElement FindFactAboutElementWhichIsQuestionSubject(Element element, Question question) { return element.Facts.Find(f => f.Id == question.Rule.Target.Id); }
public void AddingElement(Element element) { }
public void ElementHasAnswer(Element element, Question question) { stringBuilder.AppendLine(Indent() + string.Format("Element posiada fakt: {0}", question.Rule.Target.Name)); DecreaseIndent(); }
public void ProcessingElement(Element element) { stringBuilder.AppendLine(Indent() + string.Format("Przetwarzanie elementu: {0}", element.Name)); IncreaseIndent(); }
public void SearchingForAnswer(Element element, Question question) { IncreaseIndent(); stringBuilder.AppendLine(Indent() + string.Format("Szukanie, czy element {0} posiada odpowiedź na pytanie {1}", element.Name, question.Rule.Name)); }
public void ProcessingElement(Element element) { }
public void EndOfProcessingElement(Element element) { DecreaseIndent(); stringBuilder.AppendLine(Indent() + string.Format("Koniec przetwarzania elementu: {0}", element.Name)); }
public void EndOfProcessingElement(Element element) { }
public void ElementHasAnswer(Element element, Question question) { }
public void ElementDoesnotHaveAnswer(Element element, Question question) { }
public void SearchingForAnswer(Element element, Question question) { }
/// <summary> /// add new element /// </summary> /// <param name="cbElements"></param> /// <param name="clbFactsAboutElements"></param> public void AddElement(ComboBox cbElements, CheckedListBox clbFactsAboutElements) { string elementName = cbElements.Text; cbElements.Items.Add(elementName); Dictionary<Guid, bool> factsAboutElement = new Dictionary<Guid, bool>(); foreach (var item in clbFactsAboutElements.Items) { RuleArgumentListBoxItem factAboutElement = item as RuleArgumentListBoxItem; factsAboutElement.Add(factAboutElement.Id, factAboutElement.Value); } Guid elementId = dataAccessLayer.InsertElement(elementName, factsAboutElement); Element element = new Element { Id = elementId, Name = elementName, Facts = factsAboutElement.Select(fae => new FactAboutElement { Id = fae.Key, Value = fae.Value, Name = inferenceModule.Facts.Find(f => f.Id == fae.Key).Name }).ToList() }; inferenceModule.Elements.Add(element); }