def test_cut_sentences(self): text = '''江西省上饶市信州区人民法院 刑事判决书 (2016)赣1102刑初274号 公诉机关 上饶市信州区人民检察院。 被告人曾榴仙,女,1954年11月22日出生于江西省上饶市信州区, 汉族,文盲,无业,家住上饶市信州区,因涉嫌过失致人死亡罪,2016年4月27日被上饶市公 安局信州区分局刑事拘留,2016年6月1日被执行逮捕。辩护人毛巧云,江西盛义律师事务所 律师。 上饶市信州区人民检察院以饶信检公诉刑诉[2016]260号起诉书指控被告人曾榴仙犯 过失致人死亡罪,于2016年8月22日向本院提起公诉。''' text = re.sub('\\n| ', '', text) sentences = list(utils.cut_sentences(text)) self.assertEqual(len(sentences), 4)
def summarize(self, text, n): text = text.replace('\n', '') text = text.replace('\r', '') text = utils.as_text(text) tokens = utils.cut_sentences(text) sentences, sents = utils.cut_filter_words(tokens, self.__stop_words, self.__use_stopword) graph = self.create_graph(sents) scores = utils.weight_map_rank(graph, self.__max_iter, self.__tol) sent_selected = nlargest(n, zip(scores, count())) sent_index = [] for i in range(n): sent_index.append(sent_selected[i][1]) return [sentences[i] for i in sent_index]
def keywords(self, text, n): text = text.replace('\n', '') text = text.replace('\r', '') text = utils.as_text(text) tokens = utils.cut_sentences(text) sentences, sents = utils.psegcut_filter_words(tokens, self.__stop_words, self.__use_stopword) word_index, index_word, words_number = self.build_vocab(sents) graph = self.create_graph(sents, words_number, word_index, window=self.__window) scores = utils.weight_map_rank(graph, max_iter=self.__max_iter, tol=self.__tol) sent_selected = nlargest(n, zip(scores, count())) sent_index = [] for i in range(n): sent_index.append(sent_selected[i][1]) return [index_word[i] for i in sent_index]