def buildIndex(self, name): indexer = Indexer(name) documentsFileNames = os.listdir(documentsPath) for docId, documentFileName in enumerate(documentsFileNames): with open(documentsPath + '/' + documentFileName, 'r+') as fileHandler: content = fileHandler.read() tokens = tokenProcessor.preprocess(nltk.word_tokenize(content)) for token in tokens: indexer.add_word_to_document(token, docId + 1) print(indexer) indexer.save_indexer_to_disk()