Beispiel #1
0
        private static void TstFuzzyLogicNonNumericSequenceValue()
        {
            _logger.Log("Begin");

            var sequence = new FuzzyLogicNonNumericSequenceValue();

            _logger.Log($"sequence = {sequence}");
            _logger.Log($"sequence = {sequence.ToDbgString()}");

            var very = NameHelper.CreateName("very");

            sequence.AddIdentifier(very);

            _logger.Log($"sequence = {sequence}");
            _logger.Log($"sequence = {sequence.ToDbgString()}");

            var teenager = NameHelper.CreateName("teenager");

            sequence.AddIdentifier(teenager);

            sequence.CheckDirty();

            _logger.Log($"sequence = {sequence}");
            _logger.Log($"sequence = {sequence.ToDbgString()}");

            _logger.Log("End");
        }
Beispiel #2
0
        private static string FuzzyLogicNonNumericSequenceValueToString(FuzzyLogicNonNumericSequenceValue value)
        {
            var sb = new StringBuilder(value.DebugView);

            sb.Append(AnnotatedItemToString(value));
            return(sb.ToString());
        }
Beispiel #3
0
        public NumberValue Resolve(FuzzyLogicNonNumericSequenceValue fuzzyLogicNonNumericSequence, ReasonOfFuzzyLogicResolving reason, LocalCodeExecutionContext localCodeExecutionContext, ResolverOptions options)
        {
#if DEBUG
            //Log($"fuzzyLogicNonNumericSequence = {fuzzyLogicNonNumericSequence}");
#endif

            var targetItem = GetTargetFuzzyLogicNonNumericValue(fuzzyLogicNonNumericSequence.NonNumericValue, null, reason, localCodeExecutionContext, options);

#if DEBUG
            //Log($"targetItem = {targetItem}");
#endif

            if (targetItem == null)
            {
                return(new NumberValue(null));
            }

            var operatorsList = GetFuzzyLogicOperators(targetItem.Parent, fuzzyLogicNonNumericSequence.Operators).Select(p => p.Handler);

#if DEBUG
            //Log($"operatorsList.Count = {operatorsList.Count}");
#endif

            var fuzzyValue = targetItem.Handler.Defuzzificate(operatorsList).SystemValue.Value;

#if DEBUG
            //Log($"fuzzyValue = {fuzzyValue}");
#endif

            return(new NumberValue(fuzzyValue));
        }
Beispiel #4
0
        public bool Equals(FuzzyLogicNonNumericSequenceValue fuzzyLogicNonNumericSequence, NumberValue value, ReasonOfFuzzyLogicResolving reason, LocalCodeExecutionContext localCodeExecutionContext, ResolverOptions options)
        {
#if DEBUG
            //Log($"fuzzyLogicNonNumericSequence = {fuzzyLogicNonNumericSequence}");
            //Log($"value = {value}");
#endif

            var targetItem = GetTargetFuzzyLogicNonNumericValue(fuzzyLogicNonNumericSequence.NonNumericValue, value, reason, localCodeExecutionContext, options);

#if DEBUG
            //Log($"targetItem = {targetItem}");
#endif

            if (targetItem == null)
            {
                return(false);
            }

            var fuzzyValue = targetItem.Handler.SystemCall(value);

#if DEBUG
            //Log($"fuzzyValue = {fuzzyValue}");
#endif

            var operatorsList = GetFuzzyLogicOperators(targetItem.Parent, fuzzyLogicNonNumericSequence.Operators);

#if DEBUG
            //Log($"operatorsList.Count = {operatorsList.Count}");
#endif

            foreach (var op in operatorsList)
            {
#if DEBUG
                //Log($"op = {op}");
#endif

                fuzzyValue = op.Handler.SystemCall(fuzzyValue);
            }

#if DEBUG
            //Log($"fuzzyValue (after) = {fuzzyValue}");
#endif

            return(FuzzyNumericValueToSystemBool(fuzzyValue));
        }
Beispiel #5
0
        private void StartProcessingFuzzyLogicNonNumericSequenceValue(StrongIdentifierValue value)
        {
            _fuzzyLogicNonNumericSequenceValue = new FuzzyLogicNonNumericSequenceValue();

            var node = new LogicalQueryNode();

            node.Kind = KindOfLogicalQueryNode.FuzzyLogicNonNumericSequence;

            node.FuzzyLogicNonNumericSequenceValue = _fuzzyLogicNonNumericSequenceValue;

            _fuzzyLogicNonNumericSequenceValue.AddIdentifier(value);

            var intermediateNode = new IntermediateAstNode(node);

            AstNodesLinker.SetNode(intermediateNode, _nodePoint);

            _state = State.GotFuzzyLogicNonNumericSequenceItem;
        }
Beispiel #6
0
 public NumberValue Resolve(FuzzyLogicNonNumericSequenceValue fuzzyLogicNonNumericSequence, ReasonOfFuzzyLogicResolving reason, LocalCodeExecutionContext localCodeExecutionContext)
 {
     return(Resolve(fuzzyLogicNonNumericSequence, reason, localCodeExecutionContext, _defaultOptions));
 }
Beispiel #7
0
 public NumberValue Resolve(FuzzyLogicNonNumericSequenceValue fuzzyLogicNonNumericSequence, LocalCodeExecutionContext localCodeExecutionContext)
 {
     return(Resolve(fuzzyLogicNonNumericSequence, null, localCodeExecutionContext, _defaultOptions));
 }
Beispiel #8
0
 public bool Equals(FuzzyLogicNonNumericSequenceValue fuzzyLogicNonNumericSequence, NumberValue value, LocalCodeExecutionContext localCodeExecutionContext)
 {
     return(Equals(fuzzyLogicNonNumericSequence, value, null, localCodeExecutionContext, _defaultOptions));
 }
Beispiel #9
0
        /// <inheritdoc/>
        protected override void OnRun()
        {
#if DEBUG
            //Log($"_state = {_state}");
            //Log($"_currToken = {_currToken}");
            //Log($"Result = {Result}");
            //Log($"_currentItem = {_currentItem}");
#endif

            switch (_state)
            {
            case State.Init:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Word:
                    switch (_currToken.KeyWordTokenKind)
                    {
                    case KeyWordTokenKind.Is:
                        _state = State.WaitForItem;
                        break;

                    default:
                        throw new UnexpectedTokenException(_currToken);
                    }
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.WaitForItem:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Word:
                    TryCreateCurrentItem();

                    _currentItem.Rank = new LogicalValue(1.0F);

                    _currentItem.SuperName = ParseName(_currToken.Content);
                    _state = State.GotSuperName;
                    break;

                case TokenKind.OpenSquareBracket:
                    _state = State.WaitForRank;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotSuperName:
                switch (_currToken.TokenKind)
                {
                case TokenKind.OpenFigureBracket:
                    _context.Recovery(_currToken);
                    Exit();
                    break;

                case TokenKind.Comma:
                    _currentItem = null;
                    _state       = State.WaitForItem;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.WaitForRank:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Number:
                {
                    TryCreateCurrentItem();

                    _context.Recovery(_currToken);
                    var parser = new NumberParser(_context, true);
                    parser.Run();
                    _currentItem.Rank = parser.Result;
                    _state            = State.GotRankValue;
                }
                break;

                case TokenKind.Identifier:
                case TokenKind.Word:
                {
                    TryCreateCurrentItem();

                    var nextToken = _context.GetToken();

#if DEBUG
                    //Log($"nextToken = {nextToken}");
#endif

                    switch (nextToken.TokenKind)
                    {
                    case TokenKind.Word:
                    case TokenKind.Identifier:
                        _context.Recovery(nextToken);

                        _fuzzyLogicNonNumericSequenceValue = new FuzzyLogicNonNumericSequenceValue();
                        _fuzzyLogicNonNumericSequenceValue.AddIdentifier(ParseName(_currToken.Content));

                        _state = State.GotFuzzyLogicNonNumericSequenceItem;
                        break;

                    default:
                        _context.Recovery(nextToken);

                        _currentItem.Rank = ParseName(_currToken.Content);

                        _state = State.GotRankValue;
                        break;
                    }
                }
                break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotFuzzyLogicNonNumericSequenceItem:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Word:
                case TokenKind.Identifier:
                    _fuzzyLogicNonNumericSequenceValue.AddIdentifier(ParseName(_currToken.Content));

                    _state = State.GotFuzzyLogicNonNumericSequenceItem;
                    break;

                case TokenKind.CloseSquareBracket:
                    _currentItem.Rank = _fuzzyLogicNonNumericSequenceValue;
                    _state            = State.GotRank;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotRankValue:
                switch (_currToken.TokenKind)
                {
                case TokenKind.CloseSquareBracket:
                    _state = State.GotRank;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotRank:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Word:
                    TryCreateCurrentItem();

                    _currentItem.SuperName = ParseName(_currToken.Content);
                    _state = State.GotSuperName;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(_state), _state, null);
            }
        }
Beispiel #10
0
        /// <inheritdoc/>
        protected override void OnRun()
        {
#if DEBUG
            Log($"_state = {_state}");
            Log($"_currToken = {_currToken}");
            //Log($"_rawStatement = {_rawStatement}");
            //Log($"Result = {Result}");
#endif

            switch (_state)
            {
            case State.Init:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Word:
                    switch (_currToken.KeyWordTokenKind)
                    {
                    case KeyWordTokenKind.Use:
                        _state = State.GotUse;
                        break;

                    default:
                        throw new UnexpectedTokenException(_currToken);
                    }
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotUse:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Word:
                case TokenKind.SystemVar:
                    _rawStatement.FirstName = ParseName(_currToken.Content);
                    _state = State.GotFirstName;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotFirstName:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Word:
                    switch (_currToken.KeyWordTokenKind)
                    {
                    case KeyWordTokenKind.Is:
                        _state = State.GotIs;
                        break;

                    default:
                        throw new UnexpectedTokenException(_currToken);
                    }
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotIs:
                switch (_currToken.TokenKind)
                {
                case TokenKind.OpenSquareBracket:
                    _state = State.WaitForInheritanceRank;
                    break;

                case TokenKind.Word:
                    switch (_currToken.KeyWordTokenKind)
                    {
                    case KeyWordTokenKind.Not:
                        _rawStatement.HasNot = true;
                        _state = State.GotIsNot;
                        break;

                    case KeyWordTokenKind.Unknown:
                    default:
                        ProcessGotUseInheritanceSecondName();
                        break;
                    }
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotIsNot:
                switch (_currToken.TokenKind)
                {
                case TokenKind.OpenSquareBracket:
                    _state = State.WaitForInheritanceRank;
                    break;

                case TokenKind.Word:
                    ProcessGotUseInheritanceSecondName();
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotSecondName:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Semicolon:
                    Exit();
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.WaitForInheritanceRank:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Number:
                {
                    _context.Recovery(_currToken);
                    var parser = new NumberParser(_context, true);
                    parser.Run();
                    _rawStatement.Rank = parser.Result;
                    _state             = State.GotInheritanceRankValue;
                }
                break;

                case TokenKind.Identifier:
                case TokenKind.Word:
                {
                    var nextToken = _context.GetToken();

#if DEBUG
                    //Log($"nextToken = {nextToken}");
#endif
                    switch (nextToken.TokenKind)
                    {
                    case TokenKind.Word:
                    case TokenKind.Identifier:
                        _context.Recovery(nextToken);

                        _fuzzyLogicNonNumericSequenceValue = new FuzzyLogicNonNumericSequenceValue();
                        _fuzzyLogicNonNumericSequenceValue.AddIdentifier(ParseName(_currToken.Content));

                        _state = State.GotFuzzyLogicNonNumericSequenceItem;
                        break;

                    default:
                        _context.Recovery(nextToken);

                        _rawStatement.Rank = ParseName(_currToken.Content);

                        _state = State.GotInheritanceRankValue;
                        break;
                    }
                }
                break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotFuzzyLogicNonNumericSequenceItem:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Word:
                case TokenKind.Identifier:
                    _fuzzyLogicNonNumericSequenceValue.AddIdentifier(ParseName(_currToken.Content));

                    _state = State.GotFuzzyLogicNonNumericSequenceItem;
                    break;

                case TokenKind.CloseSquareBracket:
                    _rawStatement.Rank = _fuzzyLogicNonNumericSequenceValue;
                    _state             = State.GotInheritanceRank;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotInheritanceRankValue:
                switch (_currToken.TokenKind)
                {
                case TokenKind.CloseSquareBracket:
                    _state = State.GotInheritanceRank;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotInheritanceRank:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Word:
                    ProcessGotUseInheritanceSecondName();
                    break;

                //case TokenKind.Semicolon:
                //    Exit();
                //    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

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