5_A assignament

Request

Compute - in both languages C# and VB.NET (and optionally in js) - a frequency distribution of the meaningful words from any text file and create a personal graphical representation of the corresponding “word cloud” (in case, can use animation if you wish), keeping into account the frequencies of the words.

My Solution

Code in C and VB.NET#

Main Form:

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61   public partial class Form1 : Form { public Form1() { InitializeComponent(); } SortedDictionary wDstr = new SortedDictionary(); private void Form1_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { var filePath = string.Empty; openFileDialog1.InitialDirectory = "c:\\"; openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; openFileDialog1.FilterIndex = 2; openFileDialog1.RestoreDirectory = true; openFileDialog1.Title = "Select Text File"; if (openFileDialog1.ShowDialog() == DialogResult.OK) { //Get the path of specified file filePath = openFileDialog1.FileName; //Read the contents of the file into a stream using (StreamReader sr = new StreamReader(filePath)) { while (sr.Peek() >= 0) { string line = sr.ReadLine(); char[] delimiters = new char[] { ' ', '\r', '\n' }; string[] words = line.Split(delimiters, StringSplitOptions.RemoveEmptyEntries); int i = 0; foreach (string word in words) { if (!wDstr.TryGetValue(word, out i)) wDstr.Add(word, 1); else { wDstr.Remove(word); i++; wDstr.Add(word, i); } } } } int j = 0; foreach(var w in wDstr) { chart1.Series["Words"].Points.AddXY(w.Key, w.Value); } } } }