Homework 3: WordSmith

Educational Objectives: On successful completion of this assignment, the student should be able to

Background Knowledge Required: Be sure that you have mastered the material in these chapters before beginning the assignment:
Introduction to Sets, Introduction to Maps.

Operational Objectives: Create a client WordSmith of the Set API that serves as a text analysis application.

Deliverables: wordsmith.h, wordsmith.cpp, makefile, log.txt.

Procedural Requirements

  1. Begin by copying all of the files from the assignment distribution directory, which will include:

    hw3/main.cpp        # driver program for wordsmith
    hw3/data*           # sample word files
    hw3/makefile        # makefile for project
    hw3/hw3submit.sh    # submit script
    

  2. Define and implement the class WordSmith, placing the class API in the header file wordsmith.h and implementations in the code file wordsmith.cpp

  3. Be sure to fully cite all references used for code and ideas, including URLs for web-based resources. These citations should be in the file documentation and if appropriate detailed in relevant code locations.

  4. Test your API using the distributed client program main.cpp.

  5. Keep a text file log of your development and testing activities in log.txt.

  6. Submit the assignment using the script hw3submit.sh.

    Warning: Submit scripts do not work on the program and linprog servers. Use shell.cs.fsu.edu to submit assignments. If you do not receive the second confirmation with the contents of your assignment, there has been a malfunction.

Functionality Requirements

  1. WordSmith can read an arbitrary text file on command and extract all of the words in the file, maintaining the unique words, along with the frequency of occurrence of each word, in a set. Letters are converted to lower case before comparison and storage. A word is understood to be a string of letters and/or digits, with certain other symbols allowed. Most non-alpha-numeric characters are ignored. Exceptions are hyphens and apostrophes, which are considered part of the word, so that contractions and hyphenated constructs are counted as individual words. (Note: two adjacent apostrophes are not considered part of a word, since they represent closing of a quotation.)
  2. WordSmith can write an analysis of its current stored words. This analysis consists of a lexicographical listing of the unique words together with their frequencies, followed by a count of the total number of words and the vocabulary size (number of unique words). Note that this is a cumulative analysis over all of the input files read since starting up wordsmith.x (or since the last clearing operation).
  3. Note that a component of the analysis and summary is a listing of the files whose contents contributed to the data.
  4. WordSmith must operate with the supplied driver program LIB/hw3/main.cpp which has a user interface with the following options:
    1. Read a file. Read the words of the file into the structure (and report summary to screen).
    2. Write an analysis of the current data (including input file names) to a file (and report summary to screen).
    3. Clear current data and clear all data from the structure.
    4. Show current size and send a data summary to the screen.
    5. display Menu.
    6. eXit BATCH mode.
    7. Quit program.
    Use the source code in the driver program main.cpp to determine the syntax requirements for the WordSmith public interface. Use the executable in area51 to model expected behavior. The following shows the exact syntax of the WordSmith API required by the driver program:
    bool   ReadText     (const fsu::String& infile);
    bool   WriteReport  (const fsu::String& outfile, unsigned short c1 = 15, unsigned short c2 = 15) const;
    void   ShowSummary  () const;
    void   ClearData    ();
    
  5. From any directory having access to the course library and containing your submission files, entering "make" should result in an executable called "wordsmith.x". (NOTE: This requirement will necessitate only a name change for the executable in the distributed makefile.)

Implementation Requirements.

  1. You should define a class WordSmith, declared in the file wordsmith.h and implemented in the file wordsmith.cpp. An object of type WordSmith is used by the driver program to create the executable wordsmith.x.
  2. Use the following to define internal types and private class variables for WordSmith:
    private:
      // the internal class terminology:
      typedef fsu::Pair      < fsu::String, unsigned long >  EntryType;
      typedef fsu::LessThan  < EntryType >                   PredicateType;
    
      // choose one associative container class for SetType:
      typedef fsu::UOList          < EntryType , PredicateType >      SetType;
      // typedef fsu::MOList          < EntryType , PredicateType >      SetType;
      // typedef fsu::UOVector        < EntryType , PredicateType >      SetType;
      // typedef fsu::MOVector        < EntryType , PredicateType >      SetType;
      // typedef fsu::RBLLT           < EntryType , PredicateType >      SetType;
    
      // declare the two class variables:
      SetType                    wordset_;
      fsu::List < fsu::String >  infiles_;
    };
    
    This will serve several useful purposes:
    1. Changing the structure used for SetType is as simple as changing which typedef statement is uncommented in the WordSmith class definition.
    2. It is ensured that you are writing to the Set API
    3. The list of filenames is an fsu::List of fsu::String objects
    4. The "RBLLT" option will be used later when we develope left-leaning red-black trees.
    You are free to add private helper methods to the class. You should not add any class variables other than wordset_ and infiles_.
  3. Note that the fsu::Pair template class has comparison operators defined that emphasize the first coordinate of the (called the "first_", but playing the role of "key"), so that two pairs are considered equal, for example, if they have equal keys.
  4. The application should function correctly in every respect using fsu::UOList < EntryType > for SetType.
  5. The application should function correctly in every respect using fsu::UOVector < EntryType > for SetType.
  6. As usual, you should employ good software design practice. Your application should be completely robust and all classes you define should be thoroughly tested for correct function, robust behavior, and against memory leaks. Your wordsmith.x should mimic, or improve upon, the behavior illustrated in area51/wordsmith.x.

Hints