This assignment and its reflection are due by Thursday, May 2 at 11:59 pm.
You should submit your finished
document.py
,
search_engine.py
,
and hw4_test.py
on Gradescope as a zip file (described below) and the reflection on Google Forms
At a high-level, a search-engine is an algorithm that accepts a query from the user, and computes how relevant a given document is to that query. The search engine can then rank documents according to their relevance.
In this assignment you will implement your own search engine by defining two classes, document.py
and search_engine.py
. The Document
class represents a single file in the search engine, and the SearchEngine
class handles the functionality of querying the collection of stored Documents
. The SearchEngine
will use the TF-IDF (term frequency - inverse document frequency) algorithm to compute the relevance of a document to a given term.
The purpose of this assignment is to introduce you to writing cohesive python classes. This will include public methods, private methods, and data structures stored as fields. Additionally, you will work with common indexing algorithms, and consider efficient ways to store data that will be frequently accessed by the TF-IDF algorithm.
After this homework, students will be able to:
Here are some baseline expectations we expect you to meet:
Follow the course collaboration policies
You should download the starter code hw4.zip and open it as the project in Visual Studio Code. The files included are:
main.py
: A python file which will allow a user to run a new search engine at the command line. More information about this file is included later in the specification.wikipedia
: This directory contains a number of wikipedia files, and your SearchEngine can be used to query and rank the files.hw4_test.py
: The file you should put your tests for document.py
and search_engine.py
in.cse163_utils.py
: A file where we will store utility functions for helping you write tests.To implement the document ranking algorithm you will use the TF-IDF (term frequency- inverse document frequency) algorithm. This is just a fancy way of weighting documents based on their relevance to a search term. TF-IDF is one of the most popular term-weighting schemes - 83% of text-based recommender systems use TF-IDF.
The TF-IDF algorithm consists of two main computations. The following information describes these computations at a high-level, and the exact equations will be included later in the spec.
Term Frequency
The term frequency is computed on a document level, and it represents how often a search term appears in a specific document.
Inverse Document Frequency
Because filler words such as βtheβ are so common, term frequency tends to incorrectly weight documents that use the word βtheβ often. The inverse document frequency is a measure of how often the word appears in the entire set of documents. We then use this value to diminish the weight fo terms that occur very frequently.
Part 4a: Submit Assignment and Part 4b: Complete Reflection. On Gradescope, you should submit a zip of your hw4
directory.
Note: We are asking you to turn in your assignment in a different format this time. Because there are so many files and you might want to create your own directories containing text for testing, we are asking you to use zip
to turn in the assignment. You should zip
your hw4
folder and submit that to Gradescope (instructions below). Your zip
archive should have the following structure when we unzip it (this should require no extra work if you just zip
the hw4
folder). You can always test this by moving your zip
archive to another directory, and unzipping it there to see if the archive had the correct structure.
hw4
βββ cse163_utils.py
βββ document.py
βββ hw4_test.py
βββ main.py
βββ search_engine.py
βββ test_dir1
βΒ Β βββ ...
βββ ...
Where test_dir1
is one of the directory of test documents for your tests. You don't have to use that name, but you should incldue those directories of documents for testing.
UPDATE: You do NOT need to include the wikipedia
dataset in your submission. To accomplish this, move the wikipedia
folder outside the hw4
folder before you zip
it. You will probably want to move it back after you finish the zip so you can continue to develop your code.
zip
Your submission will be evaluated on the following dimensions
search_engine.py
and document.py
is a comment with your uwnetid.flake8
_
. You are allowed to access the fields directly in your tests since they are something you wrote personally and the tests don't need to behave like a true client should.