// Copyright 2015, University of Freiburg, // Chair of Algorithms and Data Structures. // Author: Hannah Bast . // NOTE: this file contains specifications and design suggestions in // pseudo-code. It is not supposed to be compilable in any language. The // specifications are mandatory, the design suggestions are not. // Class for a simple inverted index. class InvertedIndex // Construct from given text file (one record per line). This method was // coded during lecture 1, using Python. void build_from_file(String file_name) // Merge two inverted lists (= sorted lists of record ids). Take proper care // of duplicates. For example, the merged result of 1, 3, 3, 4, 6 and 2, 3, // 5, 7, 7 is 1, 2, 3, 3, 3, 4, 5, 6, 7, 7. Alternatively, you may also // represent each list item as a pair (record id, count). Array merge(Array list1, Array list2) // Process a given keyword query. For each keyword, fetch the corresponding // inverted list. Merge using repeated calls to the method above, // that is: Merge the first two keywords, then merge the result list // with the list for the third keyword, and so on. // // Return a list of pairs (record id, count), where count = sum_i ki if the // i-th keyword matches the record in ki places, sorted by count. If the query // is empty, or there are no inverted lists for any of the keywords, return an // empty list. // // Optionally explore different (better) ways to sort the result list. Array> process_query(String query) // Main program: // // 1. Take a file name as first command line argument // 2. Construct inverted index from given file // 3. Read query from standard input // 4. Process query and output the top-3 records (ordered by count); if less // than 3 hits, output less; if no hits, say that no hits // 5. Optionally highlight query words // 6. Repeat from 3 // void main