public void addActionTemplate(Name a, int p) { if (!actions.ContainsKey(a)) { actions.Add(a, new List <Effect>()); actionNames.Add(new KeyValuePair <Name, Name>(a, a)); priorityRules.Add(a, p); } }
public void Add_FilledNameSearchTree_False(string name, string value) { var tree = new NameSearchTree<string>(); Assert.Throws<DuplicatedKeyException>(() => { tree.Add(Name.BuildName(name), value); tree.Add(Name.BuildName(name), String.Empty); }); }
public void Add_FilledNameSearchTree_False(string name, string value) { var tree = new NameSearchTree <string>(); Assert.Throws <Exception>(() => { tree.Add(Name.BuildName(name), value); tree.Add(Name.BuildName(name), String.Empty); }); }
public void Add_FilledNameSearchTree_False(string name, string value) { for (int i = 0; i < rep; i++) { var tree = new NameSearchTree <string>(); Assert.Throws <DuplicatedKeyException>(() => { tree.Add(Name.BuildName(name), value); tree.Add(Name.BuildName(name), String.Empty); }); } }
public void Special_Test_For_Bug_22_11_2017() { for (int i = 0; i < rep; i++) { var tree = new NameSearchTree <byte>(); var n1 = (Name)"Speak(-,end,Meanings(a(b),c(d)),t)"; var n2 = (Name)"Speak(-,end,Meanings(a(c),e),t)"; var test1 = (Name)"Speak(-,end,*,t)"; tree.Add(n1, 0); tree.Add(n2, 0); Assert.IsTrue(tree.Unify(test1).All(r => r.Item1 == 0)); } }
public void SetObjectData(ISerializationData dataHolder, ISerializationContext context) { actions = new Dictionary <Name, List <Effect> >(); priorityRules = new Dictionary <Name, int>(); var actionsJson = dataHolder.GetValue <Dictionary <Name, List <Effect> > >("Effects"); foreach (var k in actionsJson.Keys) { if (actionsJson[k] != null) { actions.Add(k, actionsJson[k]); } } priorityRules = dataHolder.GetValue <Dictionary <Name, int> >("Priorities"); actionNames = new NameSearchTree <Name>(); foreach (var k in actions.Keys) { actionNames.Add(new KeyValuePair <Name, Name>(k, k)); } }
public void SetPerspective(Name newPerspective) { if(!newPerspective.IsPrimitive) throw new ArgumentException("Only primitive symbols are allowed to be perspectives."); if(newPerspective == Name.NIL_SYMBOL) throw new ArgumentException("NIL symbol cannot be used as a perspective."); if (newPerspective == Name.SELF_SYMBOL) throw new ArgumentException("SELF symbol cannot be set as a default a perspectives."); if (newPerspective==Perspective) return; if(GetAllPerspectives().Contains(newPerspective)) throw new ArgumentException($"The is already beliefs containing perspectives for {newPerspective}. Changing to the requested perspective would result in belief conflicts."); //Modify believes to reflect perspective changes var newStorage = new NameSearchTree<KnowledgeEntry>(); foreach (var entry in m_knowledgeStorage) { var newProperty = entry.Key.SwapTerms(Perspective, newPerspective); newStorage.Add(newProperty,entry.Value); } m_knowledgeStorage.Clear(); m_knowledgeStorage = newStorage; Perspective = newPerspective; }
public void Contains_NameSearchTreeThatContainsName_True(string name, string value) { var tree = new NameSearchTree <string>(); tree.Add(Name.BuildName(name), value); Assert.That(tree.ContainsKey(Name.BuildName(name))); }
private void internal_RegistDynamicProperty(Name propertyName, MethodInfo surogate, DynamicPropertyCalculator converted) { if (!propertyName.IsPrimitive) { throw new ArgumentException("The property name must be a primitive symbol.", nameof(propertyName)); } var p = surogate.GetParameters(); var propertyParameters = p.Skip(1).Select(p2 => Name.BuildName("[" + p2.Name + "]")).ToArray(); var template = Name.BuildName(propertyParameters.Prepend(propertyName)); var r = m_dynamicProperties.Unify(template).FirstOrDefault(); if (r != null) { var t = r.Item1.DeclaringType; if (t == surogate.DeclaringType) { return; } throw new ArgumentException("There is already a registed property with the name " + propertyName + " that receives " + (p.Length - 3) + "parameters."); } if (_willCollideDelegate(template)) { throw new ArgumentException("There are already stored property values that will collide with the given dynamic property."); } m_dynamicProperties.Add(template, new DynamicKnowledgeEntry(converted, propertyParameters, surogate.DeclaringType)); }
public void Add_EmptyNameSearchTree_True(string name, string value) { for (int i = 0; i < rep; i++) { var tree = new NameSearchTree <string>(); tree.Add(Name.BuildName(name), value); } }
private IEnumerable <DynamicPropertyResult> LastEventIdPropertyCalculator(IQueryContext context, Name type, Name subject, Name def, Name target) { ulong min = ulong.MinValue; var allEvents = m_registry.Values; foreach (var eve in allEvents) { if (eve.Timestamp >= min) { min = eve.Timestamp; } } var lastEvents = m_registry.Where(x => x.Value.Timestamp == min); var lastIndexes = new NameSearchTree <List <uint> >(); // Now we get a similar object as m_typeIndexes but only with the last events foreach (var ind in m_typeIndexes) { foreach (var eve in lastEvents) { if (ind.Key.ToString() == eve.Value.EventName.ToString() && !lastIndexes.Contains(ind)) { lastIndexes.Add(ind); } } } // Now that we have the events of the last tick we can now ask the context var key = Name.BuildName((Name)AMConsts.EVENT, type, subject, def, target); foreach (var c in context.Constraints) { var unifiedSet = lastIndexes.Unify(key, c); foreach (var pair in unifiedSet) { foreach (var id in pair.Item1) { yield return(new DynamicPropertyResult(new ComplexValue(Name.BuildName(id)), new SubstitutionSet(pair.Item2))); } } if (!unifiedSet.Any()) { yield return(new DynamicPropertyResult(new ComplexValue(Name.BuildName(-1)), c)); } } }
/// <summary> /// Adds an emotional reaction to an event /// </summary> /// <param name="emotionalAppraisalRule">the AppraisalRule to add</param> public void AddOrUpdateAppraisalRule(AppraisalRuleDTO emotionalAppraisalRuleDTO) { AppraisalRule existingRule = null; var existingRulePair = findExistingAppraisalRule(emotionalAppraisalRuleDTO.Id, out existingRule); if (existingRule == null) { this.AddEmotionalReaction(new AppraisalRule(emotionalAppraisalRuleDTO)); } else { existingRule.Desirability = emotionalAppraisalRuleDTO.Desirability; existingRule.Praiseworthiness = emotionalAppraisalRuleDTO.Praiseworthiness; existingRule.EventName = Name.BuildName(emotionalAppraisalRuleDTO.EventMatchingTemplate); Rules.Remove(existingRulePair); Rules.Add(existingRule.EventName, existingRulePair.Value); } }
public void Remove_NameSearchTreeThatContainsName_True(string name, string value) { var tree = new NameSearchTree <string>(); tree.Add(Name.BuildName(name), value); var removeSuccess = tree.Remove(Name.BuildName(name)); Assert.That(removeSuccess); }
private static NameSearchTree <int> BuildInput() { NameSearchTree <int> dict = new NameSearchTree <int>(); for (int i = 0; i < inputStrings.Length; i++) { dict.Add(Name.BuildName(inputStrings[i]), i); } return(dict); }
public void AddEmotionalReaction(AppraisalRule appraisalRule) { var name = appraisalRule.EventName; HashSet <AppraisalRule> ruleSet; if (!Rules.TryGetValue(name, out ruleSet)) { ruleSet = new HashSet <AppraisalRule>(); Rules.Add(name, ruleSet); } ruleSet.Add(appraisalRule); }
public void AddClaim(ClaimDTO claim) { Name n = null; try { n = (Name)claim.ActionTemplate; m_claimTree.Add(n, claim.ClaimSI); } catch (DuplicatedKeyException) { throw new Exception($"There is already a claim associated to the action template \"{n}\""); } }
public void LoadFromDTO(SocialImportanceDTO dto) { m_attributionRules = dto.AttributionRules.Select(adto => new AttributionRule(adto)).ToArray(); m_claimTree.Clear(); if (dto.Claims != null) { foreach (var c in dto.Claims) { var n = Name.BuildName(c.ActionTemplate); m_claimTree.Add(n, c.ClaimSI); } } //TODO load the rest }
public void AddDialog(DialogStateAction action) { if (m_dialogDictionary.ContainsKey(action.Id)) { throw new Exception($"Duplicate Dialog State Action with the same id \"{action.Id}\""); } var key = action.BuildSpeakAction(); HashSet <DialogStateAction> set; if (!m_nameToDialogues.TryGetValue(key, out set)) { set = new HashSet <DialogStateAction>(); m_nameToDialogues.Add(key, set); } set.Add(action); m_dialogDictionary[action.Id] = action; }
public void SetObjectData(ISerializationData dataHolder, ISerializationContext context) { m_attributionRules = new HashSet <AttributionRule>(dataHolder.GetValue <AttributionRule[]>("AttributionRules")); foreach (var rule in m_attributionRules) { rule.GUID = Guid.NewGuid(); } var claims = dataHolder.GetValue <ClaimDTO[]>("Claims"); m_claimTree = new NameSearchTree <uint>(); foreach (var c in claims) { m_claimTree.Add(Name.BuildName(c.ActionTemplate), c.ClaimSI); } m_cachedSI = new NameSearchTree <NameSearchTree <float> >(); }
public void RegistDynamicProperty(Name propertyTemplate, DynamicPropertyCalculator surogate, IEnumerable <string> arguments) { if (surogate == null) { throw new ArgumentNullException(nameof(surogate)); } if (propertyTemplate.IsGrounded) { throw new ArgumentException("Grounded names cannot be used as dynamic properties", nameof(propertyTemplate)); } var r = m_dynamicProperties.Unify(propertyTemplate).FirstOrDefault(); if (r != null) { throw new ArgumentException( $"The given template {propertyTemplate} will collide with already registed {propertyTemplate.MakeGround(r.Item2)} dynamic property", nameof(propertyTemplate)); } if (m_knowledgeStorage.Unify(propertyTemplate).Any()) { throw new ArgumentException($"The given template {propertyTemplate} will collide with stored constant properties", nameof(propertyTemplate)); } Name[] args; if (arguments == null) { args = new Name[0]; } else { args = arguments.Distinct().Select(s => Name.BuildName("[" + s + "]")).ToArray(); } m_dynamicProperties.Add(propertyTemplate, new DynamicKnowledgeEntry(surogate, args)); }
public void Remove_NameSearchTreeThatContainsName_True(string name, string value) { var tree = new NameSearchTree<string>(); tree.Add(Name.BuildName(name), value); var removeSuccess = tree.Remove(Name.BuildName(name)); Assert.That(removeSuccess); }
public void SetPerspective(Name newPerspective) { if(!newPerspective.IsPrimitive) throw new ArgumentException("Only primitive symbols are allowed to be perspectives."); if(newPerspective == Name.NIL_SYMBOL) throw new ArgumentException("NIL symbol cannot be used as a perspective."); if (newPerspective == Name.SELF_SYMBOL) throw new ArgumentException("SELF symbol cannot be set as a default a perspectives."); if (newPerspective==Perspective) return; if(GetAllPerspectives().Contains(newPerspective)) throw new ArgumentException($"The is already beliefs containing perspectives for {newPerspective}. Changing to the requested perspective would result in belief conflicts."); //Modify believes to reflect perspective changes var newStorage = new NameSearchTree<KnowledgeEntry>(); foreach (var entry in m_knowledgeStorage) { var newProperty = entry.Key.SwapTerms(Perspective, newPerspective); newStorage.Add(newProperty,entry.Value); } m_knowledgeStorage.Clear(); m_knowledgeStorage = newStorage; Perspective = newPerspective; }
public void Special_Test_For_Bug_22_11_2017() { var tree = new NameSearchTree<byte>(); var n1 = (Name) "Speak(-,end,Meanings(a(b),c(d)),t)"; var n2 = (Name)"Speak(-,end,Meanings(a(c),e),t)"; var test1 = (Name)"Speak(-,end,*,t)"; tree.Add(n1,0); tree.Add(n2, 0); Assert.IsTrue(tree.Unify(test1).All(r => r.Item1 == 0)); }
public void Add_EmptyNameSearchTree_True(string name, string value) { var tree = new NameSearchTree<string>(); tree.Add(Name.BuildName(name), value); }
private static NameSearchTree<int> BuildInput() { NameSearchTree<int> dict = new NameSearchTree<int>(); for (int i = 0; i < inputStrings.Length; i++) { dict.Add(Name.BuildName(inputStrings[i]), i); } return dict; }
public void Contains_NameSearchTreeThatContainsName_True(string name, string value) { var tree = new NameSearchTree<string>(); tree.Add(Name.BuildName(name), value); Assert.That(tree.ContainsKey(Name.BuildName(name))); }