Assignment 4
Due: 3:00 PM on Wednesday, February 27, 2008
Question #1
Consider the following file format for storing a sparse integer-valued
2D-matrix: The first line gives the dimensions of the x- and y-axes of
this matrix, respectively, and each subsequent line describes one
entry in this matrix in terms of its x- and y-coordinates and its value.
Each such matrix is stored in a file with extension ".s2m"
Write and document a Python script sp2Dmat.py which takes as
command-line arguments two operand sparse 2D matrix files, an operator from
the set {+, -, x}, i.e., 2D-matrix addition, subtraction, and
multiplication, and a result sparse 2D matrix file into which the
result of this operation on those operands will be written. Note that
these arguments must be organized to give the appearance of a mathematical
expression, e.g., "python sp2Dmat.py blah = m1 - m2".
This script must produce the appropriate error message (see typescript-file
below) when either the number of arguments is incorrect or an unrecognized
operation is invoked. Your script must work on datafiles
m1.s2m and
m2.s2m
to produce the output given in typescript-file
sp2Dmat.script. You may assume that all given
datafiles are formatted correctly and are readable.
Question #2
Consider the tagged input file described in Assignment #3 with the
addition of a line tagged "LEN" to each record that specifies the
number of pages taken up in the conference proceedings by the paper
described in that record. In the proceedings, the papers will be
sorted alphabetically by title. The proceedings must also have a
title-word index consisting of all non-trivial words in which the first
letter is a capital letter; in this index, these words are sorted in
alphabetical order, and each word has an associated list of the
start-pages (in ascending order) of all articles whose titles include
that word.
Write and document a Python script titleIndex.py which takes as
command-line arguments a tagged input file of the format described
above and a file listing trivial words to be ignored (one per line), and
prints an index of the form described above.
Your script must work on tagged file
titleIndex.dat
and trivial word-list files
ignore1.txt and
ignore2.txt
to produce the output given in typescript-file
titleIndex.script.
You may assume that all given
files are formatted correctly and are readable.
Hints
You may find dictionaries and sets of use in both questions.
Submission
Please hand in printed copies of all of your Python script files.
You must also submit these files electronically using the
submit-assignment command.
At the top of each script, please include a triple-quoted docstring
with your name and student number, the name of this course and the
assignment number, and a brief description of your program; also include
brief comments throughout your program describing various code-blocks.
You do not have to develop your code on our CS departmental systems.
However, as your code will be compiled and tested on our CS departmental
systems (which use Python Version 2.4) as part of the
assignment marking process,
you should ensure that your code compiles and runs correctly on at
least one of these systems.
- Feb 20, 10:40am
Assignment #4 posted.
Created: February 20, 2008
Last Modified: February 20, 2008