예제 #1
0
        private Line CreateLine(BoardProperties context, LineType type, int row, int col)
        {
            IEnumerable <Position> positions;

            if (type.Equals(LineType.Row))
            {
                positions = GetRow(context, row);
            }
            else if (type.Equals(LineType.Column))
            {
                positions = GetColumn(context, col);
            }
            else if (type.Equals(LineType.DiagonalOne))
            {
                positions = GetDiagonalOne(context, row, col);
            }
            else if (type.Equals(LineType.DiagonalTwo))
            {
                positions = GetDiagonalTwo(context, row, col);
            }
            else
            {
                throw new ArgumentException(type.ToString());
            }

            return(new Line(type, positions.ToList()));
        }
예제 #2
0
        private IEnumerable <Tuple <int, int> > GetIndexes(BoardProperties context, LineType type)
        {
            if (type.Equals(LineType.Row))
            {
                return(context.RowIndexes.Select(i => new Tuple <int, int>(i, -1)));
            }

            if (type.Equals(LineType.Column))
            {
                return(context.ColIndexes.Select(i => new Tuple <int, int>(-1, i)));
            }

            if (type.Equals(LineType.DiagonalOne))
            {
                return(context.GetDiagonalOneIndexes());
            }

            if (type.Equals(LineType.DiagonalTwo))
            {
                return(context.GetDiagonalTwoIndexes());
            }

            throw new ArgumentOutOfRangeException(string.Format("Unconsidered subclass of Line: '{0}'.", type.ToString()));
        }
예제 #3
0
        private void initialize()
        {
            _editableText = new EditableText(_textComponent, new TextGenerator());

            var caret = CreateCaret();

            if (_lineType.Equals(LineType.SingleLine))
            {
                _impl = new VrInputFieldImpl(caret,
                                             new SingleLineInputProcessor(new System.Text.StringBuilder(), new CaretNavigator(caret, _editableText, this)),
                                             this,
                                             _editableText);
            }
            else
            {
                _impl = new MultiLineInputFieldImpl(caret,
                                                    new BaseTextProcessor(new System.Text.StringBuilder(), new CaretNavigator(caret, _editableText, this)),
                                                    this,
                                                    _editableText);
            }
        }
예제 #4
0
        protected override void Start()
        {
            base.Start();
            _editableText = new EditableText(_textComponent, new TextGenerator());

            var caret = CreateCaret();

            if (_lineType.Equals(LineType.SingleLine))
            {
                Impl = new SingleLineInputField(caret,
                                                new UnityTextProcessor(new System.Text.StringBuilder(), new CaretNavigator(caret, _editableText, this)),
                                                this,
                                                _editableText);
            }
            else
            {
                Impl = new MultiLineInputField(caret,
                                               new UnityTextProcessor(new System.Text.StringBuilder(), new CaretNavigator(caret, _editableText, this)),
                                               this,
                                               _editableText);
            }
        }
예제 #5
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);
        }
예제 #6
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);
                    }
                });
            }
        }
예제 #7
0
        /*
         * this method is to create virtual nodes where a certain node has 'AND' or 'MANDATORY_AND', and 'OR' children at the same time.
         * when a virtual node is created, all 'AND' children should be connected to the virtual node as 'AND' children
         * and the virtual node should be a 'OR' child of the original parent node
         */
        public Dictionary <string, Node> HandlingVirtualNode(List <Dependency> dependencyList)
        {
            Dictionary <string, Node> virtualNodeMap = new Dictionary <string, Node>();


            nodeSet.GetNodeMap().Values.ToList().ForEach((node) => {
                virtualNodeMap.Add(node.GetNodeName(), node);
                List <Dependency> dpList = dependencyList.Where(dp => node.GetNodeName().Equals(dp.GetParentNode().GetNodeName())).ToList();


                /*
                 * need to handle Mandatory, optionally, possibly NodeOptions
                 */
                int and          = 0;
                int mandatoryAnd = 0;
                int or           = 0;
                if (dpList.Count != 0)
                {
                    foreach (Dependency dp in dpList) //can this for each loop be converted to dpList.stream().forEachOrdered() ?
                    {
                        if ((dp.GetDependencyType() & DependencyType.GetAnd()) == DependencyType.GetAnd())
                        {
                            and++;
                            if (dp.GetDependencyType() == (DependencyType.GetMandatory() | DependencyType.GetAnd()))
                            {
                                mandatoryAnd++;
                            }
                        }
                        else if ((dp.GetDependencyType() & DependencyType.GetOr()) == DependencyType.GetOr())
                        {
                            or++;
                        }
                    }
                    bool hasAndOr = (and > 0 && or > 0) ? true : false;
                    if (hasAndOr)
                    {
                        string parentNodeOfVirtualNodeName = node.GetNodeName();
                        LineType nodeLineType = node.GetLineType();
                        Node virtualNode;

                        if (nodeLineType.Equals(LineType.EXPR_CONCLUSION))
                        {
                            virtualNode = new ExprConclusionLine("VirtualNode-" + parentNodeOfVirtualNodeName, Tokenizer.GetTokens("VirtualNode-" + parentNodeOfVirtualNodeName));
                        }
                        else
                        {
                            virtualNode = new ValueConclusionLine("VirtualNode-" + parentNodeOfVirtualNodeName, Tokenizer.GetTokens("VirtualNode-" + parentNodeOfVirtualNodeName));
                        }


                        this.nodeSet.GetNodeIdMap().Add(virtualNode.GetNodeId(), "VirtualNode-" + parentNodeOfVirtualNodeName);
                        virtualNodeMap.Add("VirtualNode-" + parentNodeOfVirtualNodeName, virtualNode);
                        if (mandatoryAnd > 0)
                        {
                            dependencyList.Add(new Dependency(node, virtualNode, (DependencyType.GetMandatory() | DependencyType.GetOr())));
                        }
                        else
                        {
                            dependencyList.Add(new Dependency(node, virtualNode, DependencyType.GetOr()));
                        }
                        dpList.Where(dp => dp.GetDependencyType() == DependencyType.GetAnd() || dp.GetDependencyType() == (DependencyType.GetMandatory() | DependencyType.GetAnd()))
                        .ToList().ForEach(dp => dp.SetParentNode(virtualNode));
                    }
                }
            });
            return(virtualNodeMap);
        }