text_plain_output_1.png
from flashtext import KeywordProcessor

from nltk.tokenize import sent_tokenize

import pke

import re

import re
ml_ftxt = re.sub('\\n', ' ', ml_ftxt)
ml_ftxt = ml_ftxt.translate(str.maketrans(' ', ' ', '!"#$%&\'()*+-/:;<=>?@[\\]^_`{|}~'))
ml_ftxt = re.sub('[A-Za-z0-9]*@[A-Za-z]*\\.?[A-Za-z0-9]*', '', ml_ftxt)

extractor = pke.unsupervised.TextRank()
extractor.load_document(input=ml_ftxt)
extractor.candidate_selection()
extractor.candidate_weighting()
keyphrases2 = extractor.get_n_best(n=9)

TextRank = []
for i, j in keyphrases2:
    TextRank.append(i)

from nltk.tokenize import sent_tokenize
from flashtext import KeywordProcessor
def tokenize_sentences(text):
    sentences = [sent_tokenize(text)]
    sentences = [y for x in sentences for y in x]
    sentences = [sentence.strip() for sentence in sentences if len(sentence) > 20]
    return sentences
def get_sentences_for_keyword(keywords, sentences):
    keyword_processor = KeywordProcessor()
    keyword_sentences = {}
    for word in keywords:
        keyword_sentences[word] = []
        keyword_processor.add_keyword(word)
    for sentence in sentences:
        keywords_found = keyword_processor.extract_keywords(sentence)
        for key in keywords_found:
            keyword_sentences[key].append(sentence)
    for key in keyword_sentences.keys():
        values = keyword_sentences[key]
        values = sorted(values, key=len, reverse=True)
        keyword_sentences[key] = values
    return keyword_sentences
sentences = tokenize_sentences(ml_ftxt)
keyword_sentence_mapping = get_sentences_for_keyword(TextRank, sentences)

sentences = []
for i, j in keyword_sentence_mapping.items():
    sentences.append(j[0])

for i in sentences:
    print(nlp(i))