r - 如何为 R 主题模型正确编码 UTF-8 txt 文件
问题描述
解决方案
我找到了一种解决方法,似乎可以在您提供的 2 个示例文件上正常工作。您首先需要做的是NFKD(兼容性分解)。这将“fi”正字法连字拆分为 f 和 i。幸运的是 stringi 包可以处理这个问题。因此,在进行所有特殊文本清理之前,您需要应用该功能stringi::stri_trans_nfkd
。您可以在较低步骤之后(或之前)的预处理步骤中执行此操作。
请阅读此功能的文档和参考资料。
library(tm)
docs<- VCorpus(DirSource(directory = inputdir, encoding ="UTF-8"))
#Preprocessing
docs <-tm_map(docs,content_transformer(tolower))
# use stringi to fix all the orthographic ligature issues
docs <- tm_map(docs, content_transformer(stringi::stri_trans_nfkd))
toSpace <- content_transformer(function(x, pattern) (gsub(pattern, " ", x)))
# add following line as well to remove special quotes.
# this uses a replace from textclean to replace the weird quotes
# which later get removed with removePunctuation
docs <- tm_map(docs, content_transformer(textclean::replace_curly_quote))
....
rest of process
.....
推荐阅读
- c++ - 如何将数据写入标准输入以供等待标准输入输入的单独线程使用?
- excel - 字符串在 InsertFile 中有效。包含相同字符串的变量不会。为什么?
- matlab - 将多边形的一组点压缩为一组较短的点
- .htaccess - 我可以使用重写来显示替代域吗?
- php - Silverstripe 3:我可以在 silverstripe 中为某些页面类型设置自定义错误页面吗?
- python - 步词字谜python
- c# - 如何在 C# 中更新级联选择字段
- reactjs - 如何在 redux 中链接操作
- javascript - 如何做到这一点,当我选择一个选项时,它将显示一个选项并隐藏另一个
- python - 对 python、列表/生成器对象感到困惑