Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python homework question. 1. Create a class InvertedIndex to act as an abstract data type for the inverted index data structure. It should include the

Python homework question.

1. Create a class InvertedIndex to act as an abstract data type for the inverted index data structure. It should include the following member functions/support these operation on its data:

A normalize(term) method that takes a str object stored in term and returns a stemmed version of that word suitable for a key in the inverted index

An add term(term, docID): method that adds the unnormalized str object term to the index if need be and records that the document with integral docID contains that term

An add document(document, id) method that takes a document as a str object with integral id and adds a tokenized, normalized version of the document to the inverted index. Stopwords in the document are not indexed.

A build index(corpus) method that takes a corpus as a list of documents and uses add document as necessary to build the index. A documents ID is its index in the list corpus , so the first document has ID 0, next 1, and so on.

An object of type InvertedIndex should support the operator [term] for term lookup. In other words, if object ii was constructed via ii = Inverted Index() and a suitable index built, then

ii[bread] would return the list of document IDs containing the search term bread. Hint: magic methods

By default, if a term is not in the index, it should return the empty list [].

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Lab Manual For Database Development

Authors: Rachelle Reese

1st Custom Edition

1256741736, 978-1256741732

More Books

Students also viewed these Databases questions

Question

=+(3.14) Q((HOA) U (HenB)) = P(HOA) +P (H'nB) for A, B E 70.

Answered: 1 week ago