Project 3: WordSmith

Analyzing vocabulary in texts

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, cleanup.cpp, log.txt.

Procedural Requirements

  1. The official development/testing/assessment environment is specified in the Course Organizer.

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

    LIB/proj3/main_wb.cpp       # driver program 
    LIB/proj3/data*             # sample word files
    LIB/proj3/makefile          # makefile for project
    LIB/scripts/submit.sh       # submit script
    LIB/proj3/deliverables.sh   # submission configuration file
    

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

  4. 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.

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

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

  7. Submit the assignment using command submit.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/proj3/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; // c1,c2 are column widths
    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 optimal choice (other than RBLLT) is UOVector - unimodal set API with very fast search time. However it is important that the project is functional with all of the choices currently available, even if functionality isn't what you want for the multimodal options. This tests the generality and genericity of your code. Then, later, when you have created RBLLT, you can switch over and have fast insert times along with fast search times.
    4. The list of filenames is an fsu::List of fsu::String objects
    You are free to add private helper methods to the class. You should not add any class variables other than wordset_ and infiles_.
  3. Add a private helper method as follows:
    private: // string cleaner-upper
      static void Cleanup  (fsu::String&);
    
    Cleanup is used to "clean up" the string passed by reference according to the processing rules above. The implementation of Cleanup should be in the separate file cleanup.cpp. (This function may be used again in a future assignment.)
  4. Note that the fsu::Pair template class has comparison operators defined that emphasize the first coordinate of the pair (called "first_", but playing the role of "key"), so that two pairs are considered equal, for example, if they have equal keys.
  5. The application should function correctly in every respect using fsu::UOList < EntryType > for SetType.
  6. The application should function correctly in every respect using fsu::UOVector < EntryType > for SetType.
  7. 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