public ResolverOptions Clone()
        {
            var result = new ResolverOptions();

            result.AddSelf           = AddSelf;
            result.JustDistinct      = JustDistinct;
            result.AddTopType        = AddTopType;
            result.SkipRealSearching = SkipRealSearching;

            return(result);
        }
Beispiel #2
0
        public List <WeightedInheritanceResultItemWithStorageInfo <InlineTrigger> > ResolveSystemEventsTriggersList(KindOfSystemEventOfInlineTrigger kindOfSystemEvent, StrongIdentifierValue holder, LocalCodeExecutionContext localCodeExecutionContext, ResolverOptions options)
        {
#if DEBUG
            //Log($"kindOfSystemEvent = {kindOfSystemEvent}");
            //Log($"holder = {holder}");
#endif

            var storage = localCodeExecutionContext.Storage;

            var storagesList = GetStoragesList(storage);

#if DEBUG
            //Log($"storagesList.Count = {storagesList.Count}");
            //foreach (var tmpStorage in storagesList)
            //{
            //    Log($"tmpStorage.Key = {tmpStorage.Key}; tmpStorage.Value.Kind = '{tmpStorage.Value.Kind}'");
            //}
#endif

            var inheritanceResolver = _context.DataResolversFactory.GetInheritanceResolver();

            var optionsForInheritanceResolver = options.Clone();
            optionsForInheritanceResolver.AddSelf = true;

            var weightedInheritanceItems = inheritanceResolver.GetWeightedInheritanceItems(holder, localCodeExecutionContext, optionsForInheritanceResolver);

#if DEBUG
            //Log($"weightedInheritanceItems = {weightedInheritanceItems.WriteListToString()}");
#endif

            var rawList = GetSystemEventsRawList(kindOfSystemEvent, holder, storagesList, weightedInheritanceItems);

#if DEBUG
            //Log($"rawList = {rawList.WriteListToString()}");
#endif

            return(OrderAndDistinct(rawList, localCodeExecutionContext, options));
        }
 public LogicalValue Resolve(Value source, LocalCodeExecutionContext localCodeExecutionContext, ResolverOptions options)
 {
     return(Resolve(source, localCodeExecutionContext, options, false));
 }
Beispiel #4
0
        public NumberValue Resolve(StrongIdentifierValue name, ReasonOfFuzzyLogicResolving reason, LocalCodeExecutionContext localCodeExecutionContext, ResolverOptions options)
        {
#if DEBUG
            //Log($"name = {name}");
            //Log($"reason = {reason}");
#endif

            var targetItem = GetTargetFuzzyLogicNonNumericValue(name, null, reason, localCodeExecutionContext, options);

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

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

            var fuzzyValue = targetItem.Handler.Defuzzificate();

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

            return(fuzzyValue);
        }
Beispiel #5
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 #6
0
        private Value GetUsualVarValue(StrongIdentifierValue varName, LocalCodeExecutionContext localCodeExecutionContext, ResolverOptions options)
        {
#if DEBUG
            //Log($"varName = {varName}");
#endif

            var storage = localCodeExecutionContext.Storage;

            var storagesList = GetStoragesList(storage);

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

            foreach (var storageItem in storagesList)
            {
#if DEBUG
                //Log($"storageItem.Key = {storageItem.Key}; storageItem.Value.Kind = '{storageItem.Value.Kind}'");
#endif

                var targetValue = storageItem.Storage.VarStorage.GetValueDirectly(varName);

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

                if (targetValue != null)
                {
                    return(targetValue);
                }
            }

            return(new NullValue());
        }
 public IList <WeightedInheritanceItem> GetWeightedInheritanceItems(LocalCodeExecutionContext localCodeExecutionContext, ResolverOptions options)
 {
     return(GetWeightedInheritanceItems(localCodeExecutionContext.Holder, localCodeExecutionContext, options));
 }
        public uint?GetDistance(StrongIdentifierValue typeName, Value value, LocalCodeExecutionContext localCodeExecutionContext, ResolverOptions options)
        {
#if DEBUG
            //Log($"typeName = {typeName}");
            //Log($"value = {value}");
            //if(value.KindOfValue == KindOfValue.StrongIdentifierValue)
            //{
            //    throw new NotImplementedException();
            //}
#endif

            var biltInSuperTypesList = value.BuiltInSuperTypes;

#if DEBUG
            //Log($"biltInSuperTypesList = {biltInSuperTypesList.WriteListToString()}");
#endif

            if (biltInSuperTypesList.Contains(typeName))
            {
                return(0u);
            }

            var distancesList = new List <uint>();

            var newOptions = options.Clone();
            newOptions.AddTopType = false;
            newOptions.AddSelf    = false;

            foreach (var buildInSuperType in biltInSuperTypesList)
            {
#if DEBUG
                //Log($"typeName = {typeName}");
                //Log($"buildInSuperType = {buildInSuperType}");
#endif

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

                var weightedInheritanceItemsList = GetWeightedInheritanceItems(buildInSuperType, localCodeExecutionContext, newOptions);

#if DEBUG
                //Log($"weightedInheritanceItemsList = {weightedInheritanceItemsList.WriteListToString()}");
#endif

                if (!weightedInheritanceItemsList.Any())
                {
                    return(null);
                }

                var targetWeightedInheritanceItemsList = weightedInheritanceItemsList.Where(p => p.SuperName.Equals(typeName)).ToList();

#if DEBUG
                //Log($"targetWeightedInheritanceItemsList = {targetWeightedInheritanceItemsList.WriteListToString()}");
#endif

                if (!targetWeightedInheritanceItemsList.Any())
                {
                    return(null);
                }

                throw new NotImplementedException();
            }

            throw new NotImplementedException();
        }
Beispiel #9
0
        public Channel GetChannel(StrongIdentifierValue name, LocalCodeExecutionContext localCodeExecutionContext, ResolverOptions options)
        {
#if DEBUG
            //Log($"name = {name}");
#endif

            var storage = localCodeExecutionContext.Storage;

            var storagesList = GetStoragesList(storage);

#if DEBUG
            //Log($"storagesList.Count = {storagesList.Count}");
            //foreach (var tmpStorage in storagesList)
            //{
            //    Log($"tmpStorage.Key = {tmpStorage.Key}; tmpStorage.Value.Kind = '{tmpStorage.Value.Kind}'");
            //}
#endif

            var inheritanceResolver = _context.DataResolversFactory.GetInheritanceResolver();

            var optionsForInheritanceResolver = options.Clone();
            optionsForInheritanceResolver.AddSelf = true;

            var weightedInheritanceItems = inheritanceResolver.GetWeightedInheritanceItems(localCodeExecutionContext, optionsForInheritanceResolver);

#if DEBUG
            //Log($"weightedInheritanceItems = {weightedInheritanceItems.WriteListToString()}");
#endif

            var rawList = GetRawList(name, storagesList, weightedInheritanceItems);

#if DEBUG
            //Log($"rawList = {rawList.WriteListToString()}");
#endif

            var filteredList = Filter(rawList);

#if DEBUG
            //Log($"filteredList = {filteredList.WriteListToString()}");
#endif

            var targetChannel = ChooseTargetItem(filteredList);

            return(targetChannel);
        }
        private NamedFunction GetTargetValueFromList(List <WeightedInheritanceResultItemWithStorageInfo <NamedFunction> > source, int paramsCount, LocalCodeExecutionContext localCodeExecutionContext, ResolverOptions options)
        {
#if DEBUG
            //Log($"paramsCount = {paramsCount}");
#endif

            CorrectParametersRankMatrixForSpecialCases(source);

            IOrderedEnumerable <WeightedInheritanceResultItemWithStorageInfo <NamedFunction> > orderedList = null;

            if (paramsCount > 0)
            {
                for (var i = 0; i < paramsCount; i++)
                {
                    switch (i)
                    {
                    case 0:
                        if (orderedList == null)
                        {
                            orderedList = source.OrderBy(p => p.ParametersRankMatrix[0]);
                        }
                        else
                        {
                            orderedList = orderedList.ThenBy(p => p.ParametersRankMatrix[0]);
                        }
                        break;

                    case 1:
                        if (orderedList == null)
                        {
                            orderedList = source.OrderBy(p => p.ParametersRankMatrix[1]);
                        }
                        else
                        {
                            orderedList = orderedList.ThenBy(p => p.ParametersRankMatrix[1]);
                        }
                        break;

                    case 2:
                        if (orderedList == null)
                        {
                            orderedList = source.OrderBy(p => p.ParametersRankMatrix[2]);
                        }
                        else
                        {
                            orderedList = orderedList.ThenBy(p => p.ParametersRankMatrix[2]);
                        }
                        break;

                    case 3:
                        if (orderedList == null)
                        {
                            orderedList = source.OrderBy(p => p.ParametersRankMatrix[3]);
                        }
                        else
                        {
                            orderedList = orderedList.ThenBy(p => p.ParametersRankMatrix[3]);
                        }
                        break;

                    case 4:
                        if (orderedList == null)
                        {
                            orderedList = source.OrderBy(p => p.ParametersRankMatrix[4]);
                        }
                        else
                        {
                            orderedList = orderedList.ThenBy(p => p.ParametersRankMatrix[4]);
                        }
                        break;

                    case 5:
                        if (orderedList == null)
                        {
                            orderedList = source.OrderBy(p => p.ParametersRankMatrix[5]);
                        }
                        else
                        {
                            orderedList = orderedList.ThenBy(p => p.ParametersRankMatrix[5]);
                        }
                        break;

                    case 6:
                        if (orderedList == null)
                        {
                            orderedList = source.OrderBy(p => p.ParametersRankMatrix[6]);
                        }
                        else
                        {
                            orderedList = orderedList.ThenBy(p => p.ParametersRankMatrix[6]);
                        }
                        break;

                    case 7:
                        if (orderedList == null)
                        {
                            orderedList = source.OrderBy(p => p.ParametersRankMatrix[7]);
                        }
                        else
                        {
                            orderedList = orderedList.ThenBy(p => p.ParametersRankMatrix[7]);
                        }
                        break;

                    case 8:
                        if (orderedList == null)
                        {
                            orderedList = source.OrderBy(p => p.ParametersRankMatrix[8]);
                        }
                        else
                        {
                            orderedList = orderedList.ThenBy(p => p.ParametersRankMatrix[8]);
                        }
                        break;

                    case 9:
                        if (orderedList == null)
                        {
                            orderedList = source.OrderBy(p => p.ParametersRankMatrix[9]);
                        }
                        else
                        {
                            orderedList = orderedList.ThenBy(p => p.ParametersRankMatrix[9]);
                        }
                        break;

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

            if (orderedList == null)
            {
                orderedList = source.OrderByDescending(p => p.IsSelf);
            }
            else
            {
                orderedList = orderedList.ThenByDescending(p => p.IsSelf);
            }

            orderedList = orderedList.ThenBy(p => p.Distance).ThenBy(p => p.StorageDistance);

            return(orderedList.FirstOrDefault()?.ResultItem);
        }
        public NamedFunction Resolve(StrongIdentifierValue name, LocalCodeExecutionContext localCodeExecutionContext, ResolverOptions options)
        {
#if DEBUG
            //Log($"name = {name}");
#endif

            var storage = localCodeExecutionContext.Storage;

            var storagesList = GetStoragesList(storage);

#if DEBUG
            //Log($"name = {name}");
            //Log($"value = {value}");
            //Log($"reason = {reason}");
            //Log($"localCodeExecutionContext = {localCodeExecutionContext}");
            //Log($"storagesList.Count = {storagesList.Count}");
            //foreach (var tmpStorage in storagesList)
            //{
            //    Log($"tmpStorage = {tmpStorage}");
            //}
#endif

            var inheritanceResolver = _context.DataResolversFactory.GetInheritanceResolver();

            var optionsForInheritanceResolver = options.Clone();
            optionsForInheritanceResolver.AddSelf = true;

            var weightedInheritanceItems = inheritanceResolver.GetWeightedInheritanceItems(localCodeExecutionContext, optionsForInheritanceResolver);

#if DEBUG
            //Log($"weightedInheritanceItems = {weightedInheritanceItems.WriteListToString()}");
#endif

            var rawList = GetRawList(name, 0, storagesList, weightedInheritanceItems);

#if DEBUG
            //Log($"rawList = {rawList.WriteListToString()}");
#endif

            if (!rawList.Any())
            {
                return(null);
            }

            var filteredList = Filter(rawList);

#if DEBUG
            Log($"filteredList = {filteredList.WriteListToString()}");
#endif

            if (!filteredList.Any())
            {
                return(null);
            }

            if (filteredList.Count == 1)
            {
                return(filteredList.Single().ResultItem);
            }

            return(GetTargetValueFromList(filteredList, 0, localCodeExecutionContext, options));
        }
        private List <uint> IsFit(NamedFunction function, List <Value> positionedParameters, LocalCodeExecutionContext localCodeExecutionContext, ResolverOptions options)
        {
            var inheritanceResolver = _context.DataResolversFactory.GetInheritanceResolver();

            var positionedParametersEnumerator = positionedParameters.GetEnumerator();

            var result = new List <uint>();

            foreach (var argument in function.Arguments)
            {
#if DEBUG
                //Log($"argument = {argument}");
#endif

                if (!positionedParametersEnumerator.MoveNext())
                {
                    if (argument.HasDefaultValue)
                    {
                        result.Add(0u);

                        continue;
                    }

                    throw new NotImplementedException();
                }

                var parameterItem = positionedParametersEnumerator.Current;

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

                var distance = inheritanceResolver.GetDistance(argument.TypesList, parameterItem, localCodeExecutionContext, options);

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

                if (!distance.HasValue)
                {
                    return(null);
                }

                result.Add(distance.Value);
            }

            return(result);
        }
        private List <WeightedInheritanceResultItemWithStorageInfo <NamedFunction> > FilterByTypeOfParameters(List <WeightedInheritanceResultItemWithStorageInfo <NamedFunction> > source, List <Value> positionedParameters, LocalCodeExecutionContext localCodeExecutionContext, ResolverOptions options)
        {
            var result = new List <WeightedInheritanceResultItemWithStorageInfo <NamedFunction> >();

            foreach (var function in source)
            {
                var rankMatrix = IsFit(function.ResultItem, positionedParameters, localCodeExecutionContext, options);

#if DEBUG
                //Log($"rankMatrix = {rankMatrix.WritePODListToString()}");
#endif

                if (rankMatrix == null)
                {
                    continue;
                }

                function.ParametersRankMatrix = rankMatrix;

                result.Add(function);
            }

            return(result);
        }
        private List <uint> IsFit(NamedFunction function, Dictionary <StrongIdentifierValue, Value> namedParameters, LocalCodeExecutionContext localCodeExecutionContext, ResolverOptions options)
        {
#if DEBUG
            //Log($"namedParameters = {namedParameters.WriteDict_1_ToString()}");
#endif

            var inheritanceResolver = _context.DataResolversFactory.GetInheritanceResolver();

            var result = new List <uint>();

            var countOfUsedParameters = 0;

            foreach (var argument in function.Arguments)
            {
#if DEBUG
                //Log($"argument = {argument}");
#endif

                var argumentName = argument.Name;

                if (namedParameters.ContainsKey(argumentName))
                {
                    countOfUsedParameters++;

                    var parameterValue = namedParameters[argumentName];

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

                    var distance = inheritanceResolver.GetDistance(argument.TypesList, parameterValue, localCodeExecutionContext, options);

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

                    if (!distance.HasValue)
                    {
                        return(null);
                    }

                    result.Add(distance.Value);
                }
                else
                {
                    if (argument.HasDefaultValue)
                    {
                        result.Add(0u);

                        continue;
                    }
                    else
                    {
                        return(null);
                    }
                }
            }

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

            if (countOfUsedParameters < namedParameters.Count)
            {
                return(null);
            }

            return(result);
        }
        private void GetWeightedInheritanceItemsBySubName(StrongIdentifierValue subName, LocalCodeExecutionContext localCodeExecutionContext, Dictionary <StrongIdentifierValue, WeightedInheritanceItem> result, float currentRank, uint currentDistance, List <StorageUsingOptions> storagesList)
        {
#if DEBUG
            //Log($"subName = {subName}");
            //Log($"localCodeExecutionContext = {localCodeExecutionContext}");
            //Log($"currentRank = {currentRank}");
            //Log($"currentDistance = {currentDistance}");
            //Log($"result.Count = {result.Count}");
            //foreach(var resultItem in result)
            //{
            //    Log($"resultItem.Key = {resultItem.Key}");
            //    Log($"resultItem.Value.Rank = {resultItem.Value.Rank}");
            //    Log($"resultItem.Value.Distance = {resultItem.Value.Distance}");
            //}
#endif

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

            var rawList = GetRawList(subName, storagesList);

#if DEBUG
            //Log($"rawList = {rawList.WriteListToString()}");
#endif

            if (!rawList.Any())
            {
                return;
            }

            var filteredList = Filter(rawList);

#if DEBUG
            //Log($"filteredList = {filteredList.WriteListToString()}");
#endif

            if (!filteredList.Any())
            {
                return;
            }

            var logicalValueLinearResolver = _context.DataResolversFactory.GetLogicalValueLinearResolver();

            foreach (var filteredItem in filteredList)
            {
                var targetItem = filteredItem.ResultItem;

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

                var resolvedRankValue = logicalValueLinearResolver.Resolve(targetItem.Rank, localCodeExecutionContext, ResolverOptions.GetDefaultOptions(), true);

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

                var systemValue = resolvedRankValue.SystemValue;

                if (!systemValue.HasValue)
                {
                    systemValue = 0.5f;
                }

                var calculatedRank = currentRank * systemValue.Value;

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

                if (calculatedRank == 0)
                {
                    continue;
                }

                var superName = targetItem.SuperName;

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

                if (result.ContainsKey(superName))
                {
                    var item = result[superName];

                    if (item.Rank < calculatedRank)
                    {
                        item.Distance     = currentDistance;
                        item.Rank         = calculatedRank;
                        item.OriginalItem = targetItem;
                    }

#if DEBUG
                    //Log($"item (w 1)= {item}");
#endif
                }
                else
                {
                    var item = new WeightedInheritanceItem();
                    item.SuperName    = superName;
                    item.Distance     = currentDistance;
                    item.Rank         = calculatedRank;
                    item.OriginalItem = targetItem;

#if DEBUG
                    //Log($"item (w 2) = {item}");
#endif

                    result[superName] = item;
                }

                GetWeightedInheritanceItemsBySubName(targetItem.SuperName, localCodeExecutionContext, result, calculatedRank, currentDistance, storagesList);
            }
        }
        public uint?GetDistance(List <StrongIdentifierValue> typeNamesList, Value value, LocalCodeExecutionContext localCodeExecutionContext, ResolverOptions options)
        {
#if DEBUG
            //Log($"typeNamesList = {typeNamesList.WriteListToString()}");
            //Log($"value = {value}");
#endif

            if (typeNamesList.IsNullOrEmpty())
            {
                return(TopTypeDistance);
            }

            value.CheckDirty();

            var distancesList = new List <uint>();

            foreach (var typeName in typeNamesList)
            {
                var typeDistance = GetDistance(typeName, value, localCodeExecutionContext, options);

                if (typeDistance.HasValue)
                {
                    distancesList.Add(typeDistance.Value);
                }
            }

            if (!distancesList.Any())
            {
                return(null);
            }

            return(distancesList.Min());
        }
        public Operator GetOperator(KindOfOperator kindOfOperator, LocalCodeExecutionContext localCodeExecutionContext, ResolverOptions options)
        {
#if DEBUG
            //Log($"kindOfOperator = {kindOfOperator}");
#endif

            var storage = localCodeExecutionContext.Storage;

            var storagesList = GetStoragesList(storage);

#if DEBUG
            //Log($"storagesList.Count = {storagesList.Count}");
            //foreach(var tmpStorage in storagesList)
            //{
            //    Log($"tmpStorage = {tmpStorage}");
            //}
#endif

            var inheritanceResolver = _context.DataResolversFactory.GetInheritanceResolver();

            var optionsForInheritanceResolver = options.Clone();
            optionsForInheritanceResolver.AddSelf = true;

            var weightedInheritanceItems = inheritanceResolver.GetWeightedInheritanceItems(localCodeExecutionContext, optionsForInheritanceResolver);

#if DEBUG
            //Log($"weightedInheritanceItems = {weightedInheritanceItems.WriteListToString()}");
#endif

            var rawList = GetRawList(kindOfOperator, storagesList, weightedInheritanceItems);

#if DEBUG
            //Log($"rawList = {rawList.WriteListToString()}");
#endif

            var filteredList = Filter(rawList);

#if DEBUG
            //Log($"filteredList = {filteredList.WriteListToString()}");
#endif

            var targetOp = ChooseTargetItem(filteredList);

            return(targetOp);
        }
        public Value GetInheritanceRank(StrongIdentifierValue subName, StrongIdentifierValue superName, LocalCodeExecutionContext localCodeExecutionContext, ResolverOptions options)
        {
#if DEBUG
            //Log($"subName = {subName}");
            //Log($"superName = {superName}");
#endif

            var weightedInheritanceItemsList = GetWeightedInheritanceItems(subName, localCodeExecutionContext, options);

#if DEBUG
            //Log($"weightedInheritanceItemsList = {weightedInheritanceItemsList.WriteListToString()}");
#endif

            if (!weightedInheritanceItemsList.Any())
            {
                var result = new LogicalValue(0);
                return(result);
            }

            var targetWeightedInheritanceItemsList = weightedInheritanceItemsList.Where(p => p.SuperName.Equals(superName)).ToList();

#if DEBUG
            //Log($"targetWeightedInheritanceItemsList = {targetWeightedInheritanceItemsList.WriteListToString()}");
#endif

            if (!targetWeightedInheritanceItemsList.Any())
            {
                var result = new LogicalValue(0);
                return(result);
            }

            if (targetWeightedInheritanceItemsList.Count == 1)
            {
                var result = new LogicalValue(targetWeightedInheritanceItemsList.First().Rank);

                return(result);
            }

            throw new NotImplementedException();
        }
Beispiel #19
0
        protected List <WeightedInheritanceResultItemWithStorageInfo <T> > OrderAndDistinctByInheritance <T>(List <WeightedInheritanceResultItemWithStorageInfo <T> > source, ResolverOptions options)
            where T : AnnotatedItem
        {
            if (options.JustDistinct)
            {
                return(source);
            }

            return(source.OrderByDescending(p => p.IsSelf).ToList());
        }
Beispiel #20
0
        public Value GetVarValue(StrongIdentifierValue varName, LocalCodeExecutionContext localCodeExecutionContext, ResolverOptions options)
        {
#if DEBUG
            //Log($"varName = {varName}");
#endif

            if (varName.KindOfName == KindOfName.SystemVar)
            {
                return(GetSystemVarValue(varName, localCodeExecutionContext, options));
            }

            return(GetUsualVarValue(varName, localCodeExecutionContext, options));
        }
        public StrongIdentifierValue Resolve(Value source, LocalCodeExecutionContext localCodeExecutionContext, ResolverOptions options)
        {
#if DEBUG
            //Log($"source = {source}");
#endif

            var sourceKind = source.KindOfValue;

            switch (sourceKind)
            {
            case KindOfValue.StrongIdentifierValue:
                return(source.AsStrongIdentifierValue);

            case KindOfValue.InstanceValue:
                return(source.AsInstanceValue.InstanceInfo.Name);

            default:
                throw new ArgumentOutOfRangeException(nameof(sourceKind), sourceKind, null);
            }
        }
Beispiel #22
0
        public bool Equals(StrongIdentifierValue name, NumberValue value, ReasonOfFuzzyLogicResolving reason, LocalCodeExecutionContext localCodeExecutionContext, ResolverOptions options)
        {
#if DEBUG
            //Log($"name = {name}");
            //Log($"value = {value}");
#endif

            var targetItem = GetTargetFuzzyLogicNonNumericValue(name, 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

            return(FuzzyNumericValueToSystemBool(fuzzyValue));
        }
        public NumberValue Resolve(Value source, LocalCodeExecutionContext localCodeExecutionContext, ResolverOptions options)
        {
#if DEBUG
            //Log($"source = {source}");
#endif

            var sourceKind = source.KindOfValue;

            switch (sourceKind)
            {
            case KindOfValue.NullValue:
                return(ValueConvertor.ConvertNullValueToNumberValue(source.AsNullValue, _context));

            case KindOfValue.LogicalValue:
                return(ValueConvertor.ConvertLogicalValueToNumberValue(source.AsLogicalValue, _context));

            case KindOfValue.NumberValue:
                return(source.AsNumberValue);

            default:
                throw new ArgumentOutOfRangeException(nameof(sourceKind), sourceKind, null);
            }
        }
Beispiel #24
0
        private FuzzyLogicNonNumericValue GetTargetFuzzyLogicNonNumericValue(StrongIdentifierValue name, NumberValue value, ReasonOfFuzzyLogicResolving reason, LocalCodeExecutionContext localCodeExecutionContext, ResolverOptions options)
        {
            var storage = localCodeExecutionContext.Storage;

            var storagesList = GetStoragesList(storage);

#if DEBUG
            //Log($"name = {name}");
            //Log($"value = {value}");
            //Log($"reason = {reason}");
            //Log($"localCodeExecutionContext = {localCodeExecutionContext}");
            //Log($"storagesList.Count = {storagesList.Count}");
            //foreach (var tmpStorage in storagesList)
            //{
            //    Log($"tmpStorage.Key = {tmpStorage.Key}; tmpStorage.Value.Kind = '{tmpStorage.Value.Kind}'");
            //}
#endif

            var inheritanceResolver = _context.DataResolversFactory.GetInheritanceResolver();

            var optionsForInheritanceResolver = options.Clone();
            optionsForInheritanceResolver.AddSelf = true;

            if (reason != null && reason.Kind == KindOfReasonOfFuzzyLogicResolving.Inheritance)
            {
#if DEBUG
                //Log("^%^%^%^%^%^% reason != null && reason.Kind == KindOfReasonOfFuzzyLogicResolving.Inheritance");
#endif

                optionsForInheritanceResolver.SkipRealSearching = true;
                optionsForInheritanceResolver.AddSelf           = false;
            }

            var weightedInheritanceItems = inheritanceResolver.GetWeightedInheritanceItems(localCodeExecutionContext, optionsForInheritanceResolver);

#if DEBUG
            //Log($"weightedInheritanceItems = {weightedInheritanceItems.WriteListToString()}");
#endif

            var rawList = GetRawList(name, storagesList, weightedInheritanceItems);

#if DEBUG
            //Log($"rawList = {rawList.WriteListToString()}");
#endif

            if (!rawList.Any())
            {
                return(null);
            }

            var filteredList = Filter(rawList);

#if DEBUG
            //Log($"filteredList = {filteredList.WriteListToString()}");
#endif

            if (!filteredList.Any())
            {
                return(null);
            }

            if ((reason == null || reason.Kind != KindOfReasonOfFuzzyLogicResolving.Inheritance) && value != null)
            {
                filteredList = filteredList.Where(p => p.ResultItem.Parent.IsFitByRange(value)).ToList();

#if DEBUG
                //Log($"filteredList (2) = {filteredList.WriteListToString()}");
#endif

                if (!filteredList.Any())
                {
                    return(null);
                }
            }

            if (reason != null)
            {
                filteredList = filteredList.Where(p => p.ResultItem.Parent.IsFitByСonstraintOrDontHasСonstraint(reason)).ToList();

#if DEBUG
                //Log($"filteredList (3) = {filteredList.WriteListToString()}");
#endif

                if (!filteredList.Any())
                {
                    return(null);
                }
            }

            return(GetTargetFuzzyLogicNonNumericValueFromList(filteredList, reason));
        }
        public IList <WeightedInheritanceItem> GetWeightedInheritanceItems(StrongIdentifierValue subName, LocalCodeExecutionContext localCodeExecutionContext, ResolverOptions options)
        {
#if DEBUG
            //Log($"localCodeExecutionContext = {localCodeExecutionContext}");
#endif

            var storage = localCodeExecutionContext.Storage;

            var storagesList = GetStoragesList(storage);

#if DEBUG
            //Log($"storagesList.Count = {storagesList.Count}");
            //foreach (var tmpStorage in storagesList)
            //{
            //    Log($"tmpStorage.Storage = {tmpStorage.Storage}");
            //}
#endif

            var rawResult = new Dictionary <StrongIdentifierValue, WeightedInheritanceItem>();

            if (options == null || options.SkipRealSearching == false)
            {
                GetWeightedInheritanceItemsBySubName(subName, localCodeExecutionContext, rawResult, 1, 0, storagesList);
            }

#if DEBUG
            //Log($"rawResult.Count = {rawResult.Count}");
            //foreach (var resultItem in rawResult)
            //{
            //    Log($"resultItem.Key = {resultItem.Key}");
            //    Log($"resultItem.Value.Rank = {resultItem.Value.Rank}");
            //    Log($"resultItem.Value.Distance = {resultItem.Value.Distance}");
            //}
#endif

            var result = rawResult.Select(p => p.Value).ToList();

            if (options.AddTopType)
            {
                result.Add(GetTopTypeWeightedInheritanceItem(subName));
            }

            if (options.AddSelf)
            {
                result.Add(GetSelfWeightedInheritanceItem(subName));
            }

            return(OrderAndDistinct(result, localCodeExecutionContext, options));
        }
Beispiel #26
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));
        }
 private List <WeightedInheritanceItem> OrderAndDistinct(List <WeightedInheritanceItem> source, LocalCodeExecutionContext localCodeExecutionContext, ResolverOptions options)
 {
     return(source.OrderByDescending(p => p.IsSelf).ToList());
 }
        public LogicalValue Resolve(Value source, LocalCodeExecutionContext localCodeExecutionContext, ResolverOptions options, bool forInheritance)
        {
#if DEBUG
            //Log($"source = {source}");
#endif

            var sourceKind = source.KindOfValue;

            switch (sourceKind)
            {
            case KindOfValue.NullValue:
                return(ValueConvertor.ConvertNullValueToLogicalValue(source.AsNullValue, _context));

            case KindOfValue.LogicalValue:
                return(source.AsLogicalValue);

            case KindOfValue.NumberValue:
                return(ValueConvertor.ConvertNumberValueToLogicalValue(source.AsNumberValue, _context));

            case KindOfValue.StrongIdentifierValue:
            {
                ReasonOfFuzzyLogicResolving reasonOfFuzzyLogicResolving = null;

                if (forInheritance)
                {
                    reasonOfFuzzyLogicResolving = new ReasonOfFuzzyLogicResolving()
                    {
                        Kind = KindOfReasonOfFuzzyLogicResolving.Inheritance
                    };
                }

                return(ValueConvertor.ConvertNumberValueToLogicalValue(_context.DataResolversFactory.GetFuzzyLogicResolver().Resolve(source.AsStrongIdentifierValue, reasonOfFuzzyLogicResolving, localCodeExecutionContext, options), _context));
            }


            case KindOfValue.FuzzyLogicNonNumericSequenceValue:
            {
                ReasonOfFuzzyLogicResolving reasonOfFuzzyLogicResolving = null;

                if (forInheritance)
                {
                    reasonOfFuzzyLogicResolving = new ReasonOfFuzzyLogicResolving()
                    {
                        Kind = KindOfReasonOfFuzzyLogicResolving.Inheritance
                    };
                }

                return(ValueConvertor.ConvertNumberValueToLogicalValue(_context.DataResolversFactory.GetFuzzyLogicResolver().Resolve(source.AsFuzzyLogicNonNumericSequenceValue, reasonOfFuzzyLogicResolving, localCodeExecutionContext, options), _context));
            }

            default:
                throw new ArgumentOutOfRangeException(nameof(sourceKind), sourceKind, null);
            }
        }
Beispiel #29
0
        private List <WeightedInheritanceResultItemWithStorageInfo <InlineTrigger> > OrderAndDistinct(List <WeightedInheritanceResultItemWithStorageInfo <InlineTrigger> > source, LocalCodeExecutionContext localCodeExecutionContext, ResolverOptions options)
        {
            var inheritanceOrderOptions = options.Clone();

            var result = OrderAndDistinctByInheritance(source, inheritanceOrderOptions);

            result = result.OrderBy(p => p.Distance).ToList();

            return(result);
        }