Exemple #1
0
 // check if a value could satisfy part of the expression
 public bool CheckKey(string attributeName, AtomValue valueToCheck)
 {
     if (this.SimpleMinterms.ContainsKey(attributeName))
     {
         AtomValue result = this.SimpleMinterms[attributeName].Calculate(new List <AttributeValue>
         {
             new AttributeValue(attributeName, new AtomValue()
             {
                 Type         = valueToCheck.Type,
                 CharLimit    = valueToCheck.CharLimit,
                 FloatValue   = valueToCheck.FloatValue,
                 IntegerValue = valueToCheck.IntegerValue,
             })
         });
         return(result.BooleanValue);
     }
     else
     {
         return(true);
     }
 }
Exemple #2
0
        // get the value of this Expression
        public AtomValue Calculate(List <AttributeValue> row)
        {
            // fetch value from symbol table (from `row`)
            if (this.Operator == Operator.AtomVariable)
            {
                AttributeValue column = row.Find(x => x.AttributeName == this.AttributeName);
                if (object.ReferenceEquals(column, null))
                {
                    throw new System.Exception($"Attribute \"{this.AttributeName}\" does not exist in this table");
                }
                return(column.Value);
            }

            // directly return the concrete value
            if (this.Operator == Operator.AtomConcreteValue)
            {
                return(this.ConcreteValue);
            }

            // fetch the values of children
            AtomValue leftValue  = this.LeftOperand?.Calculate(row);
            AtomValue rightValue = this.RightOperand?.Calculate(row);
            AtomValue result     = null;

            // // make sure the types of children are the same
            // if (leftValue?.Type != rightValue?.Type)
            // {
            //     throw new System.Exception("OpersimpleMinterms type not matched!");
            // }

            // calculate the two children into a value
            switch (this.Operator)
            {
            case Operator.AtomVariable:
                throw new System.Exception("AtomVariable is not supposed to reach this step");

            case Operator.AtomConcreteValue:
                throw new System.Exception("AtomConcreteValue is not supposed to reach this step");

            case Operator.Plus:
                result = leftValue + rightValue;
                break;

            case Operator.Minus:
                result = leftValue - rightValue;
                break;

            case Operator.Multiply:
                result = leftValue * rightValue;
                break;

            case Operator.Divide:
                result = leftValue / rightValue;
                break;

            case Operator.Negative:
                result = -leftValue;
                break;

            case Operator.And:
                result              = new AtomValue();
                result.Type         = AttributeTypes.Int;
                result.IntegerValue = (leftValue.BooleanValue && rightValue.BooleanValue)? 1 : 0;
                break;

            case Operator.Or:
                result              = new AtomValue();
                result.Type         = AttributeTypes.Int;
                result.IntegerValue = (leftValue.BooleanValue || rightValue.BooleanValue)? 1 : 0;
                break;

            case Operator.Xor:
                result              = new AtomValue();
                result.Type         = AttributeTypes.Int;
                result.IntegerValue = (leftValue.BooleanValue != rightValue.BooleanValue)? 1 : 0;
                break;

            case Operator.Not:
                result = !leftValue;
                break;

            case Operator.LessThan:
                result = leftValue < rightValue;
                break;

            case Operator.MoreThan:
                result = leftValue > rightValue;
                break;

            case Operator.Equal:
                result = leftValue == rightValue;
                break;

            case Operator.NotEqual:
                result = leftValue != rightValue;
                break;

            case Operator.LessThanOrEqualTo:
                result = leftValue <= rightValue;
                break;

            case Operator.MoreThanOrEqualTo:
                result = leftValue >= rightValue;
                break;
            }
            return(result);
        }