I am trying to save the output summarized text to a text file without manually copying the output, I have a function called generate_summary(), this is the one I'm trying to save the output from. this is my code, I think I want to save the list in the function:
def generate_summary(file_name, top_n=7):
stop_words = stopwords.words('english')
summarizaed_text = []
print("original Text:\n")
sentences = read_article("AI.txt")
sentence_similarity_martix = build_similarity_matrix(sentences, stop_words)
sentence_similarity_graph = nx.from_numpy_array(sentence_similarity_martix)
scores = nx.pagerank(sentence_similarity_graph)
ranked_sentence = sorted(((scores[i],s) for i,s in enumerate(sentences)), reverse=True)
print("\nIndexes of top ranked_sentence order:\n \n ", ranked_sentence)
for i in range(top_n):
summarizaed_text.append(" ".join(ranked_sentence[i][1]))
print("\nSummarized Text:\n \n", ". ".join(summarizaed_text))
I tried running the below code but it didn't work, can someone please help me? thank you in advance:
with open('Summaty.txt', 'w') as f:
generate_summary(f)