public decimal GetRatingForSentence(string channel, string sentence) { var rating = 0m; var tokenSentence = new TokenList(sentence); var nextToken = tokenSentence.GetEnumerator(); var hasNextToken = nextToken.MoveNext(); var usedStems = new List <Stem>(); while (hasNextToken) { var stem = StemManager.GetStemForToken(nextToken.Current); if (stem != null && ChannelMemoryManager.Instance.HasStemInChannel(channel, stem) && !usedStems.Contains(stem)) { rating += ChannelMemoryManager.Instance.GetValueForStem(channel, stem); usedStems.Add(stem); } hasNextToken = nextToken.MoveNext(); } if (tokenSentence.Get().Count == 0) { return(rating); } var power = Math.Pow(tokenSentence.Get().Count, 0.5); var multiplier = (decimal)(1 / power); rating = rating * multiplier; return(rating); }
internal void UpdateMessage(string message) { var majorWords = new TokenList(message).GetMajorWords().Distinct(); foreach (var word in majorWords) { var stem = StemManager.GetStemForToken(word); if (stem == null) { continue; } UpdateMemoryForStem(stem); } DecayMemory(0.0125m); }
public void Test_AddToken_MultipleTimes() { var testToken2 = new Token { ID = Guid.NewGuid(), WordText = "Texts" }; TokenManager.SetTokenForID(testToken2.ID, testToken2); StemManager.AddToken(testToken); StemManager.AddToken(testToken); StemManager.AddToken(testToken2); var tokenList = StemManager.GetTokensForUnstemmedWord(testToken.WordText); Assert.AreEqual(2, tokenList.Count); Assert.AreEqual(new List <Token> { testToken, testToken2 }, tokenList); Assert.AreEqual("text", StemManager.GetStemForToken(testToken.WordText)); Assert.AreEqual("text", StemManager.GetStemForToken(testToken2.WordText)); }