def champion_list_creator(invertedIndex: InvertedIndex, docs, r): result = InvertedIndex.InvertedIndex() for i in range(len(invertedIndex.index_array)): word = invertedIndex.index_array[i].word arr = invertedIndex.index_array[i].doc_ids temp_res = [] for j in range(len(arr)): id_location = Document.documents_binary_search( docs, 0, len(docs) - 1, arr[j]) weight = WeightCalculator.weight_calculator_doc( word, docs, docs[id_location]) temp_res.append([arr[j], weight]) res = sorter(temp_res, r) index = InvertedIndex.Index(word) index.set_docs_id(res) result.index_array.append(index) return result
import InvertedIndex import InvertedIndexQuery i = InvertedIndex.Index() filename = '/home/mimi/Desktop/RI tp/D1.txt' file_to_index = open(filename).read() document_key = filename # index the document, using document_key as the document's # id. i.index(file_to_index, document_key) ''' filename = 'document2.txt' file_to_index = open(filename).read() document_key = filename i.index(file_to_index, document_key) search_results = InvertedIndexQuery.query('Python and spam', i) search_results.sort() cnt = 0 for document in search_results: cnt = cnt + 1 print '%d) %s' % (cnt, document[1]) '''