// Copyright 2013, University of Freiburg, // Chair of Algorithms and Data Structures. // Author: Hannah Bast . // NOTE: this is a code design suggestion in pseudo-code. It is not supposed to // be compilable in any language. You have to translate it to Java or C++ // yourself. The purpose of this file is to suggest a basic design and settle // questions you might have on what exactly your code is supossed to do. // Implementation of a very simple inverted index. class InvertedIndex { // PUBLIC MEMBERS // Create an empty index. InvertedIndex(); // Build inverted lists from a given text file. The expected format of the // file is one line per document with each line containing the text from the // document without newlines. // // IMPLEMENTATION NOTE: convert all words to lower case. If a word occurs // multiple times in a document, add the document id only once to the inverted // list. void buildFromTextFile(String fileName); // Given a query, return a list of all documents, sorted by document id, that // contain all of the words in the query. If there are more than k such // documents, return only the first k in that order, for the given value of k. // // IMPLEMENTATION NOTE: do iterative pair-wise intersection, as explained in // the lecture, and using method intersect below. Array processQuery(String query, int k); // PRIVATE MEMBERS // Intersect two sorted lists of integers. Returns the result list = sorted // list of ids contained in both input lists. // // IMPLEMENTATION NOTE: use the simple linear-time intersect explained in the // lecture. Array intersect(Array list1, Array list2); // The inverted lists = a sorted list of document ids, one for each word that // occurs at least once in the given collection. Map> invertedLists; // The text of all the documents, indexed by document id. Since document ids // are consecutive, starting at 0, a simple array suffices. Array documents; }