public Dictionary<string, double> Classify(IEnumerable<string> phrases)
{
var scores = _categories.ToDictionary(kvp => kvp.Key, kvp => 0.0);
var words = new Category(phrases);
foreach (KeyValuePair<string, int> word in words)
{
foreach (KeyValuePair<string, Category> pair in _categories)
{
Category cat = pair.Value;
double count = cat[word.Key];
if (count > 0)
scores[pair.Key] += Math.Log(count/cat.PhraseCount());
else
scores[pair.Key] += Math.Log(0.01/cat.PhraseCount());
}
}
foreach (KeyValuePair<string, Category> pair in _categories)
{
Category cat = pair.Value;
if (scores[pair.Key] > 0)
scores[pair.Key] += Math.Log((double)cat.PhraseCount()/TotalCount());
}
double totalScores = scores.Sum(kvp => kvp.Value);
return scores.ToDictionary(score => score.Key, score => score.Value/totalScores);
}
}