Question: Write a method called createIndex that creates an inverted index for a list of documents. Your method should take one argument, a list of documents

Write a method called createIndex that creates an inverted index for a list of documents. Your method should take one argument, a list of "documents" where each document is represented as a string. Your method should return a map where the keys are individual words that appear in the parameter list of documents and the values are sets of documents in which those words appear. For example, suppose the variable titles contains the following list: [Raiders of the Lost Ark, The Temple of Doom, The Last Crusade] In this case, the call createIndex(titles) would return the following map: {ark=[Raiders of the Lost Ark], crusade=[The Last Crusade], doom=[The Temple of Doom], last=[The Last Crusade], lost=[Raiders of the Lost Ark], of=[The Temple of Doom, Raiders of the Lost Ark], raiders=[Raiders of the Lost Ark], temple=[The Temple of Doom], the=[The Temple of Doom, The Last Crusade, Raiders of the Lost Ark]} The keys of the returned map should be case-insensitive (i.e. treat "The" and "the" as the same word). The keys of the returned map should be in sorted order, while the sets in the values should prefer fast lookup speed. You may assume that the parameter passed in non-null, that each element of the parameter is a non-null and non-empty string, and that words in each document are separated by a single space.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!