Exemple #1
0
        public static InvertedIndex CreateIndex(string[] files)
        {
            var result = new InvertedIndex();

            for (var i = 0; i < files.Length; i++)
            {
                var extracted = _cut.Extract(files[i]);

                var tokens = DefaultAnalyzer.Analyzer(extracted.Text.Split());

                foreach (var token in tokens)
                {
                    result.append(token, files[i]);
                }
            }

            foreach (KeyValuePair <string, Dictionary <string, int> > kvp in result.data)
            {
                Console.Write("Term = {0}", kvp.Key);

                foreach (KeyValuePair <string, int> res in kvp.Value)
                {
                    Console.Write("  Posting-List = {0},  Frequency = {1}", res.Key, res.Value);
                }

                Console.WriteLine();
            }


            return(result);
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            var files = Directory.EnumerateFiles(@"D:\Documents\DataSet\", "*.*", SearchOption.AllDirectories)
                        .Where(s => s.EndsWith(".pdf") || s.EndsWith(".doc") ||
                               s.EndsWith(".docx") || s.EndsWith(".ppt") || s.EndsWith(".ppts") ||
                               s.EndsWith(".xls") || s.EndsWith(".xlsx") || s.EndsWith(".txt") ||
                               s.EndsWith(".html") || s.EndsWith(".xml"));


            string[] filearr = files.ToArray();

            Console.WriteLine("Clicked!!" + filearr.Length);


            res = StringIndexer.CreateIndex(filearr);

            Console.WriteLine("\n\nWorked");



            AutoCompleteStringCollection sourceName = new AutoCompleteStringCollection();

            foreach (KeyValuePair <string, Dictionary <string, int> > kvp in res)
            {
                sourceName.Add(kvp.Key);
            }

            textBox1.AutoCompleteCustomSource = sourceName;
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="inder"></param>
        /// <param name="queryRep"></param>
        /// <returns></returns>
        public static Dictionary <string, Dictionary <string, int> > matchingFunction(InvertedIndex inder, string queryRep)
        {
            var res = from result in inder.data
                      where result.Key.Equals(queryRep)
                      select result;

            return(res.ToDictionary(p => p.Key, p => p.Value));
        }