【问题标题】:Use multiple dictionaries using hunspell in R在 R 中使用 hunspell 使用多个字典
【发布时间】:2018-10-14 13:31:30
【问题描述】:

当我在 hunspell 中选择不同的字典时,我观察到了奇怪的行为。我希望用澳大利亚英语对我的文本进行拼写检查。但是当我选择“en_AU”字典时,我会收到其他没有意义的拼写错误。

> require(hunspell)
> hunspell("Couldn't be more delighted." , dict = "en_AU", ignore = dic_ignore)
[[1]]
[1] "Couldn"

> hunspell("Couldn't be more delighted." , dict = "en_US", ignore = dic_ignore)
[[1]]
character(0)

我不明白为什么 en_AU 字典会这样。

如何组合这两个字典? 我尝试将它们组合起来不起作用:

    #this doesn't work
    > reviews <-  reviews[, possible_errors_2 := hunspell(review_parsed, dict = c("en_US", "en_AU"), ignore = dic_ignore)]
Warning message:
In if (!file.exists(dict)) { :
  the condition has length > 1 and only the first element will be used

编辑:我想这涉及到两个嵌套问题:1)为什么第一个字典不能正常工作? “不能”在澳大利亚英语中有效 <: r>

【问题讨论】:

  • 您的组合示例有错字,应该是dict = c("en_AU", "en_US")。我还没有投票关闭,因为修复错字似乎确实使它起作用,但也给出了一个警告,表明你不应该将多个字典传递给函数 - 不确定向量是否传递给 dict 应该工作。
  • 这很愚蠢。我会编辑

标签: r dictionary hunspell spelling


【解决方案1】:

事实上,hunspell 不支持字典向量。您可以跟踪 get_dict 函数并添加支持 https://github.com/ropensci/hunspell/pull/37/commits/da358a972d29c4bd39cf39755fc013a931bf3aba 或者您可以将您的字典文件组合在一起。

trace(hunspell:::get_dict, edit = TRUE)
 found <- file.exists(dict)
 if(!all(found)){
   dict[!found] <- sapply(paste0(sub("\\.(dic|aff)$", "", dict[!found]), ".dic"), find_in_dicpath)
 }
 normalizePath(dict, mustWork = TRUE)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-22
    • 2019-04-15
    相关资源
    最近更新 更多