I have this function that returns all the files in the folder after deleting the stop words from them, but the problem is that when I print the result of this function, only the content of the first file is printed, and I want to print all the files after deleting the stop words from them.
How can I solve the problem?
def remove_stop_word_from_files():
stop_words_list = get_stop_words()
dir_path = 'C:/Users/Super/Desktop/IR/homework/Lab4/corpus/corpus/'
save_dir = "C:/Users/Super/Desktop/IR/homework/Files_Without_SW/"
for document in os.listdir(dir_path):
with open(dir_path + document, "r") as reader:
save_file = open(save_dir + document, 'w')
text = reader.read()
text_tokens = word_tokenize(text)
tokens_without_sw = [word.replace(',', '').replace('.', '') for word in
text_tokens if (word not in stop_words_list)]
save_file.writelines(["%s " % item.replace(',', '').replace('.', '') for item in
tokens_without_sw])
return tokens_without_sw
print(remove_stop_word_from_files())