我使用R language
的帮助我有很长的文本文件我想用至少10到20行或小句子来总结文本。
如何使用R language
至少10行汇总文本?
答案 0 :(得分:4)
您可以尝试此操作(来自LSAfun包):
genericSummary(D,k=1)
其中' D'指定您的文字文件和' k'摘要中使用的句子数。 (包装文档中显示了进一步的修改)。
了解更多信息: http://search.r-project.org/library/LSAfun/html/genericSummary.html
答案 1 :(得分:1)
有一个名为lexRankr的软件包,它以与Reddit / u / autotldr bot总结文章相同的方式汇总文本。 This article对如何使用它进行了全面的演练,但这只是一个简单的示例,因此您可以在R中自行测试:
#load needed packages
library(xml2)
library(rvest)
library(lexRankr)
#url to scrape
monsanto_url = "https://www.theguardian.com/environment/2017/sep/28/monsanto-banned-from-european-parliament"
#read page html
page = xml2::read_html(monsanto_url)
#extract text from page html using selector
page_text = rvest::html_text(rvest::html_nodes(page, ".js-article__body p"))
#perform lexrank for top 3 sentences
top_3 = lexRankr::lexRank(page_text,
#only 1 article; repeat same docid for all of input vector
docId = rep(1, length(page_text)),
#return 3 sentences to mimick /u/autotldr's output
n = 3,
continuous = TRUE)
#reorder the top 3 sentences to be in order of appearance in article
order_of_appearance = order(as.integer(gsub("_","",top_3$sentenceId)))
#extract sentences in order of appearance
ordered_top_3 = top_3[order_of_appearance, "sentence"]
> ordered_top_3
[1] "Monsanto lobbyists have been banned from entering the European parliament after the multinational refused to attend a parliamentary hearing into allegations of regulatory interference."
[2] "Monsanto officials will now be unable to meet MEPs, attend committee meetings or use digital resources on parliament premises in Brussels or Strasbourg."
[3] "A Monsanto letter to MEPs seen by the Guardian said that the European parliament was not “an appropriate forum” for discussion on the issues involved."