コード例 #1
0
 /// <summary>
 /// Create a sorted list of DistinctWords using the Tokens in a Text object
 /// </summary>
 /// <param name="txt">The Text object of which we use its Tokens</param>
 public DistinctWordList(Text txt)
 {
     DistinctWords = new List<DistinctWord> ( );
     foreach (string s in txt.Tokens)
     {
         if (s.IndexOfAny ("!$%&*()-+=}{[]|\n\r\t':;?.,<>~".ToCharArray ( )) == -1)
         {
             DistinctWord dw = new DistinctWord (s);
             int n = DistinctWords.IndexOf (dw);
             if (n == -1)
                 DistinctWords.Add (dw);
             else
                 DistinctWords[n].Count++;
         }
     }
     DistinctWords.Sort ( );
 }
コード例 #2
0
        /// <summary>
        /// Parameterized constructor
        /// </summary>
        /// <param name="txt">The Text object from which the paragraphs are retrieved</param>
        public ParagraphList(Text txt)
            : this()
        {
            int start = 0;
            while (start < txt.Tokens.Count)
            {
                Paragraph p = new Paragraph (txt.Tokens, start);
                if (p.WordCount > 0)
                {
                    Paragraphs.Add (p);
                    ParagraphCount++;
                    AverageLength += p.WordCount;
                }

                start = p.End + 1;
            }
            if (ParagraphCount > 0)
                AverageLength /= ParagraphCount;
        }
コード例 #3
0
ファイル: SentenceList.cs プロジェクト: hornew/DataStructures
        /// <summary>
        /// Parameterized constructor
        /// </summary>
        /// <param name="txt">Text object from which to build the sentences</param>
        public SentenceList(Text txt)
            : this()
        {
            int start      = 0;

            while (start < txt.Tokens.Count)
            {
                Sentence s = new Sentence (txt.Tokens, start);
                if (s.WordCount > 0)
                {
                    Sentences.Add (s);
                    SentenceCount++;
                    AverageLength += s.WordCount;
                }
                start = s.End + 1;
            }

            if (SentenceCount > 0)
                AverageLength /= SentenceCount;
        }
コード例 #4
0
ファイル: MainWindow.cs プロジェクト: hornew/DataStructures
        /// <summary>
        /// Handles the Click event of the openToolStripMenuItem control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e"> <see cref="System.EventArgs"/>The instance containing the event data.</param>
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FileDialog = new OpenFileDialog();

            FileDialog.InitialDirectory = @"C:\";
            FileDialog.Title = "Open a Text File";
            FileDialog.Filter = "text files|*.txt|all files|*.*";

            if (FileDialog.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }

            try
            {
                NewFile = new Text(FileDialog.FileName);
                WordsList = new DistinctWordList(NewFile);
                Sentences = new SentenceList(NewFile);
                NewParagraphsList = new ParagraphList(NewFile);
                DisplayAnalysis();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }