Ejemplo n.º 1
0
        private void GetDataAndBuildInvertedIndex()
        {
            InvertedIndexBuildBegin(this, new EventArgs());

            TextProgress.Clear();
            TextProgress.AddInformation("Загрузка данных из БД...\r\n");
            LoadDataFromDB();
            TextProgress.AddInformation("Загрузка данных завершена.\r\n");

            TextProgress.AddInformation("Предобработка данных...\r\n");
            PreprocessData();
            TextProgress.AddInformation("Предобработка данных завершена\r\n");

            TextProgress.AddInformation("Построение индекса...\r\n");

            RussianStemmer RStemmer = new RussianStemmer();

            int SizeOfCorpus = DocumentCorpus.Count;
            int counter      = 0;

            TextProgress.AddInformation(String.Format("Прогресс: {0}/{1}\r\n", counter, SizeOfCorpus));
            foreach (IDocument doc in DocumentCorpus)
            {
                counter++;
                TextProgress.UpdateLastInfo(String.Format("Прогресс: {0}/{1}\r\n", counter, SizeOfCorpus));

                string[] terms = doc.Content.Split(' ');

                for (int i = 0; i < terms.Length; ++i)
                {
                    int    position = i + 1;
                    string term     = RStemmer.Stem(terms[i]);
                    if (term.Length < 2)
                    {
                        continue;
                    }

                    InvertedIndex.Add(term, doc.Id, position);
                }

                if (counter > 1000)
                {
                    break;
                }
            }

            TextProgress.AddInformation("Индекс построен.\r\n");

            InvertedIndexHasBeenBuilt(this, new EventArgs());
        }
Ejemplo n.º 2
0
 private static void BuildIndex(IInvertedIndex index, string[] lines)
 {
     index.Add(lines, "doc");
 }