/// <inheritdoc/> protected override ulong CalculateLongHashCode() { if (SystemValue.HasValue) { if (SystemValue >= 0 && SystemValue <= 1) { _isFuzzy = true; } } else { _isFuzzy = true; } _builtInSuperTypes = new List <StrongIdentifierValue>() { NameHelper.CreateName(StandardNamesConstants.NumberTypeName) }; if (_isFuzzy) { _builtInSuperTypes.Add(NameHelper.CreateName(StandardNamesConstants.FuzzyTypeName)); } return(base.CalculateLongHashCode() ^ (ulong)Math.Abs(SystemValue?.GetHashCode() ?? 0)); }
private void ProcessConceptLeaf() { _lastIsOperator = null; var value = NameHelper.CreateName(_currToken.Content); var kindOfName = value.KindOfName; switch (kindOfName) { case KindOfName.Concept: case KindOfName.Channel: case KindOfName.Entity: { var node = new ConstValueAstExpression(); node.Value = value; var intermediateNode = new IntermediateAstNode(node); AstNodesLinker.SetNode(intermediateNode, _nodePoint); _state = State.GotName; } break; default: throw new ArgumentOutOfRangeException(nameof(kindOfName), kindOfName, null); } }
public void Run() { _logger.Info("Begin"); var context = TstEngineContextHelper.CreateAndInitContext().EngineContext; var defaultSettings = new DefaultSettingsOfCodeEntity(); defaultSettings.Holder = NameHelper.CreateName("Tor"); _logger.Info($"defaultSettings = {defaultSettings}"); var applicationInheritanceItem = new InheritanceItem() { IsSystemDefined = true }; applicationInheritanceItem.SubName = NameHelper.CreateName("PeaseKeeper"); applicationInheritanceItem.SuperName = context.CommonNamesStorage.AppName; applicationInheritanceItem.Rank = new LogicalValue(1.0F); _logger.Info($"applicationInheritanceItem (1) = {applicationInheritanceItem}"); DefaultSettingsOfCodeEntityHelper.SetUpInheritanceItem(applicationInheritanceItem, defaultSettings); _logger.Info($"applicationInheritanceItem (2) = {applicationInheritanceItem}"); _logger.Info("End"); }
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"); }
private void CheckCodeEntity(CodeEntity codeEntity, string name) { Assert.AreEqual(codeEntity.Kind, KindOfCodeEntity.LinguisticVariable); Assert.AreEqual(codeEntity.Name, NameHelper.CreateName(name)); Assert.AreNotEqual(codeEntity.LinguisticVariable, null); Assert.AreEqual(codeEntity.InheritanceItems.Count, 0); }
public void AddAContactElementToStoredPatient() { var contact = new Patient.ContactComponent { Name = NameHelper.CreateName(HumanName.NameUse.Anonymous, "TestGiven", "TestFamily") }; _fhirResourceRepository.Patient.Contact.Add(contact); }
protected StrongIdentifierValue ParseName(string text) { #if DEBUG //Log($"text = {text}"); #endif var name = NameHelper.CreateName(text); return(name); }
public void Case13() { var text = @"linvar age for range (0, 150] { constraints: for inh; terms: `teenager` = Trapezoid(10, 12, 17, 20); }"; var codeEntity = Parse(text); CheckCodeEntity(codeEntity, "age"); var lingiusticVariable = codeEntity.LinguisticVariable; lingiusticVariable.CheckDirty(); Assert.AreEqual(lingiusticVariable.Name, NameHelper.CreateName("age")); CheckRange(lingiusticVariable.Range, false, 0, 150, true); Assert.AreEqual(lingiusticVariable.Constraint.IsEmpty, false); var constraintItems = lingiusticVariable.Constraint.Items.ToList(); Assert.AreEqual(constraintItems.Count, 2); var item1 = constraintItems[0]; Assert.AreEqual(item1.Kind, KindOfLinguisticVariableConstraintItem.Inheritance); Assert.AreEqual(item1.RelationName, null); var item2 = constraintItems[1]; Assert.AreEqual(item2.Kind, KindOfLinguisticVariableConstraintItem.Relation); Assert.AreEqual(item2.RelationName, NameHelper.CreateName("is")); var term = lingiusticVariable.Values.Single(); Assert.AreEqual(term.Name, NameHelper.CreateName("teenager")); Assert.AreEqual(term.Parent, lingiusticVariable); var handler = term.Handler; Assert.AreNotEqual(handler, null); Assert.AreEqual(handler.Kind, KindOfFuzzyLogicMemberFunction.Trapezoid); var handlerStr = handler.ToString(); Assert.AreEqual(handlerStr.Contains("_a = 10"), true); Assert.AreEqual(handlerStr.Contains("_b = 12"), true); Assert.AreEqual(handlerStr.Contains("_c = 17"), true); Assert.AreEqual(handlerStr.Contains("_d = 20"), true); }
public void NameHelper_Tests_Case_2_Concept() { var name = NameHelper.CreateName("Dog"); Assert.AreEqual(name.IsEmpty, false); Assert.AreEqual(name.NameValue, "dog"); Assert.AreEqual(name.NormalizedNameValue, "dog"); Assert.AreEqual(name.KindOfName, KindOfName.Concept); }
public void NameHelper_Tests_Case_3_Entity() { var text = "#`Barrel 1`"; var name = NameHelper.CreateName(text); Assert.AreEqual(name.IsEmpty, false); Assert.AreEqual(name.NameValue, "#`barrel 1`"); Assert.AreEqual(name.NormalizedNameValue, "#barrel 1"); Assert.AreEqual(name.KindOfName, KindOfName.Entity); }
public void NameHelper_Tests_Case_3_Concept() { var text = "small dog"; var name = NameHelper.CreateName(text); Assert.AreEqual(name.IsEmpty, false); Assert.AreEqual(name.NameValue, text); Assert.AreEqual(name.NormalizedNameValue, text); Assert.AreEqual(name.KindOfName, KindOfName.Concept); }
public void NameHelper_Tests_Case_LogicVar() { var text = "$x"; var name = NameHelper.CreateName(text); Assert.AreEqual(name.IsEmpty, false); Assert.AreEqual(name.NameValue, "$x"); Assert.AreEqual(name.NormalizedNameValue, "$x"); Assert.AreEqual(name.KindOfName, KindOfName.LogicalVar); }
public void NameHelper_Tests_Case_SystemVar() { var text = "@@host"; var name = NameHelper.CreateName(text); Assert.AreEqual(name.IsEmpty, false); Assert.AreEqual(name.NameValue, "@@host"); Assert.AreEqual(name.NormalizedNameValue, "@@host"); Assert.AreEqual(name.KindOfName, KindOfName.SystemVar); }
public void NameHelper_Tests_Case_Channel() { var text = "@>log"; var name = NameHelper.CreateName(text); Assert.AreEqual(name.IsEmpty, false); Assert.AreEqual(name.NameValue, text); Assert.AreEqual(name.NormalizedNameValue, text); Assert.AreEqual(name.KindOfName, KindOfName.Channel); }
private static void TstNameHelper() { _logger.Log("Begin"); var text = "$x"; var name = NameHelper.CreateName(text); _logger.Log($"name = {name}"); _logger.Log("End"); }
private void RegFuzzyLogicOperators() { var globalStorage = _context.Storage.GlobalStorage; var globalFuzzyLogicStorage = globalStorage.FuzzyLogicStorage; var very = new FuzzyLogicOperator(); very.Name = NameHelper.CreateName("very"); very.Handler = new VeryFuzzyLogicOperatorHandler(); globalFuzzyLogicStorage.AppendDefaultOperator(very); }
public void NameHelper_Tests_Case_2_Empty() { var name = NameHelper.CreateName(string.Empty); Assert.AreEqual(name.IsEmpty, true); Assert.AreEqual(name.NameValue, string.Empty); Assert.AreEqual(name.NormalizedNameValue, string.Empty); Assert.AreEqual(name.KindOfName, KindOfName.Unknown); Assert.AreEqual(name.KindOfValue, KindOfValue.StrongIdentifierValue); Assert.AreEqual(name.IsStrongIdentifierValue, true); Assert.AreEqual(name.AsStrongIdentifierValue, name); }
public void Check() { if (_items.Any(p => p.Kind == KindOfLinguisticVariableConstraintItem.Unknown)) { throw new Exception("Linguistic variable constraints can not be Unknown!"); } if (_items.Any(p => p.Kind == KindOfLinguisticVariableConstraintItem.Inheritance)) { if (_items.Count(p => p.Kind == KindOfLinguisticVariableConstraintItem.Inheritance) > 1) { throw new Exception("Linguistic variable's constraints for inheritance is duplicated!"); } if (!_items.Any(p => p.Kind == KindOfLinguisticVariableConstraintItem.Relation && p.RelationName.NameValue == "is")) { var relationItem = new LinguisticVariableConstraintItem() { Kind = KindOfLinguisticVariableConstraintItem.Relation }; relationItem.RelationName = NameHelper.CreateName("is"); _items.Add(relationItem); } } if (_items.Any(p => p.Kind == KindOfLinguisticVariableConstraintItem.Relation)) { var groppedItems = _items.Where(p => p.Kind == KindOfLinguisticVariableConstraintItem.Relation).GroupBy(p => p.RelationName).Where(p => p.Count() > 1).Select(p => $"`{p.Key.NameValue}`"); if (groppedItems.Any()) { if (groppedItems.Count() == 1) { throw new Exception($"Linguistic variable's constraint for relation {groppedItems.First()} is duplicated!"); } else { throw new Exception($"Linguistic variable's constraints for relation {string.Join(", ", groppedItems)} are duplicated!"); } } if (_items.Any(p => p.Kind == KindOfLinguisticVariableConstraintItem.Relation && p.RelationName.NameValue == "is") && !_items.Any(p => p.Kind == KindOfLinguisticVariableConstraintItem.Inheritance)) { var inheritanceItem = new LinguisticVariableConstraintItem() { Kind = KindOfLinguisticVariableConstraintItem.Inheritance }; _items.Add(inheritanceItem); } } }
public void Run() { _logger.Log("Begin"); var context = TstEngineContextHelper.CreateAndInitContext().EngineContext; //var dictionary = context.Dictionary; var inheritanceStorage = context.Storage.GlobalStorage.InheritanceStorage; var subName = NameHelper.CreateName("SubClass"); var superName = NameHelper.CreateName("SuperClass"); var inheritanceItem = new InheritanceItem(); inheritanceItem.SubName = subName; inheritanceItem.SuperName = superName; inheritanceItem.Rank = new LogicalValue(1); _logger.Log($"inheritanceItem = {inheritanceItem}"); inheritanceStorage.SetInheritance(inheritanceItem); inheritanceItem = new InheritanceItem(); inheritanceItem.SubName = subName; inheritanceItem.SuperName = superName; inheritanceItem.Rank = new LogicalValue(0.5F); _logger.Log($"inheritanceItem = {inheritanceItem}"); inheritanceStorage.SetInheritance(inheritanceItem); inheritanceItem = new InheritanceItem(); inheritanceItem.SubName = subName; inheritanceItem.SuperName = superName; inheritanceItem.Rank = new LogicalValue(0); _logger.Log($"inheritanceItem = {inheritanceItem}"); inheritanceStorage.SetInheritance(inheritanceItem); var list = inheritanceStorage.GetItemsDirectly(subName); _logger.Log($"list.Count = {list.Count}"); _logger.Log($"inheritanceItem = {list.WriteListToString()}"); _logger.Log("End"); }
private void ProcessVar() { _lastIsOperator = null; var value = NameHelper.CreateName(_currToken.Content); var node = new VarAstExpression(); node.Name = value; var intermediateNode = new IntermediateAstNode(node); AstNodesLinker.SetNode(intermediateNode, _nodePoint); _state = State.GotName; }
public void LoadFromSourceCode() { WorldName = NameHelper.CreateName(StandardNamesConstants.WorldTypeName); AppName = NameHelper.CreateName(StandardNamesConstants.AppTypeName); ClassName = NameHelper.CreateName(StandardNamesConstants.ClassTypeName); DefaultHolder = new StrongIdentifierValue(); SelfSystemVarName = NameHelper.CreateName(StandardNamesConstants.SelfSystemVarName); HostSystemVarName = NameHelper.CreateName(StandardNamesConstants.HostSystemVarName); SelfName = NameHelper.CreateName(_context.Id); }
private void RegChannels() { var globalStorage = _context.Storage.GlobalStorage; var globalChannelsStorage = globalStorage.ChannelsStorage; var name = NameHelper.CreateName("@>log"); var channel = new Channel { Name = name, Handler = new LogChannelHandler(_context), Holder = _context.CommonNamesStorage.DefaultHolder }; globalChannelsStorage.Append(channel); }
private void ProcessChannel() { _lastIsOperator = null; var name = NameHelper.CreateName(_currToken.Content); #if DEBUG //Log($"name = {name}"); #endif var node = new ConstValueAstExpression(); node.Value = name; var intermediateNode = new IntermediateAstNode(node); AstNodesLinker.SetNode(intermediateNode, _nodePoint); }
private static LogicalQueryNode ConvertUnaryPredicateToFullIsPredicate(LogicalQueryNode source, Dictionary <object, object> convertingContext) { #if DEBUG //_gbcLogger.Info($"source = {source}"); //_gbcLogger.Info($"source.GetHumanizeDbgString() = {source.GetHumanizeDbgString()}"); #endif if (source == null) { return(null); } if (convertingContext.ContainsKey(source)) { return((LogicalQueryNode)convertingContext[source]); } var result = new LogicalQueryNode(); convertingContext[source] = result; result.Kind = KindOfLogicalQueryNode.Relation; result.Name = NameHelper.CreateName("is"); result.ParamsList = new List <LogicalQueryNode>(); result.ParamsList.Add(source.ParamsList[0]); var superNameNode = new LogicalQueryNode(); superNameNode.Kind = KindOfLogicalQueryNode.Concept; superNameNode.Name = source.Name; result.ParamsList.Add(superNameNode); var rankNode = new LogicalQueryNode(); result.ParamsList.Add(rankNode); rankNode.Kind = KindOfLogicalQueryNode.Value; rankNode.Value = new LogicalValue(1); #if DEBUG //_gbcLogger.Info($"result = {result}"); //_gbcLogger.Info($"result.GetHumanizeDbgString() = {result.GetHumanizeDbgString()}"); #endif return(result); }
private RuleInstance CreateInheritanceFact(InheritanceItem inheritanceItem) { var factName = NameHelper.CreateRuleOrFactName(); #if DEBUG //Log($"factName = {factName}"); #endif var fact = new RuleInstance(); fact.Kind = KindOfRuleInstance.Fact; fact.AppendAnnotations(inheritanceItem); fact.Name = factName; //fact.KeysOfPrimaryRecords.Add(inheritanceItem.Id); var primaryPart = new PrimaryRulePart(); fact.PrimaryPart = primaryPart; primaryPart.Parent = fact; var isRelation = new LogicalQueryNode(); isRelation.Name = NameHelper.CreateName("is"); isRelation.Kind = KindOfLogicalQueryNode.Relation; isRelation.ParamsList = new List <LogicalQueryNode>(); primaryPart.Expression = isRelation; var subItemNode = new LogicalQueryNode(); isRelation.ParamsList.Add(subItemNode); subItemNode.Kind = KindOfLogicalQueryNode.Concept; subItemNode.Name = inheritanceItem.SubName; var superItemNode = new LogicalQueryNode(); isRelation.ParamsList.Add(superItemNode); superItemNode.Kind = KindOfLogicalQueryNode.Concept; superItemNode.Name = inheritanceItem.SuperName; var rankNode = new LogicalQueryNode(); isRelation.ParamsList.Add(rankNode); rankNode.Kind = KindOfLogicalQueryNode.Value; rankNode.Value = inheritanceItem.Rank; return(fact); }
public void Case1_a() { var text = @"linvar age for range [0, 150) { terms: `teenager` = Trapezoid(10, 12, 17, 20); }"; var codeEntity = Parse(text); CheckCodeEntity(codeEntity, "age"); var lingiusticVariable = codeEntity.LinguisticVariable; lingiusticVariable.CheckDirty(); Assert.AreEqual(lingiusticVariable.Name, NameHelper.CreateName("age")); CheckRange(lingiusticVariable.Range, true, 0, 150, false); Assert.AreEqual(lingiusticVariable.Constraint.IsEmpty, true); var term = lingiusticVariable.Values.Single(); Assert.AreEqual(term.Name, NameHelper.CreateName("teenager")); Assert.AreEqual(term.Parent, lingiusticVariable); var handler = term.Handler; Assert.AreNotEqual(handler, null); Assert.AreEqual(handler.Kind, KindOfFuzzyLogicMemberFunction.Trapezoid); var handlerStr = handler.ToString(); Assert.AreEqual(handlerStr.Contains("_a = 10"), true); Assert.AreEqual(handlerStr.Contains("_b = 12"), true); Assert.AreEqual(handlerStr.Contains("_c = 17"), true); Assert.AreEqual(handlerStr.Contains("_d = 20"), true); }
private Dictionary <StrongIdentifierValue, Value> NormalizeNamedParameters(Dictionary <StrongIdentifierValue, Value> source) { var result = new Dictionary <StrongIdentifierValue, Value>(); foreach (var namedParameter in source) { var parameterName = namedParameter.Key; #if DEBUG //Log($"parameterName = {parameterName}"); #endif var kindOfParameterName = parameterName.KindOfName; switch (kindOfParameterName) { case KindOfName.Var: break; case KindOfName.Concept: parameterName = NameHelper.CreateName($"@{parameterName.NameValue}"); break; default: throw new ArgumentOutOfRangeException(nameof(kindOfParameterName), kindOfParameterName, null); } #if DEBUG //Log($"parameterName (after) = {parameterName}"); #endif result[parameterName] = namedParameter.Value; } return(result); }
public void AddANameElementToStoredPatient() { _fhirResourceRepository.Patient.Name.Add(NameHelper.CreateName(HumanName.NameUse.Nickname, "AdditionalGiven", "AdditionalFamily")); }
private static void TstCreateName() { _logger.Log("Begin"); var parserContext = new TstMainStorageContext(); var nameVal1 = "dog"; _logger.Log($"{nameof(nameVal1)} = {nameVal1}"); //var result = ParseName(nameVal1); //_logger.Info($"result = {JsonConvert.SerializeObject(result, Formatting.Indented)}"); //var nameVal2 = "dog (animal)"; //_logger.Info($"{nameof(nameVal2)} = {nameVal2}"); //result = ParseName(nameVal2); //_logger.Info($"result = {JsonConvert.SerializeObject(result, Formatting.Indented)}"); //var nameVal3 = "dog (animal | instrument)"; //_logger.Info($"{nameof(nameVal3)} = {nameVal3}"); //result = ParseName(nameVal3); //_logger.Info($"result = {JsonConvert.SerializeObject(result, Formatting.Indented)}"); //var nameVal4 = "dog (animal (alive))"; //_logger.Info($"{nameof(nameVal4)} = {nameVal4}"); //result = ParseName(nameVal4); //_logger.Info($"result = {JsonConvert.SerializeObject(result, Formatting.Indented)}"); //var nameVal5 = "dog (alive::animal)"; //_logger.Info($"{nameof(nameVal5)} = {nameVal5}"); //result = ParseName(nameVal5); //_logger.Info($"result = {JsonConvert.SerializeObject(result, Formatting.Indented)}"); //var nameVal6 = "dog (alive::animal | instrument (big))"; //_logger.Info($"{nameof(nameVal6)} = {nameVal6}"); //result = ParseName(nameVal6); //_logger.Info($"result = {JsonConvert.SerializeObject(result, Formatting.Indented)}"); //var nameVal7 = "animal::dog"; //result = ParseName(nameVal7); //_logger.Info($"result = {JsonConvert.SerializeObject(result, Formatting.Indented)}"); //var nameVal8 = "(animal | instrument)::dog"; //result = ParseName(nameVal8); //_logger.Info($"result = {JsonConvert.SerializeObject(result, Formatting.Indented)}"); var name = NameHelper.CreateName(nameVal1); _logger.Log($"name = {name}"); _logger.Log("End"); }
public void Run() { _logger.Log("Begin"); var complexContext = TstEngineContextHelper.CreateAndInitContext(); var context = complexContext.EngineContext; var worldContext = complexContext.WorldContext; //var dictionary = context.Dictionary; var platformListener = new TstPlatformHostListener(); var npcSettings = new HumanoidNPCSettings(); npcSettings.Id = "#020ED339-6313-459A-900D-92F809CEBDC5"; //npcSettings.HostFile = Path.Combine(Directory.GetCurrentDirectory(), @"Source\Hosts\PeaceKeeper\PeaceKeeper.host"); npcSettings.LogicFile = Path.Combine(Directory.GetCurrentDirectory(), @"Source\Apps\PeaceKeeper\PeaceKeeper.sobj"); npcSettings.HostListener = platformListener; npcSettings.PlatformSupport = new PlatformSupportCLIStub(); _logger.Log($"npcSettings = {npcSettings}"); var tstBaseManualControllingGameComponent = new TstBaseManualControllingGameComponent(npcSettings, worldContext); var methodName = NameHelper.CreateName("go"); var command = new Command(); command.Name = methodName; command.ParamsDict = new Dictionary <StrongIdentifierValue, Value>(); var param1Value = new WaypointValue(25, 36, context); var param1Name = NameHelper.CreateName("to"); command.ParamsDict[param1Name] = param1Value; var param2Value = new NumberValue(12.4); var param2Name = NameHelper.CreateName("speed"); command.ParamsDict[param2Name] = param2Value; _logger.Log($"command = {command}"); //ExecuteCommand(tstBaseManualControllingGameComponent, command); methodName = NameHelper.CreateName("shoot"); command = new Command(); command.Name = methodName; ExecuteCommand(tstBaseManualControllingGameComponent, command); var gameObjectSettings = new GameObjectSettings(); gameObjectSettings.Id = "#120ED339-6313-459A-900D-92F809CEBDC5"; var gunPlatformHostListener = new TstGunPlatformHostListener(); gameObjectSettings.HostListener = gunPlatformHostListener; _logger.Log($"gameObjectSettings = {gameObjectSettings}"); var gameObject = new GameObjectImplementation(gameObjectSettings, worldContext); tstBaseManualControllingGameComponent.AddToManualControl(gameObject, 12); methodName = NameHelper.CreateName("shoot"); command = new Command(); command.Name = methodName; ExecuteCommand(tstBaseManualControllingGameComponent, command); var manualControlledObjectsList = tstBaseManualControllingGameComponent.GetManualControlledObjects(); //_logger.Log($"manualControlledObjectsList = {manualControlledObjectsList.WriteListToString()}"); _logger.Log($"manualControlledObjectsList.Count = {manualControlledObjectsList.Count}"); tstBaseManualControllingGameComponent.RemoveFromManualControl(gameObject); manualControlledObjectsList = tstBaseManualControllingGameComponent.GetManualControlledObjects(); _logger.Log($"manualControlledObjectsList.Count = {manualControlledObjectsList.Count}"); _logger.Log("End"); }