Я пытаюсь удалить стоп-слово «the» из моего корпуса, однако не все экземпляры удаляются.
library(RCurl)
library(tm)
url <- "https://raw.githubusercontent.com/angerhang/statsTutorial/master/src/textMining/data/1.txt"
file1 <- getURL(url)
url <- "https://raw.githubusercontent.com/angerhang/statsTutorial/master/src/textMining/data/2.txt"
file2 <- getURL(url)
url <- "https://raw.githubusercontent.com/angerhang/statsTutorial/master/src/textMining/data/3.txt"
file3 <- getURL(url)
shakespeare <- VCorpus(VectorSource(c(file1,file2,file3)))
list<-inspect(
DocumentTermMatrix(shakespeare,list(dictionary = c("the","thee")))
)
shakespeare <- tm_map(shakespeare, stripWhitespace)
shakespeare <- tm_map(shakespeare, stemDocument)
shakespeare <- tm_map(shakespeare, removePunctuation)
tm_map(shakespeare, content_transformer(tolower))
#taken directly from tm documentation
shakespeare <- tm_map(shakespeare, removeWords, c(stopwords("english"),"the"))
list<-inspect(
DocumentTermMatrix(shakespeare,list(dictionary = c("the","thee")))
)
Первый вызов проверки показывает:
Terms
Docs the thee
1 11665 752
2 11198 660
3 4866 382
И второй, после очистки:
Terms
Docs the thee
1 1916 1298
2 1711 1140
3 760 740
Чего мне здесь не хватает в логи c из removeWords, что он будет игнорировать все эти экземпляры "the"?
EDIT
Я смог получить экземпляры "the" ниже 1000 путем небольшого изменения вызова и выполнения удаление слов вызывает самый первый шаг очистки:
shakespeare <- tm_map(shakespeare, removeWords, c(stopwords("english"),"the","The"))
Что приводит меня к:
Docs the thee
1 145 752
2 130 660
3 71 382
Тем не менее, я хотел бы знать, почему я не могу устранить их всех.