Exemple #1
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);
        }
Exemple #2
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);
                    }
                });
            }
        }