Jac*_*ski 5 r text-mining quanteda
由于在quanteda中没有现成的波兰语停用词,我想使用自己的列表.我把它作为一个由空格分隔的列表在文本文件中.如果需要,我还可以准备一个由新行分隔的列表.
如何从语料库中删除自定义的长字停用词列表?堵塞之后怎么办?
我尝试过创建各种格式,转换为字符串向量
stopwordsPL <- as.character(readtext("polish.stopwords.txt",encoding = "UTF-8"))
stopwordsPL <- read.txt("polish.stopwords.txt",encoding = "UTF-8",stringsAsFactors = F))
stopwordsPL <- dictionary(stopwordsPL)
Run Code Online (Sandbox Code Playgroud)
我也尝试在语法中使用这样的单词向量
myStemMat <-
dfm(
mycorpus,
remove = as.vector(stopwordsPL),
stem = FALSE,
remove_punct = TRUE,
ngrams=c(1,3)
)
dfm_trim(myStemMat, sparsity = stopwordsPL)
Run Code Online (Sandbox Code Playgroud)
要么
myStemMat <- dfm_remove(myStemMat,features = as.data.frame(stopwordsPL))
Run Code Online (Sandbox Code Playgroud)
什么都行不通.我的词汇出现在语料库和分析中.应用自定义停用词的正确方法/语法应该是什么?
假设你polish.stopwords.txt是喜欢这个,那么你应该能够从你的阴茎很容易通过这种方式将其删除:
stopwordsPL <- readLines("polish.stopwords.txt", encoding = "UTF-8")
dfm(mycorpus,
remove = stopwordsPL,
stem = FALSE,
remove_punct = TRUE,
ngrams=c(1,3))
Run Code Online (Sandbox Code Playgroud)
使用readtext的解决方案无法正常工作,因为它将整个文件作为一个文档读入.为了获得个人的话,你需要tokenise它和令牌强制字符.可能readLines()更容易.
无需从stopwordsPL任何一个创建字典,因为remove应该采用字符向量.此外,我担心还没有实施波兰干扰器.
目前(v0.9.9-65)中的特征删除dfm()并没有摆脱形成双字母的停止词.要覆盖它,请尝试:
# form the tokens, removing punctuation
mytoks <- tokens(mycorpus, remove_punct = TRUE)
# remove the Polish stopwords, leave pads
mytoks <- tokens_remove(mytoks, stopwordsPL, padding = TRUE)
## can't do this next one since no Polish stemmer in
## SnowballC::getStemLanguages()
# mytoks <- tokens_wordstem(mytoks, language = "polish")
# form the ngrams
mytoks <- tokens_ngrams(mytoks, n = c(1, 3))
# construct the dfm
dfm(mytoks)
Run Code Online (Sandbox Code Playgroud)