Ejemplo n.º 1
0
        /// <summary>
        /// AND(Node, ZERO) -> Zero
        /// OR(Node, ZERO) -> Node
        /// NOT(ZERO) -> ALL
        /// </summary>
        /// <returns></returns>
        private static ExpressionTreeNode HandleZeroNode(ExpressionTreeNode node, ref int count)
        {
            if (node == null)
            {
                return(null);
            }

            if (node.Child1?.Operation == "ZERO" || node.Child2?.Operation == "ZERO")
            {
                var otherNode = node.Child1.Operation == "ZERO" ? node.Child2 : node.Child1;

                if (node.Operation == "AND")
                {
                    node = ExpressionTreeNode.CreateAllNode();
                }
                else if (node.Operation == "OR")
                {
                    node = otherNode;
                }
                else if (node.Operation == "NOT")
                {
                    node = ExpressionTreeNode.CreateAllNode();
                }

                count++;
            }

            return(node);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// OR(NOT, NOT) -> ALL - if terms are not equal
        /// OR(NOT, NOT) -> NOT(term) - if terms are equal
        /// </summary>
        /// <param name="node"></param>
        private static ExpressionTreeNode TwoNotInOrRule(ExpressionTreeNode node, ref int count)
        {
            if (node == null)
            {
                return(null);
            }

            if (node.Operation == "OR" && node.Child1.Operation == "NOT" && node.Child2.Operation == "NOT")
            {
                if (node.Child1.Child1.Term == node.Child2.Child1.Term)
                {
                    node = ExpressionTreeNode.CreateNot(node.Child1.Child1);
                }
                else
                {
                    node = ExpressionTreeNode.CreateAllNode();
                }

                count++;
            }

            return(node);
        }