public override IKnowledgeSourceActivation[] Precondition() { // Use LINQ to create a collection of the requested U_PrologEvalQueries on the blackboard. var requests = from request in m_blackboard.LookupUnits <U_PrologEvalRequest>() // Lookup ID select requests where // where the request has not been previously matched by this knowledge source precondition (!request.Slots.ContainsKey(KSPreconditionMatched)) || (!((ISet <ReactiveKnowledgeSource>)request.Slots[KSPreconditionMatched]).Contains(this)) select request; IKnowledgeSourceActivation[] activations = new IKnowledgeSourceActivation[requests.Count()]; // Currently only support one prolog KB // fixme: eventually may want to support multiple prolog KBs so will need mechanism for supporting them as well as inheritance var prologKB = m_blackboard.LookupSingleton <U_PrologKB>(); // Lookup prolog kbs. // Iterate through each of the requests, creating KnowledgeSourceActivations int i = 0; foreach (var request in requests) { var boundVars = new Dictionary <string, object> { [PrologEvalRequest] = request, [PrologKB] = prologKB }; activations[i++] = new KnowledgeSourceActivation(this, boundVars); // fixme: this bit of boilerplate code for marking a knowledge unit as having already participated in a matched precondition // should be baked into the infrastructure somewhere so knowledge source implementers don't always have to do this. // A good place to add this would be on Unit (and declare a method on IUnit). if (request.Slots.ContainsKey(KSPreconditionMatched)) { ((HashSet <ReactiveKnowledgeSource>)request.Slots[KSPreconditionMatched]).Add(this); } else { request.Slots[KSPreconditionMatched] = new HashSet <ReactiveKnowledgeSource> { this }; } } return(activations); }
public override IKnowledgeSourceActivation[] Precondition() { // Use LINQ to create a collection of the selected content units on the blackkboard var CUs = from ContentUnit cu in m_blackboard.LookupUnits <ContentUnit>() where cu.HasMetadataSlot(SelectedContentUnit) // look for a selected content unit where // that has not been previously matched by this precondition (!cu.Slots.ContainsKey(KSPreconditionMatched)) || (!((ISet <ReactiveKnowledgeSource>)cu.Slots[KSPreconditionMatched]).Contains(this)) select cu; // Iterate through each of the selected content units, creating KnowledgeSourceActivations IKnowledgeSourceActivation[] activations = new KnowledgeSourceActivation[CUs.Count()]; int i = 0; foreach (var cu in CUs) { var boundVars = new Dictionary <string, object> { [SelectedContentUnit] = cu }; activations[i++] = new KnowledgeSourceActivation(this, boundVars); // fixme: this bit of boilerplate code for marking a knowledge unit as having already participated in a matched precondition // should be baked into the infrastructure somewhere so knowledge source implementers don't always have to do this. // A good place to add this would be on Unit (and declare a method on IUnit). if (cu.Slots.ContainsKey(KSPreconditionMatched)) { ((HashSet <ReactiveKnowledgeSource>)cu.Slots[KSPreconditionMatched]).Add(this); } else { cu.Slots[KSPreconditionMatched] = new HashSet <ReactiveKnowledgeSource> { this }; } } return(activations); }
public override IKnowledgeSourceActivation[] Precondition() { // Use LINQ to create a collection of the requested U_IDQueries on the blackboard. var requests = from request in m_blackboard.LookupUnits <U_IDSelectRequest>() // Lookup ID queries where // where the query has not been previously matched by this knowledge source precondition (!request.Slots.ContainsKey(KSPreconditionMatched)) || (!((ISet <ReactiveKnowledgeSource>)request.Slots[KSPreconditionMatched]).Contains(this)) select request; IKnowledgeSourceActivation[] activations = new IKnowledgeSourceActivation[requests.Count()]; // Iterate through each of the queries, creating KnowledgeSourceActivations int i = 0; foreach (var request in requests) { var boundVars = new Dictionary <string, object> { [IDSelectRequest] = request }; activations[i++] = new KnowledgeSourceActivation(this, boundVars); // fixme: this bit of boilerplate code for marking a knowledge unit as having already participated in a matched precondition // should be baked into the infrastructure somewhere so knowledge source implementers don't always have to do this. // A good place to add this would be on Unit (and declare a method on IUnit). if (request.Slots.ContainsKey(KSPreconditionMatched)) { ((HashSet <ReactiveKnowledgeSource>)request.Slots[KSPreconditionMatched]).Add(this); } else { request.Slots[KSPreconditionMatched] = new HashSet <ReactiveKnowledgeSource> { this }; } } return(activations); }