November 5, 2009 · homework

In this homework you will apply some of the advanced function programming we have discussed, including using named arguments and default values. It covers material up to November 5th, and is due November 13th.

  1. Use svn to copy my solution to homework 8 from resources/py into your personal directory as hmwk10.py (5 points)
  2. Modify the mean_word_len and mean_sent_len functions to accept two optional
    arguments, ignore_stop and use_set. The default for each of
    these should be True. If use_set is True, you should convert the
    stopword corpus to a set. If ignore_stop is True, you should ignore stopwords from the calculation (which is what the code in hmwk8.py does). (15 points)
  3. Now create a new file called means_timing.py. In this file, import your hmwk10.py module, and use the timeit module to test how long it takes to calculate the mean sentence length 100 times, trying all 4 combinations of the parameters of use_set and ignore_stop. (10 points)
  4. Now add another global option called include-stop (i for short) to hmwk10.py specifying whether or not to ignore stopwords when calculating mean word length and sentence length. The default should be False. (10 points)
  5. Modify the calc_text_stats function so that it also computes the percentage of words that are stop words. 10 points
  6. Now create a bash script which prints out the mean word and sentence length for Huck Finn, Tom Sawyer, Candide, and the Devil’s dictionary. Pipe the output to sort to sort by mean sentence length. Try it both including and ignoring stop words. Your output (when ignoring stop words), should look like the that below.(10 points)
    filename          mean_word_len mean_sent_len  per_stop_words
    tomSawyer                  5.51          7.46            42.2
    Candide                    6.07          9.04            43.5
    huckFinn                   4.93          9.32            45.0
    devilsDictionary           6.30         10.08            40.2
    
Written by Robert Felty


2 Comments to “Homework 10 – Advanced function usage”

  1. ash_v says:

    In Q2, if ignore_stop has the value False, and use_set is True, then we get a contradiction.

Leave a Reply

You must be logged in to post a comment.

Subscribe without commenting