예제 #1
0
        //Инициализация правил из xml файла
        private List <Rule> getRulesFromFile()
        {
            List <Rule> rules    = new List <Rule>();
            string      filePath = "../../KnowledgeBaseFiles/KnowledgeBase.xml";
            XDocument   document = XDocument.Load(filePath);

            foreach (XElement el in document.Root.Elements())
            {
                List <FactChecking> factCheckings = new List <FactChecking>();
                foreach (XElement factCheckingElem in el.Element("factCheckings").Elements())
                {
                    bool         isNot        = Boolean.Parse(factCheckingElem.Element("isNot").Value);
                    string       factName     = factCheckingElem.Element("factName").Value;
                    int          value        = Int32.Parse(factCheckingElem.Element("value").Value);
                    FactChecking factChecking = new FactChecking(isNot, factName, value);
                    factCheckings.Add(factChecking);
                }

                XElement actionElem = el.Element("action");
                string   fact       = actionElem.Element("fact").Value;

                XElement valueElem  = actionElem.Element("value");
                string   actionType = valueElem.Element("type").Value;

                Action action = null;
                if (actionType == "askQuestion")
                {
                    string questionText = valueElem.Element("question").Value;
                    List <AllowedValue> allowedValues     = new List <AllowedValue>();
                    XElement            allowedValuesElem = valueElem.Element("allowedValues");
                    foreach (XElement valueId in allowedValuesElem.Elements())
                    {
                        int          id           = Int32.Parse(valueId.Value);
                        AllowedValue allowedValue = _allowedValuesForFacts[fact].Where(e => e.Id == id).First();
                        allowedValues.Add(allowedValue);
                    }
                    ElementGetter <AllowedValue> allowedValuesGetter = ElementGetterAndGetterAdderFactory <AllowedValue> .CreateElementGetter(allowedValues);

                    action = new QuestionForFact(fact, questionText, allowedValuesGetter);
                }

                if (actionType == "concreteValue")
                {
                    string value = valueElem.Element("concreteValue").Value;
                    action = new ConcreteValueForFact(fact, value);
                }

                ElementGetter <FactChecking> factCheckingsGetter = ElementGetterAndGetterAdderFactory <FactChecking> .CreateElementGetter(factCheckings);

                Rule rule = new Rule(action, factCheckingsGetter);
                rules.Add(rule);
            }

            return(rules);
        }
예제 #2
0
        public ArticleElement this[int index]
        {
            get
            {
                if (index < 0)
                {
                    throw new ArgumentOutOfRangeException();
                }

                ElementGetter getter = new ElementGetter(index);
                Iterate(getter);
                PdfDictionary bead = getter.Bead;
                if (bead == null)
                {
                    throw new ArgumentOutOfRangeException();
                }

                return(Wrap <ArticleElement>(bead.Reference));
            }
            set => throw new NotImplementedException();
예제 #3
0
        public void Insert(int index, ArticleElement @object)
        {
            if (index < 0)
            {
                throw new ArgumentOutOfRangeException();
            }

            ElementGetter getter = new ElementGetter(index);

            Iterate(getter);
            PdfDictionary bead = getter.Bead;

            if (bead == null)
            {
                Add(@object);
            }
            else
            {
                Link(@object.BaseDataObject, bead);
            }
        }
 public QuestionForFact(string factToChangeName, string questionText, ElementGetter <AllowedValue> allowedValues) : base(factToChangeName)
 {
     QuestionText  = questionText;
     AllowedValues = allowedValues;
 }
예제 #5
0
 public Rule(Action action, ElementGetter <FactChecking> factCheckings)
 {
     Action        = action;
     FactCheckings = factCheckings;
 }
예제 #6
0
 protected void Register(string propName, ElementGetter elementGetterDelegate)
 {
     BackedGuidListAttribute.Add(new Tuple <string, ElementGetter>(propName, elementGetterDelegate));
 }