public async Task <IPurposeFullfillment> WorkAsync(IContext context, IKalos message) { var purposeFullfillment = new PurposeFullfillment(); if (!context.AddressedToSelf) { purposeFullfillment.Weight = -1; return(purposeFullfillment); } var matchedWords = new List <IKeyword>(); await Task.Run(() => { foreach (var keyword in OvermindAccessor.GetAllKeywords()) { if (message.Msg.Contains(keyword.Word)) { var previousMatch = matchedWords.FirstOrDefault(); if (previousMatch == null) { matchedWords.Add(keyword); } else if (previousMatch.Word.Length < keyword.Word.Length) { matchedWords.Remove(previousMatch); matchedWords.Add(keyword); } } } }); if (matchedWords.Count == 0) { purposeFullfillment.Weight = -1; return(purposeFullfillment); } if (!LastTimeKeywordUsed.ContainsKey(matchedWords[0].Word)) { LastTimeKeywordUsed.Add(matchedWords[0].Word, DateTime.Now); } else { if (LastTimeKeywordUsed[matchedWords[0].Word] > DateTime.Now.AddMinutes(-1)) { purposeFullfillment.Weight = -1; return(purposeFullfillment); } LastTimeKeywordUsed[matchedWords[0].Word] = DateTime.Now; } purposeFullfillment.Weight = 100; var responses = matchedWords[0].Response.Split('\n'); foreach (var response in responses) { var outMessage = MessageCreator.CreateOutgoingMessage(message.Origin, HumanInterface.Name, response); purposeFullfillment.AddMessage(outMessage); } return(purposeFullfillment); }
private static IPurposeFullfillment CreateDefaultResponse() { var purposeFullfillment = new PurposeFullfillment { Weight = 0 }; return(purposeFullfillment); }
public async Task <IPurposeFullfillment> WorkAsync(IContext context, IKalos message) { var purposeFullfillment = new PurposeFullfillment(); var messageLower = message.Msg.ToLowerInvariant(); var obj = ExtractObject(messageLower); if (string.IsNullOrEmpty(obj)) { var subject = ExtractIndependentSubject(messageLower); if (string.IsNullOrEmpty(subject) || subject.Length < 2) { purposeFullfillment.Weight = -1; return(purposeFullfillment); } IList <IWhatIs> results = null; await Task.Run(() => { results = OvermindAccessor.GetMatchingWhatIsAnswers(subject, string.Empty, "definition"); }); if (results.Count == 0) { purposeFullfillment.Weight = -1; return(purposeFullfillment); } var response = CreateResponse(message, results); purposeFullfillment.AddMessage(response); purposeFullfillment.Weight = 1000001; return(purposeFullfillment); } else { var subject = ExtractDependentSubject(messageLower); if (string.IsNullOrEmpty(subject)) { purposeFullfillment.Weight = -1; return(purposeFullfillment); } IList <IWhatIs> results = null; await Task.Run(() => { results = OvermindAccessor.GetMatchingWhatIsAnswers(subject, obj, "attribute"); }); if (results.Count == 0) { purposeFullfillment.Weight = -1; return(purposeFullfillment); } var response = CreateResponse(message, results); purposeFullfillment.AddMessage(response); purposeFullfillment.Weight = 1000001; return(purposeFullfillment); } }
public async Task <IPurposeFullfillment> WorkAsync(IContext context, IKalos message) { var purposeFullfillment = new PurposeFullfillment(); if (!context.AddressedToSelf) { purposeFullfillment.Weight = -1; return(purposeFullfillment); } var outgoingMessage = MessageCreator.CreateOutgoingMessage(message.Origin, HumanInterface.Name, Response); purposeFullfillment.AddMessage(outgoingMessage); purposeFullfillment.Weight = 1; return(purposeFullfillment); }