Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_summary_lex_rank(self,num_sentence):
from sumy.parsers.plaintext import PlaintextParser # 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
try:
parser = HtmlParser.from_url(self.url, Tokenizer("english"))
except:
try:
parser = PlaintextParser.from_string(self.body, Tokenizer("english"))
except Exception as e:
raise(e)
summarizer = LexRankSummarizer()
summary = summarizer(parser.document, num_sentence)
out=''
for sentence in summary:
out+= str(sentence)
return out
def get_summary(self,num_sentence):
out = ''
try:
try:
parser = HtmlParser.from_url(self.url, Tokenizer("english"))
except:
try:
parser = PlaintextParser.from_string(self.body, Tokenizer("english"))
except Exception as e:
raise(e)
stemmer = Stemmer('english')
summarizer = Summarizer(stemmer)
summarizer.stop_words = get_stop_words('english')
for sentence in summarizer(parser.document, num_sentence):
out+=str(sentence)
except:
return self.body
return out