예제 #1
0
        /// <summary>
        /// Gets Postings of a given term from in-memory index.
        /// </summary>
        /// <param name="term">a processed string</param>
        /// <return>a posting list</return>
        public IList <Posting> GetPostings(string term)
        {
            List <Posting> result = postingMap.Get(term);

            Console.WriteLine("results for get postings" + result.Count);
            if (default(List <Posting>) == result)
            {
                return(new List <Posting>());
            }
            else
            {
                return(result);
            }
        }
        public void TestWriteToDisk()
        {
            OnDiskDictionary <string, string> dic = new OnDiskDictionary <string, string>("./", "TestAlphabet", new StringEncoderDecoder(), new StringEncoderDecoder());

            dic.Add("A", "Apple");
            dic.Add("B", "Banana");
            dic.Add("C", "Cat");
            dic.Add("D", "Dog");
            dic.Add("E", "Eye");
            Assert.Equal("Apple", dic.Get("A"));
            Assert.Equal("Eye", dic.Get("E"));
            Assert.Equal("Banana", dic.Get("B"));
            Assert.Equal("Dog", dic.Get("D"));
            Assert.Equal("Cat", dic.Get("C"));
            dic.Clear();
        }
예제 #3
0
        /// <summary>
        /// Get a list of vocabularies for a given kGram
        /// </summary>
        /// <param name="kGram">K-gram to search for</param>
        /// <returns>A list of vocabularies</returns>
        public List <string> getVocabularies(string kGram)
        {
            //If requested k-gram's length is less than this k-gram size, use mini kgram to find the right k-gram
            if (kGram.Length < this.size)
            {
                HashSet <string> candidates = new HashSet <string>();

                List <string> possibleKGram = this.miniMap.Get(kGram);
                if (possibleKGram == default(List <string>))
                {
                    return(new List <string>());
                }

                List <List <string> > KGramLists = new List <List <string> >();

                foreach (string k in possibleKGram)
                {
                    List <string> result = map.Get(k);
                    if (result != default(List <string>))
                    {
                        foreach (string item in result)
                        {
                            candidates.Add(item);
                        }
                    }
                }

                return(candidates.ToList());
            }
            else
            {
                List <string> result = this.map.Get(kGram);
                return(default(List <string>) == result ? new List <string>() : result);
            }
        }
예제 #4
0
        // not sure what GetDocWeightsIds is used for  ? but apparently nothing references it so we might not even need it ???

        // public List<int> GetDocWeightsIds()
        // {
        //     List<int> documents = docWeigthsHashMap.GetKeys().ToList();
        //     List<PostingDocWeight> finalList = new List<PostingDocWeight>();
        //     foreach (int documentID in documents)
        //     {
        //         finalList.Add(GetPostingDocWeight(documentID));
        //     }

        //     return finalList;
        // }

        public PostingDocWeight GetPostingDocWeight(int docID)
        {
            PostingDocWeight result = docWeigthsHashMap.Get(docID);

            if (default(PostingDocWeight) == result)
            {
                return(new PostingDocWeight(0.0, 0, 0, 0.0));
            }
            else
            {
                return(result);
            }
        }
예제 #5
0
        public List <MaxPriorityQueue.InvertedIndex> GetPostingsFromTier(string term, int tierNumber = 1)
        {
            List <MaxPriorityQueue.InvertedIndex> result = new List <MaxPriorityQueue.InvertedIndex>();
            List <MaxPriorityQueue.InvertedIndex> temp   = new List <MaxPriorityQueue.InvertedIndex>();

            switch (tierNumber)
            {
            case 1:
                temp = tier1.Get(term);

                result.AddRange(temp);
                if (result.Count < 20)
                {
                    goto case 2;
                }
                else
                {
                    return(result);
                }


            case 2:

                temp = tier2.Get(term);
                result.AddRange(temp);

                if (result.Count < 20)
                {
                    goto case 3;
                }
                else
                {
                    return(result);
                }

            case 3:
                temp = tier3.Get(term);
                result.AddRange(temp);
                return(result);

            default:
                //an empty posting if the term does not exist.
                return(result);
            }
        }