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(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); }
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); } }
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)); }
public NumberValue Resolve(FuzzyLogicNonNumericSequenceValue fuzzyLogicNonNumericSequence, ReasonOfFuzzyLogicResolving reason, LocalCodeExecutionContext localCodeExecutionContext) { return(Resolve(fuzzyLogicNonNumericSequence, reason, localCodeExecutionContext, _defaultOptions)); }
public NumberValue Resolve(StrongIdentifierValue name, ReasonOfFuzzyLogicResolving reason, LocalCodeExecutionContext localCodeExecutionContext) { return(Resolve(name, reason, localCodeExecutionContext, _defaultOptions)); }
private FuzzyLogicNonNumericValue GetTargetFuzzyLogicNonNumericValueFromList(List <WeightedInheritanceResultItemWithStorageInfo <FuzzyLogicNonNumericValue> > list, ReasonOfFuzzyLogicResolving reason) { if (!list.Any()) { return(null); } if (list.Count == 1) { return(list.FirstOrDefault()?.ResultItem); } if (list.Any(p => p.ResultItem.Parent.IsFitByСonstraint(reason)) && list.Any(p => p.ResultItem.Parent.IsConstraintNullOrEmpty)) { list = list.Where(p => p.ResultItem.Parent.IsFitByСonstraint(reason)).ToList(); if (!list.Any()) { return(null); } if (list.Count == 1) { return(list.FirstOrDefault()?.ResultItem); } } var minLengthOfRange = list.Min(p => p.ResultItem.Parent.Range.Length); #if DEBUG //Log($"minLengthOfRange = {minLengthOfRange}"); #endif var targetItem = list.FirstOrDefault(p => p.ResultItem.Parent.Range.Length == minLengthOfRange)?.ResultItem; return(targetItem); }
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 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)); }
public bool Equals(StrongIdentifierValue name, NumberValue value, ReasonOfFuzzyLogicResolving reason, LocalCodeExecutionContext localCodeExecutionContext) { return(Equals(name, value, reason, localCodeExecutionContext, _defaultOptions)); }