コード例 #1
0
 /// <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);
 }
コード例 #2
0
        /// <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;
        }
コード例 #3
0
        /// <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);
        }
コード例 #4
0
 /// <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);
 }
コード例 #5
0
 public void AddingElement(Element element)
 {
 }
コード例 #6
0
 public void ElementHasAnswer(Element element, Question question)
 {
     stringBuilder.AppendLine(Indent() + string.Format("Element posiada fakt: {0}", question.Rule.Target.Name));
     DecreaseIndent();
 }
コード例 #7
0
 public void ProcessingElement(Element element)
 {
     stringBuilder.AppendLine(Indent() + string.Format("Przetwarzanie elementu: {0}", element.Name));
     IncreaseIndent();
 }
コード例 #8
0
 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));
 }
コード例 #9
0
 public void ProcessingElement(Element element)
 {
 }
コード例 #10
0
 public void EndOfProcessingElement(Element element)
 {
     DecreaseIndent();
     stringBuilder.AppendLine(Indent() + string.Format("Koniec przetwarzania elementu: {0}", element.Name));
 }
コード例 #11
0
 public void EndOfProcessingElement(Element element)
 {
 }
コード例 #12
0
 public void ElementHasAnswer(Element element, Question question)
 {
 }
コード例 #13
0
 public void ElementDoesnotHaveAnswer(Element element, Question question)
 {
 }
コード例 #14
0
 public void SearchingForAnswer(Element element, Question question)
 {
 }
コード例 #15
0
        /// <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);
        }