예제 #1
0
        public void EstablishNodeSet(Dictionary <string, Record> recordMapOfNodes)
        {
            NodeSet ns = scanFeeder.GetNodeSet();

            ns.SetDependencyMatrix(scanFeeder.CreateDependencyMatrix());
            List <Node> sortedList = TopoSort.DfsTopoSort(ns.GetNodeMap(), ns.GetNodeIdMap(), ns.GetDependencyMatrix().GetDependencyMatrixArray(), recordMapOfNodes);

            if (sortedList.Count != 0)
            {
                ns.SetNodeSortedList(sortedList);
            }
            else
            {
                scanFeeder.HandleWarning("RuleSet needs rewriting due to it is cyclic.");
            }
        }
예제 #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);
        }