Ejemplo n.º 1
0
        }         //end Words()

        /// <summary>
        /// paramterized constructor
        /// </summary>
        /// <param name="obj">Text object to be manipulated</param>
        public Words(Text obj)
        {
            DistinctWord dw;

            for (int i = 0; i < obj.TokenList.Count; i++)
            {
                dw = new DistinctWord(obj.TokenList[i]);
                DistinctList.Add(dw);
            }
        }//end Words(Text)
Ejemplo n.º 2
0
        }     //End Method

        /// <summary>
        /// Tests to see whether the word should be added to an existing word's count or added to the list
        /// </summary>
        /// <param name="tempWord">The word to be added</param>
        private void AddWordOrCount(DistinctWord tempWord)
        {
            //if it is a word it checks to see if it is already in the list and adds it to the respective words count
            if (!DistinctWords.Contains(tempWord))
            {
                DistinctWords.Add(tempWord);
            }
            else
            {
                foreach (var word in DistinctWords)
                {
                    word.Count += (word.Word == tempWord.Word) ? 1 : 0;
                } //End Foreach
            }     //End If
        }
Ejemplo n.º 3
0
        }//End Method

        /// <summary>
        /// Parameterized constructor that takes a text object and puts the tokens into the list of Distinct words.
        /// </summary>
        /// <param name="words">Text object containing File text</param>
        public Words(Text words)
        {
            DistinctWords = new List <DistinctWord>();

            //Loops through the list and checks if the item is a word
            foreach (var item in words.Tokens)
            {
                if (wordPattern.IsMatch(item))
                {
                    DistinctWord matchedWord = new DistinctWord(item);

                    AddWordOrCount(matchedWord);
                } //End If
            }     //End Foreach
            DistinctWords.Sort();
        }         //End Method
Ejemplo n.º 4
0
        readonly int Count; //Count for each word
        /// <summary>
        /// default constructor
        /// </summary>
        public Words()
        {
            DistinctWord dw;

            DistinctList = new List <DistinctWord>();
            Text PathText = new Text();

            for (int i = 0; i < PathText.TokenList.Count; i++)
            {
                if (PathText.TokenList[i].Contains("\\w"))
                {
                    dw = new DistinctWord(PathText.TokenList[i]);
                    DistinctList.Add(dw);
                    Count = dw.Counter;
                } //end if
            }     //end for
            Display();
        }         //end Words()
Ejemplo n.º 5
0
        }//Words(Text)

        /// <summary>
        /// Alphabetizes all the DistinctWords in words
        /// </summary>
        private static void Alphabetize()
        {
            DistinctWord temp;      //holds latest (alphabetically) distinctword found
            int          prevIndex; //holds index location of the above

            //remove dupes
            for (int j = words.Count; j > 0; j--)
            {
                temp = new DistinctWord(words[j - 1]);
                for (int i = 0; i < j; i++)
                {
                    if (temp.Equals(words[i]) && words.IndexOf(temp) != j - 1) //Word found is the same word, different indexes
                    {
                        words[j - 1].count++;                                  //DistinctWord now has count of 2
                        words.Remove(words[i]);                                //Duplicate word removed
                        i--;                                                   //i searches this index again next loop (since a new word has moved here)
                        j--;                                                   //j searches one less index total
                    }//else if
                }//for
            }//for

            //aplhabetize tokens
            for (int j = words.Count; j > 0; j--)
            {
                temp      = new DistinctWord(words[0]);
                prevIndex = 0;
                for (int i = 0; i < j; i++)
                {
                    if (temp.CompareTo(words[i]) > 0)
                    {
                        temp      = new DistinctWord(words[i]);
                        prevIndex = i;
                    } //if
                }     //for
                words.Remove(words[prevIndex]);
                words.Add(temp);
            } //for
        }     //Alphabetize()
Ejemplo n.º 6
0
        public static void Main(string[] args)
        {
            //user input for name, email address, and phone number as well as validation
            Console.WriteLine("Hello! Welcome to my first project for my Data Structures Class.");
            Console.WriteLine("My name is Greer Goodman.");
            Console.WriteLine("What is your name?\n");
            User.Name = Console.ReadLine();
            Console.WriteLine("What is your email address?\n");
            User.Email = Console.ReadLine();
            Console.WriteLine("And last but not least, what is your phone number?\n");
            User.Phone = Console.ReadLine();
            bool check = false;//checks to see if the user input valid information

            while (check == false)
            {
                if (User.TestEmail() == true && User.TestPhone() == true)
                {
                    check = true;
                }//end if
                else if (User.TestEmail() == false || User.TestPhone() == false)
                {
                    Console.WriteLine("One of the fields you entered is incorrect. Please fix it.");
                    Console.WriteLine("What is your email address?\n");
                    User.Email = Console.ReadLine();
                    Console.WriteLine("And last but not least, what is your phone number?\n");
                    User.Phone = Console.ReadLine();
                }//end if
                Console.WriteLine("Press Enter to continue.");
                Console.ReadLine();
            }//end while

            //Menu creation and implementation
            UtilityNamespace.Menu NewMenu = new UtilityNamespace.Menu("Data Structures Project 1 Menu");
            NewMenu += "1. Open a file and tokenize it";
            NewMenu += "2. Get Distinct Words";
            NewMenu += "3. Get a list of Distinct Words";
            NewMenu += "4. Get a Sentence";
            NewMenu += "5. Get a list of Sentences";
            NewMenu += "6. Get a Paragraph";
            NewMenu += "7. Get a list of Paragraphs";
            NewMenu += "8. Exit";

            int  choice = 0;       //used for switch choosing.
            Text NewText;          //varibale created here so other switches can use it
            bool OneFirst = false; // checks to see if option one has been chosen yet

            while (choice != 8)
            {
                NewMenu.Display();
                choice = NewMenu.GetChoice();
                switch (choice)
                {
                case 1:
                    Console.WriteLine("Please select a text file to work with.");
                    OpenFileDialog OpenDlg = new OpenFileDialog();
                    OpenDlg.Filter           = "text files|*.txt;*.text|all files|*.*";
                    OpenDlg.InitialDirectory = "Project1/TextFiles";
                    OpenDlg.Title            = "Select a file with which you would like to work with.";
                    if (DialogResult.Cancel != OpenDlg.ShowDialog())
                    {
                        FileName = OpenDlg.FileName;
                    }
                    NewText  = new Text();
                    OneFirst = true;
                    break;

                case 2:
                    if (OneFirst != false)
                    {
                        DistinctWord dw = new DistinctWord();
                        Console.WriteLine(dw.ToString());
                        Console.ReadLine();
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Please press enter and choose option one to continue.");
                        Console.ReadLine();
                        break;
                    }

                case 3:
                    if (OneFirst != false)
                    {
                        Words NewWord = new Words();
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Please press enter and choose option one to continue.");
                        Console.ReadLine();
                        break;
                    }

                case 4:
                    if (OneFirst != false)
                    {
                        Sentence Sent = new Sentence();
                        Console.WriteLine(Sent.ToString());
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Please press enter and choose option one to continue.");
                        Console.ReadLine();
                        break;
                    }

                case 5:
                    if (OneFirst != false)
                    {
                        SentenceList SentList = new SentenceList();
                        SentenceList.Display();
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Please press enter and choose option one to continue.");
                        Console.ReadLine();
                        break;
                    }

                case 6:
                    if (OneFirst != false)
                    {
                        Paragraph Para = new Paragraph();
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Please press enter and choose option one to continue.");
                        Console.ReadLine();
                        break;
                    }

                case 7:
                    if (OneFirst != false)
                    {
                        ParagraphList ParaList = new ParagraphList();
                        ParagraphList.Display();
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Please press enter and choose option one to continue.");
                        Console.ReadLine();
                        break;
                    }

                case 8:
                    Console.WriteLine("Thank{0} ({1}, {2}) for using my program. I was completely unprepared to turn this project in. Have a nice day. ", User.Name, User.Email, User.Phone);
                    Console.ReadLine();
                    Environment.Exit(0);
                    break;
                } //end switch
            }     //end while
        }         //end main(string[])
Ejemplo n.º 7
0
        /// <summary>
        /// Finds all the Distinct Words and Counts how many the times each individual distinct word
        /// appears in the text.
        /// </summary>
        /// <param name="t1">The Text file the user has chosen.</param>
        public void CountingAndSetting(Text t1)
        {
            List <String> OriginalTokenList = new List <string>();//stores the original tokens

            for (int i = 0; i < t1.Tokens.Count; i++)
            {
                OriginalTokenList.Add(t1.Tokens[i]);
            }


            List <String> DistinctTokenList = new List <string>(); //stores the distinct tokens found in the original

            DistinctWordList = new List <DistinctWord>();          //Instantiates the DistinctWordList
                                                                   //to put in all the distinct words

            OriginalTokenList.RemoveAll(s => s.Equals("."));       //Removes all periods
            OriginalTokenList.RemoveAll(s => s.Equals("!"));       //Removes all exclamation
            OriginalTokenList.RemoveAll(s => s.Equals("?"));       //Removes all question marks
            OriginalTokenList.RemoveAll(s => s.Equals(";"));       //Removes all semicolons
            OriginalTokenList.RemoveAll(s => s.Equals(","));       //Removes all commas
            OriginalTokenList.RemoveAll(s => s.Equals(":"));       //Removes all colons
            OriginalTokenList.RemoveAll(s => s.Equals("@"));       //Removes all @
            OriginalTokenList.RemoveAll(s => s.Equals("\""));      //Removes all parenthesis



            OriginalTokenList.RemoveAll(s => s.Equals("\n"));       //Removes all newlines
            OriginalTokenList.RemoveAll(s => s.Equals("\r"));       //Removes all returnlines
            OriginalTokenList.RemoveAll(s => s.Equals("\t"));       //Removes all tabs



            OriginalTokenList.RemoveAll(NoSpaces);


            OriginalTokenList = LowerCase(OriginalTokenList);


            for (int i = 0; i < OriginalTokenList.Count; i++)
            {
                if (DistinctTokenList.IndexOf(OriginalTokenList[i]) < 0)
                {
                    //This will return a -1 if the token from OriginalTokenList
                    //is not in the DistinctTokenList

                    DistinctTokenList.Add(OriginalTokenList[i]);
                    //If the DistinctTokenList does not contain something in
                    //the Original, it gets added to the DistinctTokenList
                }
            }



            for (int i = 0; i < DistinctTokenList.Count; i++)
            {
                DistinctWord w1 = new DistinctWord(DistinctTokenList[i]);
                DistinctWordList.Add(w1);
            }
            //Puts all the strings in DistinctTokenList into the class
            //property, DistinctWordList, as DistinctWord objects


            for (int i = 0; i < DistinctWordList.Count; i++)
            {
                for (int j = 0; j < OriginalTokenList.Count; j++)
                {
                    if (DistinctWordList[i].Word.ToLower().Equals(OriginalTokenList[j].ToLower()))
                    {
                        DistinctWordList[i].Count += 1;
                    }

                    //The outer loop loops through all elements of the DistinctWord List. The inner
                    //Loop compares each element of the DistinctWordList to all of the OriginalTokenList
                    //THe if statement compares the string from both lists and sees if they are equal.
                    //In order for this equality to work properly, both strings must be lower cased.
                    //If there is a match for the DistinctWord, Its Counter gets bumped up by 1
                }
            }
        }//end CountingAndSetting(Text)