python参考文献库_Python lexrank包_程序模块 - PyPI - Python中文网

fromlexrankimportSTOPWORDS,LexRankfrompathimportPathdocuments=[]documents_dir=Path('bbc/politics')forfile_pathindocuments_dir.files('*.txt'):withfile_path.open(mode='rt',encoding='utf-8')asfp:documents.append(fp.readlines())lxr=LexRank(documents,stopwords=STOPWORDS['en'])sentences=['One of David Cameron\'s closest friends and Conservative allies, ''George Osborne rose rapidly after becoming MP for Tatton in 2001.','Michael Howard promoted him from shadow chief secretary to the ''Treasury to shadow chancellor in May 2005, at the age of 34.','Mr Osborne took a key role in the election campaign and has been at ''the forefront of the debate on how to deal with the recession and ''the UK\'s spending deficit.','Even before Mr Cameron became leader the two were being likened to ''Labour\'s Blair/Brown duo. The two have emulated them by becoming ''prime minister and chancellor, but will want to avoid the spats.','Before entering Parliament, he was a special adviser in the ''agriculture department when the Tories were in government and later ''served as political secretary to William Hague.','The BBC understands that as chancellor, Mr Osborne, along with the ''Treasury will retain responsibility for overseeing banks and ''financial regulation.','Mr Osborne said the coalition government was planning to change the ''tax system\"to make it fairer for people on low and middle ''incomes\", and undertake\"long-term structural reform\"of the ''banking sector, education and the welfare state.',]# get summary with classical LexRank algorithmsummary=lxr.get_summary(sentences,summary_size=2,threshold=.1)print(summary)# ['Mr Osborne said the coalition government was planning to change the tax '# 'system "to make it fairer for people on low and middle incomes", and '# 'undertake "long-term structural reform" of the banking sector, education and '# 'the welfare state.',# 'The BBC understands that as chancellor, Mr Osborne, along with the Treasury '# 'will retain responsibility for overseeing banks and financial regulation.']# get summary with continuous LexRanksummary_cont=lxr.get_summary(sentences,threshold=None)print(summary_cont)# ['The BBC understands that as chancellor, Mr Osborne, along with the Treasury '# 'will retain responsibility for overseeing banks and financial regulation.']# get LexRank scores for sentences# 'fast_power_method' speeds up the calculation, but requires more RAMscores_cont=lxr.rank_sentences(sentences,threshold=None,fast_power_method=False,)print(scores_cont)# [1.0896493024505858,# 0.9010711968859021,# 1.1139166497016315,# 0.8279523250808547,# 0.8112028559566362,# 1.185228912485382,# 1.0709787574388283]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值