Skip to content

Instantly share code, notes, and snippets.

@philgooch
Forked from lastlegion/lexrank.py
Created June 21, 2017 12:52
Show Gist options
  • Save philgooch/52dc5061da710787f2a7d4ee19b62fba to your computer and use it in GitHub Desktop.
Save philgooch/52dc5061da710787f2a7d4ee19b62fba to your computer and use it in GitHub Desktop.
LexRank summarization in python using sumy
#Import library essentials
from sumy.parsers.plaintext import PlaintextParser #We're choosing a plaintext parser here, other parsers available for HTML etc.
from sumy.nlp.tokenizers import Tokenizer
from sumy.summarizers.lex_rank import LexRankSummarizer #We're choosing Lexrank, other algorithms are also built in
file = "plain_text.txt" #name of the plain-text file
parser = PlaintextParser.from_file(file, Tokenizer("english"))
summarizer = LexRankSummarizer()
summary = summarizer(parser.document, 5) #Summarize the document with 5 sentences
for sentence in summary:
print sentence
@vaishnavijha
Copy link

what if we need to return this summary to another fn instead of printing here

@philgooch
Copy link
Author

Hi @vaishnavijha I forked the repo from lastlegion/lexrank.py 3 years ago but haven't looked at the code since then, it might be better to ask the original author of the repo, see https://gist.github.com/lastlegion/dd7f11aada4673dfbb4b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment