def test_get_optimal_subset_by_percent_words(self): # takes about 1.2 seconds with open('sample_text.txt', encoding="utf8") as text_file: # Load text sample_text = str(text_file.read()) # Remove unwanted text in the essay. ie '(fr)' sample_text = sample_text.replace('(fr) ', '') # Load document class summarizer = Summarizer(text=sample_text) # Find summary with 25% words val, summary = summarizer.get_optimal_subset_by_percent_words(.25, ret_as="str") # Write out summary with open('output.txt', 'w+') as w_file: w_file.write(summary)
subj, text = body_from_website(copied_text.lower()) if text == '': if len(copied_text) > 100: text = copied_text subj = '' else: print(f'Invalid Input: {copied_text}') input('Press enter to continue...') sys.exit() else: print(f'Loading text from: {copied_text}') document = Summarizer(text) _, summary = document.get_optimal_subset_by_percent_words(.15, ret_as='str') # Generate response response_body = 'Title: ' + subj + '\n\n' if len(summary) != 0: response_body += summary else: response_body += 'Text Too Short' response_body += '\n\n--------------\n\n' print(response_body) loc = 'output.txt' with open(loc, "w") as output_file: output_file.write(str(response_body))