コード例 #1
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);
        }
コード例 #2
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);
        }
コード例 #3
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);
            }
        }