/// <summary>
        /// Clones the instance using special context and returns cloned instance.
        /// </summary>
        /// <param name="context">Special context for providing references continuity.</param>
        /// <returns>Cloned instance.</returns>
        public FuzzyLogicNonNumericSequenceValue Clone(Dictionary <object, object> context)
        {
            if (context.ContainsKey(this))
            {
                return((FuzzyLogicNonNumericSequenceValue)context[this]);
            }

            var result = new FuzzyLogicNonNumericSequenceValue();

            context[this] = result;

            result.NonNumericValue = NonNumericValue?.Clone(context);
            result._operators      = _operators?.Select(p => p.Clone(context)).ToList();

            result.AppendAnnotations(this, context);

            return(result);
        }
Example #2
0
        /// <inheritdoc/>
        protected override ulong CalculateLongHashCode()
        {
#if DEBUG
            //_gbcLogger.Info($"this = {DebugHelperForRuleInstance.ToString(this)}");
#endif

            switch (Kind)
            {
            case KindOfLogicalQueryNode.BinaryOperator:
                switch (KindOfOperator)
                {
                case KindOfOperatorOfLogicalQueryNode.And:
                case KindOfOperatorOfLogicalQueryNode.Or:
                case KindOfOperatorOfLogicalQueryNode.Is:
                case KindOfOperatorOfLogicalQueryNode.IsNot:
                case KindOfOperatorOfLogicalQueryNode.More:
                case KindOfOperatorOfLogicalQueryNode.MoreOrEqual:
                case KindOfOperatorOfLogicalQueryNode.Less:
                case KindOfOperatorOfLogicalQueryNode.LessOrEqual:
                    return(base.CalculateLongHashCode() ^ LongHashCodeWeights.BaseOperatorWeight ^ (ulong)Math.Abs(KindOfOperator.GetHashCode()) ^ Left.GetLongHashCode() ^ Right.GetLongHashCode());

                default:
                    throw new ArgumentOutOfRangeException(nameof(KindOfOperator), KindOfOperator, null);
                }

            case KindOfLogicalQueryNode.UnaryOperator:
                switch (KindOfOperator)
                {
                case KindOfOperatorOfLogicalQueryNode.Not:
                    return(base.CalculateLongHashCode() ^ LongHashCodeWeights.BaseOperatorWeight ^ (ulong)Math.Abs(KindOfOperator.GetHashCode()) ^ Left.GetLongHashCode());

                default:
                    throw new ArgumentOutOfRangeException(nameof(KindOfOperator), KindOfOperator, null);
                }

            case KindOfLogicalQueryNode.Concept:
            case KindOfLogicalQueryNode.Entity:
            case KindOfLogicalQueryNode.QuestionVar:
            case KindOfLogicalQueryNode.LogicalVar:
                return(base.CalculateLongHashCode() ^ Name.GetLongHashCode());

            case KindOfLogicalQueryNode.Value:
                return(base.CalculateLongHashCode() ^ Value.GetLongHashCode());

            case KindOfLogicalQueryNode.FuzzyLogicNonNumericSequence:
                return(base.CalculateLongHashCode() ^ FuzzyLogicNonNumericSequenceValue.GetLongHashCode());

            case KindOfLogicalQueryNode.StubParam:
                return(LongHashCodeWeights.StubWeight ^ base.CalculateLongHashCode());

            case KindOfLogicalQueryNode.EntityCondition:
            case KindOfLogicalQueryNode.EntityRef:
                break;

            case KindOfLogicalQueryNode.Relation:
            {
                var result = base.CalculateLongHashCode() ^ LongHashCodeWeights.BaseFunctionWeight ^ Name.GetLongHashCode();

                foreach (var param in ParamsList)
                {
                    result ^= LongHashCodeWeights.BaseParamWeight ^ param.GetLongHashCode();
                }

                return(result);
            }

            case KindOfLogicalQueryNode.Group:
                return(base.CalculateLongHashCode() ^ LongHashCodeWeights.GroupWeight ^ Left.GetLongHashCode());

            default:
                throw new ArgumentOutOfRangeException(nameof(Kind), Kind, null);
            }

            throw new NotImplementedException();
        }
Example #3
0
        //public bool HasQuestionVars
        //{
        //    get
        //    {
        //        if(IsQuestion)
        //        {
        //            return true;
        //        }

        //        if(Left != null && Left.HasQuestionVars)
        //        {
        //            return true;
        //        }

        //        if(Right != null && Right.HasQuestionVars)
        //        {
        //            return true;
        //        }

        //        if (ParamsList != null && ParamsList.Any(p => p.HasQuestionVars))
        //        {
        //            return true;
        //        }

        //        return false;
        //    }
        //}

        public void PrepareDirty(ContextOfConvertingExpressionNode contextOfConvertingExpressionNode, RuleInstance ruleInstance, BaseRulePart rulePart)
        {
#if DEBUG
            //_gbcLogger.Info($"this = {this}");
            //_gbcLogger.Info($"contextOfConvertingExpressionNode = {contextOfConvertingExpressionNode}");
#endif

            RuleInstance = ruleInstance;
            RulePart     = rulePart;

            switch (Kind)
            {
            case KindOfLogicalQueryNode.BinaryOperator:
                switch (KindOfOperator)
                {
                case KindOfOperatorOfLogicalQueryNode.And:
                case KindOfOperatorOfLogicalQueryNode.Or:
                case KindOfOperatorOfLogicalQueryNode.Is:
                case KindOfOperatorOfLogicalQueryNode.IsNot:
                case KindOfOperatorOfLogicalQueryNode.More:
                case KindOfOperatorOfLogicalQueryNode.MoreOrEqual:
                case KindOfOperatorOfLogicalQueryNode.Less:
                case KindOfOperatorOfLogicalQueryNode.LessOrEqual:
                    Left.PrepareDirty(contextOfConvertingExpressionNode, ruleInstance, rulePart);
                    Right.PrepareDirty(contextOfConvertingExpressionNode, ruleInstance, rulePart);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(KindOfOperator), KindOfOperator, null);
                }
                break;

            case KindOfLogicalQueryNode.UnaryOperator:
                switch (KindOfOperator)
                {
                case KindOfOperatorOfLogicalQueryNode.Not:
                    Left.PrepareDirty(contextOfConvertingExpressionNode, ruleInstance, rulePart);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(KindOfOperator), KindOfOperator, null);
                }
                break;

            case KindOfLogicalQueryNode.Concept:
            case KindOfLogicalQueryNode.Entity:
            case KindOfLogicalQueryNode.QuestionVar:
                Name.CheckDirty();
                break;

            case KindOfLogicalQueryNode.LogicalVar:
                contextOfConvertingExpressionNode.HasVars = true;
                Name.CheckDirty();
                break;

            case KindOfLogicalQueryNode.Value:
            case KindOfLogicalQueryNode.StubParam:
            case KindOfLogicalQueryNode.EntityCondition:
            case KindOfLogicalQueryNode.EntityRef:
                break;

            case KindOfLogicalQueryNode.FuzzyLogicNonNumericSequence:
                FuzzyLogicNonNumericSequenceValue.CheckDirty();
                break;

            case KindOfLogicalQueryNode.Relation:
                Name.CheckDirty();
                if (Name.KindOfName == KindOfName.LogicalVar)
                {
                    IsQuestion = true;
                }
                FillRelationParams(ParamsList, contextOfConvertingExpressionNode);
                break;

            case KindOfLogicalQueryNode.Group:
                Left.PrepareDirty(contextOfConvertingExpressionNode, ruleInstance, rulePart);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(Kind), Kind, null);
            }

#if DEBUG
            //_gbcLogger.Info($"contextOfConvertingExpressionNode (after) = {contextOfConvertingExpressionNode}");
#endif
        }