Beispiel #1
0
        public override void Initialisation(string childText, Tokens tokens)
        {
            /*
             * this line pattern is as (^[ML]+)(O)([MLNoDaDeHaUrlId]*$)
             */

            this.nodeName = childText;

            /*
             * In javascript engine '=' operator means assigning a value, hence if the operator is '=' then it needs to be replaced with '=='.
             */
            int operatorIndex = tokens.tokensStringList.IndexOf("O");

            this.operatorString = tokens.tokensList[operatorIndex].Equals("=") ? "==" : tokens.tokensList[operatorIndex];

            if (operatorString.Equals("=="))
            {
                this.variableName = childText.Split('=')[0].Trim();
            }
            else
            {
                string[] splitor = new string[] { this.operatorString };

                this.variableName = childText.Split(splitor, StringSplitOptions.None)[0].Trim();
            }
            this.lhs = variableName;

            int    tokensStringListSize = tokens.tokensStringList.Count;
            String lastToken            = tokens.tokensList[tokensStringListSize - 1];
            String lastTokenString      = tokens.tokensStringList[tokensStringListSize - 1];

            this.SetValue(lastTokenString, lastToken);
            this.rhs = this.value;
        }
Beispiel #2
0
 public int NumberOfTrueChildren(Dictionary <string, FactValue> workingMemory)
 {
     return(this.iterateIE.GetNodeSet().GetDependencyMatrix().GetToChildDependencyList(this.nodeId)
            .Where((i) => i != this.nodeId + 1)
            .Where((id) => FactValue.GetValueInString(workingMemory[this.iterateIE.GetNodeSet().GetNodeIdMap()[id]].GetFactValueType(), workingMemory[this.iterateIE.GetNodeSet().GetNodeIdMap()[id]]).ToLower().Equals("true"))
            .ToList().Count);
 }
Beispiel #3
0
        public Node GetIterateNextQuestion(NodeSet parentNodeSet, AssessmentState parentAst)
        {
            if (this.iterateNodeSet == null && this.givenListSize != 0)
            {
                this.iterateNodeSet = CreateIterateNodeSet(parentNodeSet);
                this.iterateIE      = new InferenceEngine(this.iterateNodeSet);
                if (this.iterateIE.GetAssessment() == null)
                {
                    this.iterateIE.SetAssessment(new Assessment(this.iterateNodeSet, this.GetNodeName()));
                }
            }

            Node firstIterateQuestionNode = parentNodeSet.GetNodeByNodeId(parentNodeSet.GetDependencyMatrix().GetToChildDependencyList(this.GetNodeId()).Min());
            Node questionNode             = null;

            if (!parentAst.GetWorkingMemory().ContainsKey(FactValue.GetValueInString(this.value.GetFactValueType(), this.value))) // a list is not given yet so that the engine needs to find out more info.
            {
                if (!parentAst.GetWorkingMemory().ContainsKey(firstIterateQuestionNode.GetNodeName()))
                {
                    questionNode = firstIterateQuestionNode;
                }
                else
                {
                    if (!CanBeSelfEvaluated(parentAst.GetWorkingMemory()))
                    {
                        questionNode = this.iterateIE.GetNextQuestion(this.iterateIE.GetAssessment());
                    }
                }
            }


            return(questionNode);
        }
        public override void Initialisation(string parentText, Tokens tokens)
        {
            this.nodeName = parentText;
            string[] tempArray = Regex.Split(parentText, "IS CALC");
            variableName = tempArray[0].Trim();
            int indexOfCInTokensStringList = tokens.tokensStringList.IndexOf("C");

            this.SetValue(tokens.tokensStringList[indexOfCInTokensStringList].Trim(), tokens.tokensList[indexOfCInTokensStringList].Trim());
            this.equation = this.value;
        }
Beispiel #5
0
        public override FactValue SelfEvaluate(Dictionary <string, FactValue> workingMemory, Jint.Engine nashorn)
        {
            int numberOfTrueChildren = NumberOfTrueChildren(workingMemory);
            int sizeOfGivenList      = this.givenListSize;
            FactBooleanValue fbv     = null;

            switch (this.numberOfTarget)
            {
            case "ALL":
                if (numberOfTrueChildren == sizeOfGivenList)
                {
                    fbv = FactValue.Parse(true);
                }
                else
                {
                    fbv = FactValue.Parse(false);
                }
                break;

            case "NONE":
                if (numberOfTrueChildren == 0)
                {
                    fbv = FactValue.Parse(true);
                }
                else
                {
                    fbv = FactValue.Parse(false);
                }
                break;

            case "SOME":
                if (numberOfTrueChildren > 0)
                {
                    fbv = FactValue.Parse(true);
                }
                else
                {
                    fbv = FactValue.Parse(false);
                }
                break;

            default:
                if (numberOfTrueChildren == Int32.Parse(this.numberOfTarget))
                {
                    fbv = FactValue.Parse(true);
                }
                else
                {
                    fbv = FactValue.Parse(false);
                }
                break;
            }
            return(fbv);
        }
Beispiel #6
0
 public void TranseferFactValue(Dictionary <string, FactValue> workingMemory_one, Dictionary <string, FactValue> workingMemory_two)
 {
     workingMemory_one.Keys.ToList().ForEach((key) =>
     {
         FactValue tempFv = workingMemory_one[key];
         if (!workingMemory_two.ContainsKey(key))
         {
             workingMemory_two.Add(key, tempFv);
         }
     });
 }
Beispiel #7
0
        public void HandleListItem(string parentText, string itemText, MetaType?metaType)
        {
            Tokens    tokens = Tokenizer.GetTokens(itemText);
            FactValue fv;

            if (tokens.tokensString.Equals("Da"))
            {
                DateTime factValueInDate;
                DateTime.TryParseExact(itemText, "dd/MM/yyyy", null, System.Globalization.DateTimeStyles.None, out factValueInDate);
                fv = FactValue.Parse(factValueInDate);
            }
            else if (tokens.tokensString.Equals("De"))
            {
                fv = FactValue.Parse(Double.Parse(itemText));
            }
            else if (tokens.tokensString.Equals("No"))
            {
                fv = FactValue.Parse(Int32.Parse(itemText));
            }
            else if (tokens.tokensString.Equals("Ha"))
            {
                fv = FactValue.ParseHash(itemText);
            }
            else if (tokens.tokensString.Equals("Url"))
            {
                fv = FactValue.ParseURL(itemText);
            }
            else if (tokens.tokensString.Equals("Id"))
            {
                fv = FactValue.ParseUUID(itemText);
            }
            else if (Regex.Match(itemText, "FfAaLlSsEe").Success || Regex.Match(itemText, "TtRrUuEe").Success)
            {
                fv = FactValue.Parse(Boolean.Parse(itemText));
            }
            else
            {
                fv = FactValue.Parse(itemText);
            }
            string stringToGetFactValue = (parentText.Substring(5, parentText.IndexOf("AS", StringComparison.CurrentCulture) - 5)).Trim(); //the int value of 5 refers to the length of keyword, 'INPUT', +1

            if (metaType.Equals(MetaType.INPUT))
            {
                ((FactListValue)this.nodeSet.GetInputMap()[stringToGetFactValue]).AddFactValueToListValue(fv);
            }
            else if (metaType.Equals(MetaType.FIXED))
            {
                ((FactListValue)this.nodeSet.GetFactMap()[stringToGetFactValue]).AddFactValueToListValue(fv);
            }
        }
        /*
         * this method is to set a rule as a fact in the workingMemory
         * before this method is called, nodeName should be given and look up nodeMap in NodeSet to find variableName of the node
         * then the variableName of the node should be passed to this method.
         */

        public void SetFact(string nodeVariableName, FactValue value)
        {
            if (workingMemory.ContainsKey(nodeVariableName))
            {
                FactValue tempFv = workingMemory[nodeVariableName];

                if (tempFv.GetFactValueType().Equals(FactValueType.LIST))
                {
                    ((FactListValue)tempFv).AddFactValueToListValue(tempFv);
                }
                else
                {
                    FactListValue flv = FactValue.Parse(new List <FactValue>());
                    flv.AddFactValueToListValue(tempFv);
                }
            }
            else
            {
                workingMemory.Add(nodeVariableName, value);
            }
        }
Beispiel #9
0
        public override FactValue SelfEvaluate(Dictionary <string, FactValue> workingMemory, Jint.Engine nashorn)
        {
            FactValue fv = null;

            /*
             * Negation and Known type are a part of dependency
             * hence, only checking its variableName value against the workingMemory is necessary.
             * type is as follows;
             *  1. the rule is a plain statement
             *  2. the rule is a statement of 'A IS B'
             *  3. the rule is a statement of 'A IS IN LIST: B'
             *  4. the rule is a statement of 'needs(wants) A'. this is from a child node of ExprConclusionLine type
             */

            if (!this.isPlainStatementFormat)
            {
                if (tokens.tokensList.Any(s => s.Equals("IS")))
                {
                    fv = this.value;
                }
                else if (tokens.tokensList.Any((s) => s.Equals("IS IN LIST:")))
                {
                    bool   lineValue = false;
                    string listName  = FactValue.GetValueInString(this.GetFactValue().GetFactValueType(), this.GetFactValue());
                    if (workingMemory[listName] != null)
                    {
                        FactValue variableValueFromWorkingMemory = workingMemory[this.variableName];
                        lineValue = variableValueFromWorkingMemory != null ?
                                    ((FactListValue)workingMemory[listName]).GetValue().Any((item) => (item as FactStringValue).GetValue().Equals(FactValue.GetValueInString(variableValueFromWorkingMemory.GetFactValueType(), variableValueFromWorkingMemory)))
                        :
                                    ((FactListValue)workingMemory[listName]).GetValue().Any((item) => (item as FactStringValue).GetValue().Equals(this.variableName));
                    }

                    fv = FactValue.Parse(lineValue);
                }
            }

            return(fv);
        }
Beispiel #10
0
        public bool CanBeSelfEvaluated(Dictionary <string, FactValue> workingMemory)
        {
            bool canBeSelfEvaluated = false;

            if (this.iterateIE != null)
            {
                FactValue  outFactValue = null;
                List <int> numberOfDeterminedSecondLevelNode = this.iterateIE.GetNodeSet().GetDependencyMatrix().GetToChildDependencyList(this.nodeId)
                                                               .Where((i) => i != this.nodeId + 1)
                                                               .Where((id) => workingMemory.TryGetValue(this.iterateIE.GetNodeSet().GetNodeIdMap()[id], out outFactValue) && outFactValue != null && FactValue.GetValueInString(outFactValue.GetFactValueType(), outFactValue) != null)
                                                               .ToList();



                if (this.givenListSize == numberOfDeterminedSecondLevelNode.Count && this.iterateIE.HasAllMandatoryChildAnswered(this.nodeId))
                {
                    canBeSelfEvaluated = true;
                }
            }



            return(canBeSelfEvaluated);
        }
Beispiel #11
0
        ///*
        // * this method is used when a givenList does NOT exist
        // */
        public void IterateFeedAnswers(Node targetNode, string questionName, FactValue nodeValue, NodeSet parentNodeSet, AssessmentState parentAst, Assessment ass)
        {
            if (this.iterateNodeSet == null)
            {
                Node firstIterateQuestionNode = parentNodeSet.GetNodeByNodeId(parentNodeSet.GetDependencyMatrix().GetToChildDependencyList(this.GetNodeId()).Min());
                if (questionName.Equals(firstIterateQuestionNode.GetNodeName()))
                {
                    this.givenListSize = Int32.Parse(FactValue.GetValueInString(nodeValue.GetFactValueType(), nodeValue));
                }
                this.iterateNodeSet = CreateIterateNodeSet(parentNodeSet);
                this.iterateIE      = new InferenceEngine(this.iterateNodeSet);
                if (this.iterateIE.GetAssessment() == null)
                {
                    this.iterateIE.SetAssessment(new Assessment(this.iterateNodeSet, this.GetNodeName()));
                }
            }
            this.iterateIE.GetAssessment().SetNodeToBeAsked(targetNode);
            this.iterateIE.FeedAnswerToNode(targetNode, questionName, nodeValue, this.iterateIE.GetAssessment());

            Dictionary <string, FactValue> iterateWorkingMemory = this.iterateIE.GetAssessmentState().GetWorkingMemory();
            Dictionary <string, FactValue> parentWorkingMemory  = parentAst.GetWorkingMemory();

            TranseferFactValue(iterateWorkingMemory, parentWorkingMemory);
        }
Beispiel #12
0
        protected void SetValue(string lastTokenstring, string lastToken)
        {
            switch (lastTokenstring)
            {
            case "No":
                int intValue = 0;
                Int32.TryParse(lastToken, out intValue);

                this.value = FactValue.Parse(intValue);
                break;

            case "Do":
                double doubleValue = 0.0;
                Double.TryParse(lastToken, out doubleValue);

                this.value = FactValue.Parse(doubleValue);
                break;

            case "Da":
                DateTime dateValue;
                DateTime.TryParseExact(lastToken, "dd/MM/yyyy", null, System.Globalization.DateTimeStyles.None, out dateValue);

                this.value = FactValue.Parse(dateValue);
                break;

            case "Url":
                this.value = FactValue.ParseURL(lastToken);
                break;

            case "Id":
                this.value = FactValue.ParseUUID(lastToken);
                break;

            case "Ha":
                this.value = FactValue.ParseHash(lastToken);
                break;

            case "Q":
                this.value = FactValue.ParseDefiString(lastToken);
                break;

            case "L":
            case "M":
            case "U":
            case "C":
                if (this.IsBoolean(lastToken))
                {
                    this.value = string.Equals(lastToken, "false", StringComparison.OrdinalIgnoreCase)? FactValue.Parse(false) : FactValue.Parse(true);
                }
                else
                {
                    Regex regex = new Regex(@"^([""\“])(.*)([""\”]$)");

                    Match match = regex.Match(lastToken);

                    if (match.Success)
                    {
                        string newS = match.Groups[2].Value;
                        this.value = FactValue.ParseDefiString(newS);
                    }
                    else
                    {
                        this.value = FactValue.Parse(lastToken);
                    }
                }
                break;
            }
        }
Beispiel #13
0
        public NodeSet CreateIterateNodeSet(NodeSet parentNodeSet)
        {
            DependencyMatrix          parentDM        = parentNodeSet.GetDependencyMatrix();
            Dictionary <string, Node> parentNodeMap   = parentNodeSet.GetNodeMap();
            Dictionary <int?, string> parentNodeIdMap = parentNodeSet.GetNodeIdMap();


            Dictionary <string, Node> thisNodeMap        = new Dictionary <string, Node>();
            Dictionary <int?, string> thisNodeIdMap      = new Dictionary <int?, string>();
            List <Dependency>         tempDependencyList = new List <Dependency>();
            NodeSet newNodeSet = new NodeSet();

            thisNodeMap.Add(this.nodeName, this);
            thisNodeIdMap.Add(this.nodeId, this.nodeName);
            Enumerable.Range(1, this.givenListSize).ToList().ForEach((nth) =>
            {
                parentDM.GetToChildDependencyList(this.nodeId).ForEach((item) =>
                {
                    if (this.GetNodeId() + 1 != item) // not first question id
                    {
                        Node tempChildNode = parentNodeMap[parentNodeIdMap[item]];
                        LineType lineType  = tempChildNode.GetLineType();

                        Node tempNode          = null;
                        string nextNThInString = Oridinal(nth);

                        if (lineType.Equals(LineType.VALUE_CONCLUSION))
                        {
                            tempNode = new ValueConclusionLine(nextNThInString + " " + this.GetVariableName() + " " + tempChildNode.GetNodeName(), tempChildNode.GetTokens());
                        }
                        else if (lineType.Equals(LineType.COMPARISON))
                        {
                            tempNode             = new ComparisonLine(nextNThInString + " " + this.GetVariableName() + " " + tempChildNode.GetNodeName(), tempChildNode.GetTokens());
                            FactValue tempNodeFv = ((ComparisonLine)tempNode).GetRHS();
                            if (tempNodeFv.GetFactValueType().Equals(FactValueType.STRING))
                            {
                                FactValue tempFv = FactValue.Parse(nextNThInString + " " + this.GetVariableName() + " " + FactValue.GetValueInString(FactValueType.STRING, tempNodeFv));
                                tempNode.SetValue(tempFv);
                            }
                        }
                        else if (lineType.Equals(LineType.EXPR_CONCLUSION))
                        {
                            tempNode = new ExprConclusionLine(nextNThInString + " " + this.GetVariableName() + " " + tempChildNode.GetNodeName(), tempChildNode.GetTokens());
                        }


                        thisNodeMap.Add(tempNode.GetNodeName(), tempNode);
                        thisNodeIdMap.Add(tempNode.GetNodeId(), tempNode.GetNodeName());
                        tempDependencyList.Add(new Dependency(this, tempNode, parentDM.GetDependencyType(this.nodeId, item)));

                        CreateIterateNodeSetAux(parentDM, parentNodeMap, parentNodeIdMap, thisNodeMap, thisNodeIdMap, tempDependencyList, item, tempNode.GetNodeId(), nextNThInString);
                    }
                    else // first question id
                    {
                        Node firstIterateQuestionNode = parentNodeSet.GetNodeByNodeId(parentNodeSet.GetDependencyMatrix().GetToChildDependencyList(this.GetNodeId()).Min());
                        if (!thisNodeMap.ContainsKey(firstIterateQuestionNode.GetNodeName()))
                        {
                            thisNodeMap.Add(firstIterateQuestionNode.GetNodeName(), firstIterateQuestionNode);
                            thisNodeIdMap.Add(item, firstIterateQuestionNode.GetNodeName());
                            tempDependencyList.Add(new Dependency(this, firstIterateQuestionNode, parentDM.GetDependencyType(this.nodeId, item)));
                        }
                    }
                });
            });



            int numberOfRules = Node.GetStaticNodeId();

            int[,] dependencyMatrix = new int[numberOfRules, numberOfRules];


            tempDependencyList.ForEach(dp => {
                int parentId = dp.GetParentNode().GetNodeId();
                int childId  = dp.GetChildNode().GetNodeId();
                int dpType   = dp.GetDependencyType();
                dependencyMatrix[parentId, childId] = dpType;
            });



            newNodeSet.SetNodeIdMap(thisNodeIdMap);
            newNodeSet.SetNodeMap(thisNodeMap);
            newNodeSet.SetDependencyMatrix(new DependencyMatrix(dependencyMatrix));
            newNodeSet.SetFactMap(parentNodeSet.GetFactMap());
            newNodeSet.SetNodeSortedList(TopoSort.DfsTopoSort(thisNodeMap, thisNodeIdMap, dependencyMatrix));
            //      newNodeSet.getNodeSortedList().stream().forEachOrdered(item->System.out.println(item.getNodeId()+"="+item.getNodeName()));
            return(newNodeSet);
        }
        public override FactValue SelfEvaluate(Dictionary <string, FactValue> workingMemory, Jint.Engine jint)
        {
            /*
             * calculation can only handle int, double(long) and difference in years between two dates at the moment.
             * if difference in days or months is required then new 'keyword' must be introduced such as 'Diff Years', 'Diff Days', or 'Diff Months'
             */
            string equationInString = FactValue.GetValueInString(this.equation.GetFactValueType(), this.equation);
            string pattern          = @"[-+/*()?:;,.""](\s*)";
            string datePattern      = @"([0-2]?[0-9]|3[0-1])/(0?[0-9]|1[0-2])/([0-9][0-9])?[0-9][0-9]|([0-9][0-9])?[0-9][0-9]/(0?[0-9]|1[0-2])/([0-2]?[0-9]|3[0-1])";


            /*
             * logic for this is as follows;
             *  1. replace all variables with actual values from 'workingMemory'
             *  2. find out if equation is about date (difference in years) calculation or not
             *  3. if it is about date then call 'java.time.LocalDate'and 'java.time.temporal.ChronoUnit' package then do the calculation
             *  3-1. if it is about int or double(long) then use plain Javascript
             *
             */

            string script     = equationInString;
            string tempScript = script;
            string result;

            if (Regex.IsMatch(equationInString, pattern))
            {
                string[] tempArray       = Regex.Split(equationInString, pattern);
                int      tempArrayLength = tempArray.Length;
                string   tempItem;
                for (int i = 0; i < tempArrayLength; i++)
                {
                    tempItem = tempArray[i];
                    if (!string.IsNullOrEmpty(tempItem.Trim()) && (workingMemory.ContainsKey(tempItem.Trim()) && workingMemory[tempItem.Trim()] != null))
                    {
                        FactValue tempFv = workingMemory[tempItem.Trim()];
                        if (tempFv.GetFactValueType().Equals(FactValueType.DATE))
                        {
                            /*
                             * below line is temporary solution.
                             * Within next iteration it needs to be that this node should take dateFormatter for its constructor to determine which date format it needs
                             */
                            string tempStr = DateTime.ParseExact(FactValue.GetValueInString(tempFv.GetFactValueType(), tempFv), dateFormatter, CultureInfo.InvariantCulture).ToString().Split(' ')[0].Trim();
                            tempScript = tempScript.Replace(tempItem.Trim(), tempStr);
                        }
                        else
                        {
                            tempScript = tempScript.Replace(tempItem.Trim(), FactValue.GetValueInString(workingMemory[tempItem.Trim()].GetFactValueType(), workingMemory[tempItem.Trim()]).Trim());
                        }
                    }
                }
            }



            MatchCollection dateMatcher  = Regex.Matches(tempScript, datePattern);
            List <DateTime> dateTimeList = new List <DateTime>();

            if (dateMatcher.Count > 0)
            {
                foreach (Match match in dateMatcher)
                {
                    string[] datetimeString = Regex.Split(match.Groups[0].ToString(), @"/");
                    int      year           = 0;
                    int      month          = 0;
                    int      day            = 0;
                    if (Int32.TryParse(datetimeString[2], out year) && Int32.TryParse(datetimeString[1], out month) && Int32.TryParse(datetimeString[0], out day))
                    {
                        dateTimeList.Add(new DateTime(year, month, day));
                    }
                }

                result = (dateTimeList[0].Subtract(dateTimeList[1]).TotalDays / 365.25).ToString();
            }
            else
            {
                result = jint.Execute(tempScript).GetCompletionValue().ToString();
            }

            FactValue returnValue = null;

            switch (Tokenizer.GetTokens(result).tokensString)
            {
            case "No":
                int intResult = 0;
                Int32.TryParse(result, out intResult);
                returnValue = FactValue.Parse(intResult);
                break;

            case "De":
                returnValue = FactValue.Parse(Convert.ToDouble(result));
                break;

            //there is no function for outcome to be a date at the moment  E.g.The determination IS CALC(enrollment date + 5 days)
            //case "Da":
            default:
                returnValue = FactValue.Parse(result);
                break;
            }

            return(returnValue);
        }
Beispiel #15
0
        public void HandleChild(string parentText, string childText, string firstKeywordsGroup, int lineNumber)
        {
            /*
             * the reason for using '*' at the last group of pattern within comparison is that
             * the last group contains No, Da, De, Ha, Url, Id.
             * In order to track more than one character within the square bracket of last group '*'(Matches 0 or more occurrences of the preceding expression) needs to be used.
             *
             */
            int dependencyType = 0;

            // is 'ITEM' child line
            if (Regex.Match(childText, "(ITEM)(.*)").Success)
            {
                if (!Regex.Match(parentText, "(.*)(AS LIST)").Success)
                {
                    HandleWarning(childText);
                    return;
                }

                // is an indented item child

                childText = childText.Remove(childText.IndexOf("ITEM", StringComparison.CurrentCulture), "ITEM".Length).Trim();

                MetaType?metaType = null;
                if (Regex.Match(parentText, "^(INPUT)(.*)").Success)
                {
                    metaType = MetaType.INPUT;
                }
                else if (Regex.Match(parentText, "^(FIXED)(.*)").Success)
                {
                    metaType = MetaType.FIXED;
                }
                HandleListItem(parentText, childText, metaType);
            }
            else  // is 'A-statement', 'A IS B', 'A <= B', or 'A IS CALC (B * C)' child line
            {
                if (Regex.Match(firstKeywordsGroup, "^(AND\\s?)(.*)").Success)
                {
                    dependencyType = HandleNotKnownManOptPos(firstKeywordsGroup, DependencyType.GetAnd()); // 8-AND | 1-KNOWN? 2-NOT? 64-MANDATORY? 32-OPTIONALLY? 16-POSSIBLY?
                }
                else if (Regex.Match(firstKeywordsGroup, "^(OR\\s?)(.*)").Success)
                {
                    dependencyType = HandleNotKnownManOptPos(firstKeywordsGroup, DependencyType.GetOr()); // 4-OR | 1-KNOWN? 2-NOT? 64-MANDATORY? 32-OPTIONALLY? 16-POSSIBLY?
                }
                else if (Regex.Match(firstKeywordsGroup, "^(WANTS)").Success)
                {
                    dependencyType = DependencyType.GetOr(); // 4-OR
                }
                else if (Regex.Match(firstKeywordsGroup, "^(NEEDS)").Success)
                {
                    dependencyType = DependencyType.GetMandatory() | DependencyType.GetAnd();  //  8-AND | 64-MANDATORY
                }


                /*
                 * the keyword of 'AND' or 'OR' should be removed individually.
                 * it should NOT be removed by using firstToken string in Tokens.tokensList.get(0)
                 * because firstToken string may have something else.
                 * (e.g. string: 'AND NOT ALL Males' name should sound Male', then Token string will be 'UMLM', and 'U' contains 'AND NOT ALL'.
                 * so if we used 'firstToken string' to remove 'AND' in this case as 'string.replace(firstTokenString)'
                 * then it will remove 'AND NOT ALL' even we only need to remove 'AND'
                 *
                 */


                Node data = null;
                nodeSet.GetNodeMap().TryGetValue(childText, out data);
                Tokens tokens = Tokenizer.GetTokens(childText);

                if (data == null)
                {
                    Regex[]       matchPatterns = { VALUE_MATCHER, COMPARISON_MATCHER, ITERATE_MATCHER, EXPRESSION_CONCLUSION_MATCHER, WARNING_MATCHER };
                    Node          tempNode;
                    List <string> possibleChildNodeKeyList;

                    for (int i = 0; i < matchPatterns.Length; i++)
                    {
                        Regex regex = matchPatterns[i];
                        Match match = regex.Match(tokens.tokensString);

                        if (match.Success)
                        {
                            switch (i)
                            {
                            case 4:      // warningMatcher case
                                HandleWarning(childText);
                                break;

                            case 0:      // valueConclusionMatcher case
                                data = new ValueConclusionLine(childText, tokens);

                                tempNode = data;
                                possibleChildNodeKeyList = nodeSet.GetNodeMap().Keys.Where(key => Regex.Match(key, "^(" + tempNode.GetVariableName() + ")(\\s+(IS(?!(\\s+IN\\s+LIST))).*)*$").Success).ToList();

                                if (possibleChildNodeKeyList.Count != 0)
                                {
                                    possibleChildNodeKeyList.ForEach(item => {
                                        this.dependencyList.Add(new Dependency(tempNode, nodeSet.GetNodeMap()[item], DependencyType.GetOr()));     //Dependency Type :OR
                                    });
                                }

                                if (FactValue.GetValueInString(data.GetFactValue().GetFactValueType(), data.GetFactValue()).Equals("WARNING"))
                                {
                                    HandleWarning(parentText);
                                }
                                break;

                            case 1:      // comparisonMatcher case
                                data = new ComparisonLine(childText, tokens);

                                FactValueType rhsType   = ((ComparisonLine)data).GetRHS().GetFactValueType();
                                string        rhsString = FactValue.GetValueInString(((ComparisonLine)data).GetRHS().GetFactValueType(), ((ComparisonLine)data).GetRHS());
                                string        lhsString = ((ComparisonLine)data).GetLHS();
                                tempNode = data;
                                possibleChildNodeKeyList = rhsType.Equals(FactValueType.STRING) ?
                                                           nodeSet.GetNodeMap().Keys.Where(key => Regex.Match(key, "^(" + lhsString + ")(\\s+(IS(?!(\\s+IN\\s+LIST))).*)*$").Success || Regex.Match(key, "^(" + rhsString + ")(\\s+(IS(?!(\\s+IN\\s+LIST))).*)*$").Success).ToList()
                                                                :
                                                           nodeSet.GetNodeMap().Keys.Where(key => Regex.Match(key, "^(" + lhsString + ")(\\s+(IS(?!(\\s+IN\\s+LIST))).*)*$").Success).ToList();

                                if (possibleChildNodeKeyList.Count != 0)
                                {
                                    possibleChildNodeKeyList.ForEach(item => {
                                        this.dependencyList.Add(new Dependency(tempNode, nodeSet.GetNodeMap()[item], DependencyType.GetOr()));     //Dependency Type :OR
                                    });
                                }

                                if (FactValue.GetValueInString(data.GetFactValue().GetFactValueType(), data.GetFactValue()).Equals("WARNING"))
                                {
                                    HandleWarning(parentText);
                                }
                                break;

                            case 2:      // iteratenMatcher case
                                data = new IterateLine(childText, tokens);
                                if (FactValue.GetValueInString(data.GetFactValue().GetFactValueType(), data.GetFactValue()).Equals("WARNING"))
                                {
                                    HandleWarning(parentText);
                                }
                                break;

                            case 3: //exprConclusionMatcher case
                                data = new ExprConclusionLine(childText, tokens);

                                /*
                                 * In this case, there is no mechanism to find possible parent nodes.
                                 * I have brought 'local variable' concept for this case due to it may massed up with structuring node dependency tree with topological sort
                                 * If ExprConclusion node is used as a child, then it means that this node is a local node which has to be strictly bound to its parent node only.
                                 */

                                if (FactValue.GetValueInString(data.GetFactValue().GetFactValueType(), data.GetFactValue()).Equals("WARNING"))
                                {
                                    HandleWarning(parentText);
                                }
                                break;
                            }
                            data.SetNodeLine(lineNumber);
                            this.nodeSet.GetNodeMap().Add(data.GetNodeName(), data);
                            this.nodeSet.GetNodeIdMap().Add(data.GetNodeId(), data.GetNodeName());
                            break;
                        }
                    }
                }

                this.dependencyList.Add(new Dependency(this.nodeSet.GetNode(parentText), data, dependencyType));
            }
        }
Beispiel #16
0
        /*
         * this method is used when a givenList exists as a string
         */
        public void IterateFeedAnswers(string givenJsonString, NodeSet parentNodeSet, AssessmentState parentAst, Assessment ass) // this method uses JSON object via jackson library
        {
            /*
             *      givenJsonString has to be in same format as Example otherwise the engine would NOT be able to enable 'IterateLine' node
             *      --------------------------- "givenJsonString" Format ----------------------------
             *
             *      string givenJsonString = "{
             *                                  \"iterateLineVariableName\":
             *                                      [
             *                                        {
             *                                          \"1st iterateLineVariableName\":
             *                                              {
             *                                                \"1st iterateLineVariableName ruleNme1\":\"..value..\",
             *                                                \"1st iterateLineVariableName ruleNme2\":\"..value..\"
             *                                              }
             *                                        },
             *                                        {
             *                                          \"2nd iterateLineVariableName\":
             *                                              {
             *                                                \"2nd iterateLineVariableName ruleName1\":\"..value..\",
             *                                                \"2nd iterateLineVariableName ruleName2\":\"..value..\"}
             *                                        }
             *                                      ]
             *                               }";
             *
             *     -----------------------------  "givenJsonString" Example ----------------------------
             *     string givenJsonString = "{
             *                                  \"service\":
             *                                      [
             *                                        {
             *                                          \"1st service\":
             *                                              {
             *                                                \"1st service period\":\"..value..\",
             *                                                \"1st service type\":\"..value..\"
             *                                              }
             *                                        },
             *                                        {
             *                                          \"2nd service\":
             *                                              {
             *                                                \"2nd service period\":\"..value..\",
             *                                                \"2nd service type\":\"..value..\"}
             *                                        }
             *                                      ]
             *                               }";
             */
            JObject       jObject     = JObject.Parse(givenJsonString);
            List <JToken> serviceList = jObject.Property(this.variableName).ToList();

            this.givenListSize = serviceList.Count;

            if (this.iterateNodeSet == null)
            {
                this.iterateNodeSet = CreateIterateNodeSet(parentNodeSet);
                this.iterateIE      = new InferenceEngine(this.iterateNodeSet);
                if (this.iterateIE.GetAssessment() == null)
                {
                    this.iterateIE.SetAssessment(new Assessment(this.iterateNodeSet, this.GetNodeName()));
                }
            }
            while (!this.iterateIE.GetAssessmentState().GetWorkingMemory().ContainsKey(this.nodeName))
            {
                Node   nextQuestionNode = GetIterateNextQuestion(parentNodeSet, parentAst);
                string answer           = "";
                Dictionary <string, FactValueType> questionFvtMap = this.iterateIE.FindTypeOfElementToBeAsked(nextQuestionNode);
                foreach (string question in this.iterateIE.GetQuestionsFromNodeToBeAsked(nextQuestionNode))
                {
                    //    answer = jObject.GetValue(this.variableName)
                    //                    .SelectToken
                    //        jsonObj.get(this.variableName)
                    //                    .get(nextQuestionNode.getVariableName().substring(0, nextQuestionNode.getVariableName().lastIndexOf(this.variableName) + this.variableName.length()))
                    //                    .get(nextQuestionNode.getVariableName())
                    //                    .asText().trim();

                    this.iterateIE.FeedAnswerToNode(nextQuestionNode, question, FactValue.Parse(answer), this.iterateIE.GetAssessment());
                }

                Dictionary <string, FactValue> iterateWorkingMemory = this.iterateIE.GetAssessmentState().GetWorkingMemory();
                Dictionary <String, FactValue> parentWorkingMemory  = parentAst.GetWorkingMemory();

                TranseferFactValue(iterateWorkingMemory, parentWorkingMemory);
            }
        }
Beispiel #17
0
        public void CreateIterateNodeSetAux(DependencyMatrix parentDM, Dictionary <string, Node> parentNodeMap, Dictionary <int?, string> parentNodeIdMap, Dictionary <string, Node> thisNodeMap, Dictionary <int?, string> thisNodeIdMap, List <Dependency> tempDependencyList, int originalParentId, int modifiedParentId, string nextNThInString)
        {
            List <int> childDependencyList = parentDM.GetToChildDependencyList(originalParentId);

            if (childDependencyList.Count > 0)
            {
                childDependencyList.ForEach((item) => {
                    Node tempChildNode = parentNodeMap[parentNodeIdMap[item]];
                    LineType lt        = tempChildNode.GetLineType();

                    Node tempNode;
                    thisNodeMap.TryGetValue(nextNThInString + " " + this.GetVariableName() + " " + tempChildNode.GetNodeName(), out tempNode);
                    if (tempNode == null)
                    {
                        if (lt.Equals(LineType.VALUE_CONCLUSION))
                        {
                            tempNode = new ValueConclusionLine(nextNThInString + " " + this.GetVariableName() + " " + tempChildNode.GetNodeName(), tempChildNode.GetTokens());

                            if (parentNodeMap[parentNodeIdMap[originalParentId]].GetLineType().Equals(LineType.EXPR_CONCLUSION))
                            {
                                ExprConclusionLine exprTempNode = thisNodeMap[thisNodeIdMap[modifiedParentId]] as ExprConclusionLine;
                                string replacedString           = FactValue.GetValueInString(exprTempNode.GetEquation().GetFactValueType(), exprTempNode.GetEquation()).Replace(tempChildNode.GetNodeName(), nextNThInString + " " + this.GetVariableName() + " " + tempChildNode.GetNodeName());
                                exprTempNode.SetValue(FactValue.Parse(replacedString));
                                exprTempNode.SetEquation(FactValue.Parse(replacedString));
                            }
                        }
                        else if (lt.Equals(LineType.COMPARISON))
                        {
                            tempNode             = new ComparisonLine(nextNThInString + " " + this.GetVariableName() + " " + tempChildNode.GetNodeName(), tempChildNode.GetTokens());
                            FactValue tempNodeFv = ((ComparisonLine)tempNode).GetRHS();
                            if (tempNodeFv.GetFactValueType().Equals(FactValueType.STRING))
                            {
                                FactValue tempFv = FactValue.Parse(nextNThInString + " " + this.GetVariableName() + " " + tempNodeFv);
                                tempNode.SetValue(tempFv);
                            }
                        }
                        else if (lt.Equals(LineType.EXPR_CONCLUSION))
                        {
                            tempNode = new ExprConclusionLine(nextNThInString + " " + this.GetVariableName() + " " + tempChildNode.GetNodeName(), tempChildNode.GetTokens());
                        }
                    }
                    else
                    {
                        if (lt.Equals(LineType.VALUE_CONCLUSION) && parentNodeMap[parentNodeIdMap[originalParentId]].GetLineType().Equals(LineType.EXPR_CONCLUSION))
                        {
                            ExprConclusionLine exprTempNode = ((ExprConclusionLine)thisNodeMap[thisNodeIdMap[modifiedParentId]]);
                            string replacedString           = FactValue.GetValueInString(exprTempNode.GetEquation().GetFactValueType(), exprTempNode.GetEquation()).Replace(tempChildNode.GetNodeName(), nextNThInString + " " + this.GetVariableName() + " " + tempChildNode.GetNodeName());
                            exprTempNode.SetValue(FactValue.Parse(replacedString));
                            exprTempNode.SetEquation(FactValue.Parse(replacedString));
                        }
                    }

                    if (!thisNodeMap.ContainsKey(tempNode.GetNodeName()))
                    {
                        thisNodeMap.Add(tempNode.GetNodeName(), tempNode);
                        thisNodeIdMap.Add(tempNode.GetNodeId(), tempNode.GetNodeName());
                        tempDependencyList.Add(new Dependency(thisNodeMap[thisNodeIdMap[modifiedParentId]], tempNode, parentDM.GetDependencyType(originalParentId, item)));

                        CreateIterateNodeSetAux(parentDM, parentNodeMap, parentNodeIdMap, thisNodeMap, thisNodeIdMap, tempDependencyList, item, tempNode.GetNodeId(), nextNThInString);
                    }
                });
            }
        }
Beispiel #18
0
        public void SetValue(string valueInString, Tokens tokens)
        {
            int    tokenStringListSize = tokens.tokensStringList.Count;
            string lastTokenString     = tokens.tokensStringList[tokenStringListSize - 1];

            string[] tempArray = Regex.Split(valueInString, " ");
            string   tempStr   = tempArray[0];

            if (metaType.Equals(MetaType.FIXED))
            {
                if (tempStr.Equals("IS"))
                {
                    if (this.IsDate(lastTokenString))
                    {
                        DateTime factValueInDate;
                        DateTime.TryParseExact(tempArray[1], "dd/MM/yyyy", null, System.Globalization.DateTimeStyles.None, out factValueInDate);

                        this.value = FactValue.Parse(factValueInDate);
                    }
                    else if (this.IsDouble(lastTokenString))
                    {
                        double tempDouble = Double.Parse(tempArray[1]);
                        this.value = FactValue.Parse(tempDouble);
                    }
                    else if (this.IsInteger(lastTokenString))
                    {
                        int tempInt = Int32.Parse(tempArray[1]);
                        this.value = FactValue.Parse(tempInt);
                    }
                    else if (this.IsBoolean(tempArray[1]))
                    {
                        this.value = tempArray[1].ToLower().Equals("false") ? FactValue.Parse(false) : FactValue.Parse(true);
                    }
                    else if (this.IsHash(lastTokenString))
                    {
                        this.value = FactValue.ParseHash(tempArray[1]);
                    }
                    else if (this.IsURL(lastTokenString))
                    {
                        this.value = FactValue.ParseURL(tempArray[1]);
                    }
                    else if (this.IsGUID(lastTokenString))
                    {
                        this.value = FactValue.ParseUUID(tempArray[1]);
                    }
                }
                else if (tempStr.Equals("AS"))
                {
                    if (tempArray[1].Equals("LIST"))
                    {
                        this.value = FactValue.Parse(new List <FactValue>());
                    }
                    else
                    {
                        this.value = FactValue.Parse("WARNING");
                    }
                }
            }
            else if (metaType.Equals(MetaType.INPUT))
            {
                if (tempArray.Length > 1)
                {
                    /*
                     * within this case 'DefaultValue' will be set due to the statement format is as follows;
                     * 'A AS 'TEXT' IS B'
                     * and 'A' is variable, 'TEXT' is a type of variable, and 'B' is a default value.
                     * if the type is 'LIST' then variable is a list then the factValue has a default value.
                     */
                    String tempStr2 = tempArray[2];

                    if (FactValueType.LIST.ToString().Equals(tempStr))
                    {
                        List <FactValue> valueList = new List <FactValue>();
                        FactValue        tempValue;
                        if (this.IsDate(lastTokenString)) // tempStr2 is date value
                        {
                            DateTime factValueInDate;
                            DateTime.TryParseExact(tempStr2, "dd/MM/yyyy", null, System.Globalization.DateTimeStyles.None, out factValueInDate);
                            tempValue = FactValue.Parse(factValueInDate);
                            valueList.Add(tempValue);
                        }
                        else if (this.IsDouble(lastTokenString)) //tempStr2 is double value
                        {
                            double tempDouble = Double.Parse(tempStr2);
                            tempValue = FactValue.Parse(tempDouble);
                            valueList.Add(tempValue);
                        }
                        else if (this.IsInteger(lastTokenString)) //tempStr2 is integer value
                        {
                            int tempInt = Int32.Parse(tempStr2);
                            tempValue = FactValue.Parse(tempInt);
                            valueList.Add(tempValue);
                        }
                        else if (this.IsHash(lastTokenString)) //tempStr2 is integer value
                        {
                            tempValue = FactValue.ParseHash(tempStr2);
                            valueList.Add(tempValue);
                        }
                        else if (this.IsURL(lastTokenString)) //tempStr2 is integer value
                        {
                            tempValue = FactValue.ParseURL(tempStr2);
                            valueList.Add(tempValue);
                        }
                        else if (this.IsGUID(lastTokenString)) //tempStr2 is integer value
                        {
                            tempValue = FactValue.ParseUUID(tempStr2);
                            valueList.Add(tempValue);
                        }
                        else if (this.IsBoolean(tempStr2)) // tempStr2 is boolean value
                        {
                            if (tempStr2.ToLower().Equals("false"))
                            {
                                tempValue = FactValue.Parse(false);
                            }
                            else
                            {
                                tempValue = FactValue.Parse(true);
                            }
                            valueList.Add(tempValue);
                        }
                        else // tempStr2 is String value
                        {
                            tempValue = FactValue.Parse(tempStr2);
                            valueList.Add(tempValue);
                        }

                        this.value = FactValue.Parse(valueList);
                        ((FactListValue)this.value).SetDefaultValue(tempValue);
                    }
                    else if (FactValueType.TEXT.ToString().Equals(tempStr))
                    {
                        this.value = FactValue.Parse(tempStr2);
                    }
                    else if (FactValueType.DATE.ToString().Equals(tempStr))
                    {
                        DateTime factValueInDate;
                        DateTime.TryParseExact(tempStr2, "dd/MM/yyyy", null, System.Globalization.DateTimeStyles.None, out factValueInDate);

                        this.value = FactValue.Parse(factValueInDate);
                    }
                    else if (FactValueType.NUMBER.ToString().Equals(tempStr))
                    {
                        int factValueInInteger = Int32.Parse(tempStr2);
                        this.value = FactValue.Parse(factValueInInteger);
                    }
                    else if (FactValueType.DECIMAL.ToString().Equals(tempStr))
                    {
                        double factValueInDouble = Double.Parse(tempStr2);
                        this.value = FactValue.Parse(factValueInDouble);
                    }
                    else if (FactValueType.BOOLEAN.ToString().Equals(tempStr))
                    {
                        if (tempStr2.ToLower().Equals("true"))
                        {
                            this.value = FactValue.Parse(true);
                        }
                        else
                        {
                            this.value = FactValue.Parse(false);
                        }
                    }
                    else if (FactValueType.URL.ToString().Equals(tempStr))
                    {
                        this.value = FactValue.ParseURL(tempStr2);
                    }
                    else if (FactValueType.HASH.ToString().Equals(tempStr))
                    {
                        this.value = FactValue.ParseHash(tempStr2);
                    }
                    else if (FactValueType.UUID.ToString().Equals(tempStr))
                    {
                        this.value = FactValue.ParseUUID(tempStr2);
                    }
                }
                else
                {
                    /*
                     * case of the statement does not have value, only contains a type of the variable
                     * so that the value will not have any default values
                     */
                    if (FactValueType.LIST.ToString().Equals(tempStr))
                    {
                        this.value = FactValue.Parse(new List <FactValue>());
                    }
                    else if (FactValueType.TEXT.ToString().Equals(tempStr) || FactValueType.URL.ToString().Equals(tempStr) || FactValueType.HASH.ToString().Equals(tempStr) || FactValueType.UUID.ToString().Equals(tempStr))
                    {
                        this.value = FactValue.Parse(" ");
                    }
                    else if (FactValueType.DATE.ToString().Equals(tempStr))
                    {
                        this.value = FactValue.Parse(DateTime.MinValue);
                    }
                    else if (FactValueType.NUMBER.ToString().Equals(tempStr))
                    {
                        this.value = FactValue.Parse(-1111);
                    }
                    else if (FactValueType.DECIMAL.ToString().Equals(tempStr))
                    {
                        this.value = FactValue.Parse(-0.1111);
                    }
                    else if (FactValueType.BOOLEAN.ToString().Equals(tempStr))
                    {
                        this.value = FactValue.Parse(Boolean.TrueString);
                    }
                }
            }
        }
Beispiel #19
0
        public override FactValue SelfEvaluate(Dictionary <string, FactValue> workingMemory, Jint.Engine nashorn)
        {
            FactValue fv = null;

            return(fv);
        }
 public void SetEquation(FactValue newEquation)
 {
     this.equation = newEquation;
 }
Beispiel #21
0
        public void HandleParent(string parentText, int lineNumber)
        {
            Node data = nodeSet.GetNodeMap().ContainsKey(parentText)?nodeSet.GetNodeMap()[parentText]:null;

            if (data == null)
            {
                Tokens tokens = Tokenizer.GetTokens(parentText);

                Regex[] matchPatterns = { META_PATTERN_MATCHER, VALUE_MATCHER, EXPRESSION_CONCLUSION_MATCHER, WARNING_MATCHER };

                for (int i = 0; i < matchPatterns.Length; i++)
                {
                    //matcher = Regex.Match(tokens.tokensString, matchPatterns[i]);
                    Regex regex = matchPatterns[i];
                    Match match = regex.Match(tokens.tokensString);
                    if (match.Success)
                    {
                        string        variableName;
                        Node          tempNode;
                        List <string> possibleParentNodeKeyList;
                        switch (i)
                        {
                        case 3:      //warningMatcher case
                            HandleWarning(parentText);
                            break;

                        case 0:      //metaMatcher case
                            data = new MetadataLine(parentText, tokens);

                            if (data.GetFactValue().GetFactValueType() != FactValueType.LIST && FactValue.GetValueInString(data.GetFactValue().GetFactValueType(), data.GetFactValue()).Equals("WARNING"))
                            {
                                HandleWarning(parentText);
                            }
                            break;

                        case 1:     //valueConclusionLine case
                            data = new ValueConclusionLine(parentText, tokens);
                            if (match.Groups[2] != null ||
                                (tokens.tokensString.Equals("L") || tokens.tokensString.Equals("LM") || tokens.tokensString.Equals("ML") || tokens.tokensString.Equals("M")))
                            {
                                variableName = data.GetVariableName();
                                tempNode     = data;

                                /*
                                 * following lines are to look for any nodes having a its nodeName with any operators due to the reason that
                                 * the node could be used to define a node previously used as a child node for other nodes
                                 */
                                possibleParentNodeKeyList = nodeSet.GetNodeMap().Keys.Where(key => Regex.Match(key, "(.+)?(\\s[<>=]+\\s?)?(" + variableName + ")(\\s?[<>=]+)*(?!(.*(IS)))(.*(IS IN LIST).*)*").Success).ToList();
                                if (possibleParentNodeKeyList.Count != 0)
                                {
                                    possibleParentNodeKeyList.ForEach(item => {
                                        this.dependencyList.Add(new Dependency(nodeSet.GetNodeMap()[item], tempNode, DependencyType.GetOr()));     //Dependency Type :OR
                                    });
                                }
                            }
                            if (FactValue.GetValueInString(data.GetFactValue().GetFactValueType(), data.GetFactValue()).Equals("WARNING"))
                            {
                                HandleWarning(parentText);
                            }
                            break;

                        case 2:     //exprConclusionMatcher case
                            data = new ExprConclusionLine(parentText, tokens);

                            variableName = data.GetVariableName();
                            tempNode     = data;

                            /*
                             * following lines are to look for any nodes having a its nodeName with any operators due to the reason that
                             * the exprConclusion node could be used to define another node as a child node for other nodes if the variableName of exprConclusion node is mentioned somewhere else.
                             * However, it is excluding nodes having 'IS' keyword because if it has the keyword then it should have child nodes to define the node otherwise the entire rule set has NOT been written in correct way
                             */
                            possibleParentNodeKeyList = nodeSet.GetNodeMap().Keys.Where(key => Regex.Match(key, "(.+)?(\\s[<>=]+\\s?)?(" + variableName + ")(\\s?[<>=]+)*(?!(.*(IS)))(.*(IS IN LIST).*)*").Success).ToList();
                            if (possibleParentNodeKeyList.Count != 0)
                            {
                                possibleParentNodeKeyList.ForEach(item => {
                                    this.dependencyList.Add(new Dependency(nodeSet.GetNodeMap()[item], tempNode, DependencyType.GetOr()));     //Dependency Type :OR
                                });
                            }
                            if (FactValue.GetValueInString(data.GetFactValue().GetFactValueType(), data.GetFactValue()).Equals("WARNING"))
                            {
                                HandleWarning(parentText);
                            }
                            break;

                        default:
                            HandleWarning(parentText);
                            break;
                        }
                        data.SetNodeLine(lineNumber);
                        if (data.GetLineType().Equals(LineType.META))
                        {
                            if (((MetadataLine)data).GetMetaType().Equals(MetaType.INPUT))
                            {
                                this.nodeSet.GetInputMap().Add(data.GetVariableName(), data.GetFactValue());
                            }
                            else if (((MetadataLine)data).GetMetaType().Equals(MetaType.FIXED))
                            {
                                this.nodeSet.GetFactMap().Add(data.GetVariableName(), data.GetFactValue());
                            }
                        }
                        else
                        {
                            this.nodeSet.GetNodeMap().Add(data.GetNodeName(), data);
                            this.nodeSet.GetNodeIdMap().Add(data.GetNodeId(), data.GetNodeName());
                        }
                        break;
                    }
                }
            }
        }
Beispiel #22
0
        public override FactValue SelfEvaluate(Dictionary <string, FactValue> workingMemory, Jint.Engine jint)
        {
            /*
             * Negation type can only be used for this line type
             *
             */

            FactValue workingMemoryLhsValue = workingMemory.ContainsKey(this.variableName) ? workingMemory[this.variableName] : null;
            string    rhsValueInString      = FactValue.GetValueInString(this.GetRHS().GetFactValueType(), this.GetRHS());

            FactValue workingMemoryRhsValue = this.GetRHS().GetFactValueType().Equals(FactValueType.STRING) ?
                                              workingMemory[rhsValueInString]
                                                     :
                                              this.GetRHS();

            String script = "";

            /*
             * There will NOT be the case of that workingMemoryRhsValue is null because the node must be in following format;
             * - A = 12231 (int or double)
             * - A = Adam sandler (String)
             * - A = 11/11/1977 (Date)
             * - A = 123123dfae1421412aer(Hash)
             * - A = 1241414-12421312-142421312(UUID)
             * - A = true(Boolean)
             * - A = www.aiBrain.com(URL)
             * - A = B(another variable)
             */

            /*
             * if it is about date comparison then string of 'script' needs rewriting
             */
            if ((workingMemoryLhsValue != null && workingMemoryLhsValue.GetFactValueType().Equals(FactValueType.DATE)) || (workingMemoryRhsValue != null && workingMemoryRhsValue.GetFactValueType().Equals(FactValueType.DATE)))
            {
                Boolean returnValue;
                switch (this.operatorString)
                {
                case ">":
                    returnValue = (((FactDateValue)workingMemoryLhsValue).GetValue()).CompareTo((((FactDateValue)workingMemoryRhsValue).GetValue())) > 0 ? true : false;
                    return(FactValue.Parse(returnValue));

                case ">=":
                    returnValue = (((FactDateValue)workingMemoryLhsValue).GetValue()).CompareTo((((FactDateValue)workingMemoryRhsValue).GetValue())) >= 0 ? true : false;
                    return(FactValue.Parse(returnValue));

                case "<":
                    returnValue = (((FactDateValue)workingMemoryLhsValue).GetValue()).CompareTo((((FactDateValue)workingMemoryRhsValue).GetValue())) < 0 ? true : false;
                    return(FactValue.Parse(returnValue));

                case "<=":
                    returnValue = (((FactDateValue)workingMemoryLhsValue).GetValue()).CompareTo((((FactDateValue)workingMemoryRhsValue).GetValue())) <= 0 ? true : false;
                    return(FactValue.Parse(returnValue));
                }
                //          script = "new Date("+((FactDateValue)workingMemoryLhsValue).getValue().getYear()+"/"+((FactDateValue)workingMemoryLhsValue).getValue().getMonthValue()+"/"+((FactDateValue)workingMemoryLhsValue).getValue().getDayOfMonth()+")"+operator+"new Date("+((FactDateValue)workingMemoryRhsValue).getValue().getYear()+"/"+((FactDateValue)workingMemoryRhsValue).getValue().getMonthValue()+"/"+((FactDateValue)workingMemoryRhsValue).getValue().getDayOfMonth()+");" ;
            }
            else if (workingMemoryLhsValue != null && (workingMemoryLhsValue.GetFactValueType().Equals(FactValueType.DECIMAL) || workingMemoryLhsValue.GetFactValueType().Equals(FactValueType.DOUBLE) ||
                                                       workingMemoryLhsValue.GetFactValueType().Equals(FactValueType.INTEGER) || workingMemoryLhsValue.GetFactValueType().Equals(FactValueType.NUMBER)))
            {
                script = FactValue.GetValueInString(workingMemoryLhsValue.GetFactValueType(), workingMemoryLhsValue) + operatorString + FactValue.GetValueInString(workingMemoryRhsValue.GetFactValueType(), workingMemoryRhsValue);
            }
            else
            {
                if (workingMemoryRhsValue != null && workingMemoryLhsValue != null)
                {
                    script = "'" + FactValue.GetValueInString(workingMemoryLhsValue.GetFactValueType(), workingMemoryLhsValue) + "' " + operatorString + " '" + FactValue.GetValueInString(workingMemoryRhsValue.GetFactValueType(), workingMemoryRhsValue) + "'";
                }
            }
            Boolean   result;
            FactValue fv = null;

            if (workingMemoryRhsValue != null && workingMemoryLhsValue != null)
            {
                result = Convert.ToBoolean(jint.Execute(script).GetCompletionValue().ToString());
                fv     = FactValue.Parse(result);
            }


            return(fv);
        }
Beispiel #23
0
 public void SetValue(FactValue fv)
 {
     this.value = fv;
 }