библиотека quanteda
работает достаточно хорошо в этом случае.Здесь ниже я привожу пример:
library(tibble)
library(quanteda)
df<- data_frame(text = c("when uploading objective file bugzilla se",
"spelling mistake docs section searching fo",
"editparams cgi won save updates iis instal",
"editparams cgi won save updates",
"rfe unsubscribe from bug you reported",
"unsubscribe from bug you reported"))
DocTerm <- quanteda::dfm(df$text)
textstat_simil(DocTerm, margin="documents", method = "cosine")
text1 text2 text3 text4 text5
text2 0.0000000
text3 0.0000000 0.0000000
text4 0.0000000 0.0000000 0.8451543
text5 0.0000000 0.0000000 0.0000000 0.0000000
text6 0.0000000 0.0000000 0.0000000 0.0000000 0.9128709
textstat_simil(DocTerm, margin="documents", method = "cosine")
Если кто-то хочет установить его на определенную сумму и посмотреть, какие из них похожи на определенное число (в этом 0,9), можно сделать следующее:
mycosinesim<-textstat_simil(DocTerm, margin="documents", method = "cosine")
myMatcosine<-as.data.frame(as.matrix(mycosinesim))
higherthan90<-as.data.frame(which(myMatcosine>0.9,arr.ind = T, useNames = T))
higherthan90[which(higherthan90$row !=higherthan90$col),]
row col
text6 6 5
text5.1 5 6
Теперь вы можете решить, удалять ли 5 или 6 как текст, поскольку они действительно похожи