Example #1
0
        ///<summary>
        ///Creates an Hashtable that is an Inverted index oif the collection
        ///</summary>
        ///<param name="folder">The folder containing the collection</param>
        ///<returns>
        ///A Hashtable of the collection
        ///</returns>
        public Dictionary <string, Dictionary <int, double> > InvertedIndex(string folder)
        {
            if (internalIndex != null)
            {
                internalIndex.Clear();
            }                                                                     // clears the memory usage of exisitng Index
            internalIndex = new Dictionary <string, Dictionary <int, double> >(); // the invertedIndex to be returned
            searchUtil    = new SearchUtilities();                                // instantiate SearchUtilities class object
            dynamic form1 = Application.OpenForms[0];                             // will create a reference to the Main Form object

            indexCount = 0;                                                       // a counter for how large the inverted index is.

            Dictionary <int, double> fileList = new Dictionary <int, double>();   // a list to populate the files that match a term

            stemmer = new PorterStemmer();                                        // instantiate a PorterStemmer object to stem words from files

            foreach (string file in searchUtil.IndexingFolders(folder))
            {
                int fileID = converter.AssignId(file); // create an Id from the string of the file and store in HashMap Converter.paths

                foreach (string word in ReadFromFile.GetWords(file))
                {
                    // stem the word
                    string stemmedWord = stemmer.StemWord(word);
                    // create the Dictionary for the collection
                    if (internalIndex.ContainsKey(stemmedWord))
                    {
                        fileList = internalIndex[stemmedWord];
                        // check if the file is already in the list or not
                        if (fileList.ContainsKey(fileID))
                        {
                            fileList[fileID] = double.Parse(fileList[fileID].ToString()) + 1;
                        }
                        else
                        {
                            fileList.Add(fileID, 1.0);
                        }

                        internalIndex[stemmedWord] = fileList;
                    }
                    else
                    {
                        // create a new key and start new List of files for the key
                        fileList = new Dictionary <int, double>
                        {
                            { fileID, 1.0 }
                        };
                        internalIndex.Add(stemmedWord, fileList);
                        indexCount++;
                    }
                }
                form1.ShowIndexLength(false); // cross thread method to keep a running total of the index size on the Main form.
            }
            return(internalIndex);
        }
Example #2
0
        public Form1()
        {
            InitializeComponent(); // Auto-created methods .. do not alter anything in this method

            // Initialize or instantiate class objects or private variables for use in the form
            FileOutput.MouseDoubleClick += new MouseEventHandler(FileOutput_DoubleClick);
            db              = new Database(newWordsDataSet);
            indexUtils      = new IndexUtilities();
            searchUtil      = new SearchUtilities();
            tStart          = new ThreadStart(BuildIndex);
            thread          = new Thread(tStart);
            searchCount     = 0;
            totalSearchTime = 0;
            isIndexCreated  = false;
        }
Example #3
0
        /*
         * Returns a Hashtable of the collection
         */
        public Hashtable GetHashtable(string folder)
        {
            Hashtable wf = new Hashtable();

            searchUtil = new SearchUtilities(); // instantiated in this method, as its the only method requiring SearchUtilites.

            string[] words = searchUtil.GetWordCollection(folder);

            foreach (string word in words)
            {
                // create the Hashtable for the collection
                if (wf.ContainsKey(word))
                {
                    wf[word] = double.Parse(wf[word].ToString()) + 1;
                }
                else
                {
                    wf.Add(word, 1.0);
                }
            }

            return(wf);
        }