using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void buttonIndex_Click_Click(object sender, EventArgs e) { if (openFileDialog.ShowDialog() != DialogResult.OK) return; // parse each file and build the inverted index. foreach (string fileName in openFileDialog.FileNames) { string text = File.ReadAllText(fileName).Replace("\r", " ").Replace("\n", " "); string[] terms = text.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); // parse each term (word) in text file and put it in dictionary foreach (string term in terms) { if (!InvertedIndex.ContainsKey(term)) InvertedIndex.Add(term, new List<string>()); if (!InvertedIndex[term].Contains(fileName)) InvertedIndex[term].Add(fileName); } } // update label labelIndex.Text = openFileDialog.FileNames.Length.ToString() + " files indexed"; } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)