创建 TermDocument 矩阵后无法将单个 digit/letter 视为术语
Not able to see single digit/letter as a term in after creating TermDocument Matrix
我在R中使用了TermDocument
矩阵,文档(字符串)也包括单字母单词。使用 TermDocument
矩阵后,术语不包括那些单字母单词,请建议我应该将哪个控件作为输入参数包含在内,以便在我的术语文档矩阵中包含单字母单词。`
默认情况下 min wordlength
是 3
。您需要将参数指定为 control
以覆盖默认值,请查看以下代码。
library(tm)
docs <- c("This is a text","When Will u start", "1 12 123")
corpus <- Corpus(VectorSource(docs))
as.matrix(DocumentTermMatrix(corpus)) #words with length < 3 ('a','u','1','12') are excluded
# Terms
#Docs 123 start text this when will
# 1 0 0 1 1 0 0
# 2 0 1 0 0 1 1
# 3 1 0 0 0 0 0
as.matrix(DocumentTermMatrix(corpus, control = list(wordLengths=c(1,Inf))))
# Terms
#Docs 1 12 123 a is start text this u when will
# 1 0 0 0 1 1 0 1 1 0 0 0
# 2 0 0 0 0 0 1 0 0 1 1 1
# 3 1 1 1 0 0 0 0 0 0 0 0
我在R中使用了TermDocument
矩阵,文档(字符串)也包括单字母单词。使用 TermDocument
矩阵后,术语不包括那些单字母单词,请建议我应该将哪个控件作为输入参数包含在内,以便在我的术语文档矩阵中包含单字母单词。`
默认情况下 min wordlength
是 3
。您需要将参数指定为 control
以覆盖默认值,请查看以下代码。
library(tm)
docs <- c("This is a text","When Will u start", "1 12 123")
corpus <- Corpus(VectorSource(docs))
as.matrix(DocumentTermMatrix(corpus)) #words with length < 3 ('a','u','1','12') are excluded
# Terms
#Docs 123 start text this when will
# 1 0 0 1 1 0 0
# 2 0 1 0 0 1 1
# 3 1 0 0 0 0 0
as.matrix(DocumentTermMatrix(corpus, control = list(wordLengths=c(1,Inf))))
# Terms
#Docs 1 12 123 a is start text this u when will
# 1 0 0 0 1 1 0 1 1 0 0 0
# 2 0 0 0 0 0 1 0 0 1 1 1
# 3 1 1 1 0 0 0 0 0 0 0 0