regex - R 正则表达式错误 :java. lang.NoSuchMethodException 中的 Mallet:给定参数没有合适的方法

标签 regex r rjava topic-modeling mallet

我一直在学习如何在 R 中使用 mallet 创建主题模型的教程。我的文本文件每行 1 个句子。它看起来像这样,大约有 50 个句子。

Thank you again and have a good day :).
This is an apple.
This is awesome!
LOL!
i need 2.
.
.
. 

这是我的代码:

Sys.setenv(NOAWT=TRUE)

#setup the workspace
# Set working directory
dir<-"/Users/jxn"
Dir <- "~/Desktop/Chat/malletR/text" # adjust to suit
require(mallet)
documents1 <- mallet.read.dir(Dir)
View(documents1)
stoplist1<-mallet.read.dir("~/Desktop/Chat/malletR/stoplists")
View(stoplist1)
**mallet.instances <- mallet.import(documents1$id, documents1$text, "~/Desktop/Chat/malletR/stoplists/en.txt", token.regexp ="\\p{L}[\\p{L}\\p{P}]+\\p{L}")**

除了最后一行代码,一切正常

**`**mallet.instances <- mallet.import(documents1$id, documents1$text, "~/Desktop/Chat/malletR/stoplists/en.txt", token.regexp ="\\p{L}[\\p{L}\\p{P}]+\\p{L}")**`**

我一直收到这个错误:

Error in .jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod", cl,  : 
  java.lang.NoSuchMethodException: No suitable method for the given parameters

根据包,函数应该是这样的:

mallet.instances <- mallet.import(documents$id, documents$text, "en.txt",
                    token.regexp = "\\p{L}[\\p{L}\\p{P}]+\\p{L}")

我相信它与 token.regexp 参数有关
documents1 <- mallet.read.dir(Dir)工作正常,这意味着提供给 mallet.instances 的前 3 个参数是正确的。

这是我从中学习教程的 git 存储库的链接。 https://github.com/shawngraham/R/blob/master/topicmodel.R

任何帮助将不胜感激。

谢谢, J

最佳答案

我怀疑问题出在您的文本文件上。我遇到了同样的错误并使用 as.character() 解决了它功能如下:

mallet.instances <- mallet.import(as.character(documents$id), as.character(documents$text), "en.txt", FALSE, token.regexp="\\p{L}[\\p{L}\\p{P}]+\\p{L}")

关于regex - R 正则表达式错误 :java. lang.NoSuchMethodException 中的 Mallet:给定参数没有合适的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22878215/

相关文章:

java - 我的正则表达式模式不起作用

regex - R中的字母数字正则表达式

r - JRI 可以访问 Vista 上用户安装的软件包吗?

java - 使用 Java、R 和 JavaGD 绘制多个图形时出现问题?

r - 在 r (i.graph) 中创建一个有限制的关联矩阵

r - 在 centos(64 位)上安装 rJava。找不到 lpcre、llzma

regex - 使用 stringr 从 R 中的文本字符串中提取一个或多个单词

ruby - 如何用不在引号中的冒号分隔字符串

python - 用于反转字符串中单词顺序的正则表达式

r - 如何使用dplyr从R中数据框中的多列中减去一列