本文整理匯總了Python中extractor.Extractor.getContext方法的典型用法代碼示例。如果您正苦於以下問題:Python Extractor.getContext方法的具體用法?Python Extractor.getContext怎麽用?Python Extractor.getContext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類extractor.Extractor
的用法示例。
在下文中一共展示了Extractor.getContext方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: tokenize2
# 需要導入模塊: from extractor import Extractor [as 別名]
# 或者: from extractor.Extractor import getContext [as 別名]
def tokenize2(text):
for k in Tokenize(text):
if len(k) > 1:
yield k
def key_rank(text, topk=18):
sents = list(cut_sentence(text))
docs = [list(tokenize2(sent)) for sent in sents]
keyword_rank = textrank.KeywordTextRank(docs)
keyword_rank.solve()
keys = [w for w in keyword_rank.top_index(topk)]
return keys
def sum_rank(text):
sents = list(cut_sentence(text))
docs = [list(tokenize2(sent)) for sent in sents]
sim_res = bm25_weights(docs)
rank = textrank.TextRank(sim_res)
rank.solve()
top_n_summary = []
for index in sorted(rank.top_index(3)):
top_n_summary.append(sents[index])
return u'。 '.join(top_n_summary).replace('\r','').replace('\n','')+u'。'
if __name__ == '__main__':
ext = Extractor(url="http://news.cctv.com/2018/03/14/ARTIae5nIxMetJzk20Gk8Vw7180314.shtml",blockSize=5, image=False)
content = ext.getContext()
print(repr(key_rank(content)).decode('unicode-escape'))
print(sum_rank(content))