public void AddTfIdfToDocuments() { foreach (var term in invertedIndex.Keys) { double idf = invertedIndex[term].Idf; TermPostingList postingLine = GetPostingLineFromPostingFile(term, invertedIndex[term].PointerLine); foreach (var termData in postingLine.PostingList) { DocumentsDataList[termData.DocumentId].TotalSquaredTfIdf += Math.Pow((termData.TF / DocumentsDataList[termData.DocumentId].FrequentTermNumberOfInstances) * idf, 2); } } }
/// <summary> /// Gets all the posting list of the terms in the query /// </summary> /// <param name="termsInQuery">List of terms in the query</param> /// <returns>Dictionary of the term and it's posting list</returns> private Dictionary <string, TermPostingList> GetQueryPostingList(List <string> termsInQuery) { Dictionary <string, TermPostingList> queryPostingsList = new Dictionary <string, TermPostingList>(); foreach (var term in termsInQuery) // for each term in the query { TermPostingList termPostingList = null; if (_controller.InvertedIndex.ContainsKey(term)) // case the term appearce in the inverted index { //switch (_controller.InvertedIndex[term].TermDictionaryPointer) // check the location of the posting list //{ //case TermDictionaryPointer.Cache: // case the posting line is in the cache, extract from the cacheDictionary // termPostingList = _controller.CacheDictionary[term].PostingList; // break; //case TermDictionaryPointer.Posting:// case the posting line is in the posting file, extract from the file termPostingList = GetPostingLineFromPostingFile(term, _controller.InvertedIndex[term].PointerLine); //break; // } queryPostingsList.Add(term, termPostingList); // add the posting list to the dictionary } } return(queryPostingsList); }