我一直在学习如何在 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/