我正在使用Textrank方法解释这里来获得文本的摘要。是否有一种方法来绘制textrank_sentences的输出,就像将所有textrank_ids连接在一起的网络一样?
library(textrank)
data(joboffer)
library(udpipe)
tagger <- udpipe_load_model(tagger$file_model)
joboffer <- udpipe_annotate(tagger, job_rawtxt)
joboffer <- as.data.frame(joboffer)
joboffer$textrank_id <- unique_identifier(joboffer, c("doc_id","paragraph_id", "sentence_id"))
sentences <- unique(joboffer[, c("textrank_id", "sentence")])
terminology <- subset(joboffer, upos %in% c("NOUN", "ADJ"))
terminology <- terminology[, c("textrank_id", "lemma")]
tr <- textrank_sentences(data = sentences, terminology = terminology)发布于 2022-06-10 00:45:21
这个问题相当古老,但它是一个很好的问题,值得回答。
是的!textrank返回您需要的所有信息。只需查看str(tr)的输出即可。它的部分内容是:
$ sentences_dist:Classes ‘data.table’ and 'data.frame': 666 obs. of 3 variables:
..$ textrank_id_1: int [1:666] 1 1 1 1 1 1 1 1 1 1 ...
..$ textrank_id_2: int [1:666] 2 3 4 5 6 7 8 9 10 11 ...
..$ weight : num [1:666] 0.1429 0.4167 0 0.0625 0 ...这给出了哪些句子是以下三角矩阵的形式连接的。如果两个句子的连接权重大于零,则两句话是相互关联的。要将图形可视化,请使用非零权重作为编辑人员,并构建图表。
Links = which(tr$sentences_dist$weight > 0)
EdgeList = cbind(tr$sentences_dist$textrank_id_1[Links],
tr$sentences_dist$textrank_id_2[Links])
library(igraph)
SGraph1 = graph_from_edgelist(EdgeList, directed=FALSE)
set.seed(42)
plot(SGraph1)

我们看到,11个节点(句子)没有连接到任何其他节点。例如,第15和36句
tr$sentences$sentence[c(36,15)]
[1] "Contact:"
[2] "Integration of the models into the existing architecture."但其他节点确实连接起来,例如节点1连接到节点2。
tr$sentences$sentence[c(1,2)]
[1] "Statistical expert / data scientist / analytical developer"
[2] "BNOSAC (Belgium Network of Open Source Analytical Consultants),
is a Belgium consultancy company specialized in data analysis and
statistical consultancy using open source tools."因为这些句子共有“统计”、“数据”和“分析”等(重要的)词。
单点节点在图中占据了很大的空间,使得其他节点比较拥挤。因此,我也将显示那些删除的图表。
which(degree(SGraph1) == 0)
[1] 4 7 15 20 21 23 25 26 29 30 36
SGraph2 = delete.vertices(SGraph1, which(degree(SGraph1) == 0))
set.seed(42)
plot(SGraph2)

这显示了句子之间的关系更好,但我希望你能找到一个更好的布局图,更好地显示关系。然而,这并不是问题的重点,我让你们来使这个图形变得漂亮。
https://stackoverflow.com/questions/56702374
复制相似问题