Example #1
0
        // We use the term frequency of the query and the IDF value we previously calculated.
        private void CalculateQueryTfIdf(string userQuery)
        {
            QueryTfIdfWeight = new Dictionary <string, double>();
            var queryTermFrequency = CalculateQueryTermFrequency(userQuery);

            foreach (KeyValuePair <string, int> entry in queryTermFrequency)
            {
                if (InverseDocumentFrequency.ContainsKey(entry.Key))
                {
                    var tfidf = entry.Value * InverseDocumentFrequency[entry.Key];
                    QueryTfIdfWeight.Add(entry.Key, tfidf);
                }
                else
                {
                    QueryTfIdfWeight.Add(entry.Key, 0);
                }
            }
        }