Пример #1
0
    def summarize(self):
        firsts = []
        middles = []
        ends = []
        for doc in self.documents:
            cur = doc.get_most_important_sentences()
            #get the first, middle and end best sentences
            firsts.append(cur[1][0])
            middles.append(cur[2][0])
            ends.append(cur[3][0])

        #find the best of each section in total
        best_first = textrank(firsts)[0]
        best_middle = textrank(middles)[0]
        best_end = textrank(ends)[0]

        self.summary = [
            # first section
            {
                'sentence': best_first.sentence,
                'from_article': self.urls[best_first.document]
            },
            # middle section
            {
                'sentence': best_middle.sentence,
                'from_article': self.urls[best_middle.document]
            },
            # end section
            {
                'sentence': best_end.sentence,
                'from_article': self.urls[best_end.document]
            }
        ]

        return best_first, best_middle, best_end
Пример #2
0
    def summarize(self):
        firsts = []
        middles = []
        ends = []
        for doc in self.documents:
            cur = doc.get_most_important_sentences()
            #get the first, middle and end best sentences
            firsts.append(cur[1][0])
            middles.append(cur[2][0])
            ends.append(cur[3][0])

        #find the best of each section in total
        best_first = textrank(firsts)[0]
        best_middle = textrank(middles)[0]
        best_end = textrank(ends)[0]

        self.summary = [
            # first section
            {
                'sentence': best_first.sentence,
                'from_article': self.urls[best_first.document]
            },
            # middle section
            {
                'sentence': best_middle.sentence,
                'from_article': self.urls[best_middle.document]
            },
            # end section
            {
                'sentence': best_end.sentence,
                'from_article': self.urls[best_end.document]
            }
        ]

        return best_first, best_middle, best_end
Пример #3
0
 def get_most_important_sentences(self):
     #find the single most important sentence in the first
     #paragraph
     ranked_sentences = textrank(self.text)
     best_first = self.get_best_sentence_in_set(self.begining, ranked_sentences)
     best_middle = self.get_best_sentence_in_set(self.middle, ranked_sentences)
     best_last = self.get_best_sentence_in_set(self.end, ranked_sentences)
     return ranked_sentences, best_first, best_middle, best_last
Пример #4
0
 def get_most_important_sentences(self):
     #find the single most important sentence in the first
     #paragraph
     ranked_sentences = textrank(self.text)
     best_first = self.get_best_sentence_in_set(self.begining,
                                                ranked_sentences)
     best_middle = self.get_best_sentence_in_set(self.middle,
                                                 ranked_sentences)
     best_last = self.get_best_sentence_in_set(self.end, ranked_sentences)
     return ranked_sentences, best_first, best_middle, best_last