我想比较两个文本的相似性,因此我需要一个简单的函数来清楚地按时间顺序列出两个文本中出现的单词和短语.这些单词/句子应突出显示或加下划线以便更好地显示
在@joris Meys想法的基础上,我添加了一个数组,将文本分成句子和从属句子.
这是它的样子:
textparts <- function (text){
textparts <- c("\\,", "\\.")
i <- 1
while(i<=length(textparts)){
text <- unlist(strsplit(text, textparts[i]))
i <- i+1
}
return (text)
}
textparts1 <- textparts("This is a complete sentence, whereas this is a dependent clause. This thing works.")
textparts2 <- textparts("This could be a sentence, whereas this is a dependent clause. Plagiarism is not cool. This thing works.")
commonWords <- intersect(textparts1, textparts2)
commonWords <- paste("\\<(",commonWords,")\\>",sep="")
for(x in commonWords){
textparts1 <- gsub(x, "\\1*", textparts1,ignore.case=TRUE)
textparts2 <- …Run Code Online (Sandbox Code Playgroud) 我是R的新手,我需要建议在R中绘制一个如下所示的数据帧:
V1 V2 V3 V4
1 Mazda Toyota Peugeot
Car1.txt 0,507778837 0,19834711 0,146892655
Car2.txt 0,908717802 0,64214047 0,396508728
Run Code Online (Sandbox Code Playgroud)
我想在一个图中绘制这个数据帧(实际上有7列和95行),其中v2,v3,v4代表一条不同颜色的线,并命名为汽车名称,V1作为x-的标签轴,而y轴在[0,1]范围内.
我真的不知道如何做到这一点,所以我非常感谢任何建议