Quanteda:如何删除我自己的单词列表

Quanteda:如何删除我自己的单词列表,第1张

概述由于在quanteda中没有现成的波兰语停用词,我想使用自己的列表.我把它作为一个由空格分隔的列表在文本文件中.如果需要,我还可以准备一个由新行分隔的列表. 如何从语料库中删除自定义的长字停用词列表? 堵塞之后怎么办? 我尝试过创建各种格式,转换为字符串向量 stopwordsPL <- as.character(readtext("polish.stopwords.txt",encoding = 由于在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)

我也尝试在语法中使用这样的单词向量

mystemMat <-  dfm(    mycorpus,remove = as.vector(stopwordsPL),stem = FALSE,remove_punct = TRUE,ngrams=c(1,3)  )dfm_trim(mystemMat,sparsity = stopwordsPL)

要么

mystemMat <- dfm_remove(mystemMat,features = as.data.frame(stopwordsPL))

什么都行不通.我的词汇出现在语料库和分析中.应用自定义停用词的正确方法/语法应该是什么?

解决方法 假设你的polish.stopwords.txt类似于 this,那么你应该可以通过这种方式轻松地从你的语料库中删除它们:

stopwordsPL <- readlines("polish.stopwords.txt",enCoding = "UTF-8")dfm(mycorpus,remove = stopwordsPL,3))

使用readtext的解决方案无法正常工作,因为它将整个文件作为一个文档读入.要获得单个单词,您需要对其进行标记并将标记强制转换为字符.可能readlines()更容易.

无需从stopwordsPL创建字典,因为删除应采用字符向量.此外,我担心还没有实施波兰干扰器.

目前(v0.9.9-65)dfm()中的特征删除并没有消除形成双字母的停止词.要覆盖它,请尝试:

# form the tokens,removing punctuationmytoks <- tokens(mycorpus,remove_punct = TRUE)# remove the Polish stopwords,leave padsmytoks <- 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 ngramsmytoks <- tokens_ngrams(mytoks,n = c(1,3))# construct the dfmdfm(mytoks)
总结

以上是内存溢出为你收集整理的Quanteda:如何删除我自己的单词列表全部内容,希望文章能够帮你解决Quanteda:如何删除我自己的单词列表所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1046500.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存