我无法在运行 High Sierra 的 Mac 上访问 R 中的 coreNLP
。我不确定问题出在哪里,但似乎每次我再次尝试让 coreNLP
工作时,我都会遇到不同的错误。我有 JDK 9.0.4。请在下面查看我的代码,了解我正在尝试做什么,以及阻止我的错误。
我之前的尝试是让 initCoreNLP()
运行并加载包的某些元素,但它会在其他元素上失败。当我随后尝试运行 annotateString()
时,它会抛出错误 Error Must initialize with 'int CoreNLP'!
。
我已经多次下载并重新下载 coreNLP
Java 存档,但仍然没有成功!查看图像,了解位于 /Library/Frameworks/R.framework/Versions/3.4/Resources/library/coreNLP
的我的 coreNLP
R 包文件夹的内容。
你知道我如何成功初始化coreNLP
吗?
dyn.load("/Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home/lib/server/libjvm.dylib")
library(NLP)
library(coreNLP)
> downloadCoreNLP()
trying URL 'http://nlp.stanford.edu/software//stanford-corenlp-full-2015-12-09.zip'
Content type 'application/zip' length 403157240 bytes (384.5 MB)
==================================================
downloaded 384.5 MB
> initCoreNLP()
[main] INFO edu.stanford.nlp.pipeline.StanfordCoreNLP - Searching for resource: StanfordCoreNLP.properties
Error in rJava::.jnew("edu.stanford.nlp.pipeline.StanfordCoreNLP", basename(path)) :
edu.stanford.nlp.io.RuntimeIOException: ERROR: cannot find properties file "StanfordCoreNLP.properties" in the classpath!
最佳答案
根据我们的讨论。
我的感觉是您的 Java/R 配置依赖性问题。因此,rJava
似乎依赖于所使用的 java
版本,而 coreNLP
依赖于 rJava
。
java <- rJava <- coreNLP
因此我们可以将dlynlib版本设置为1.8.X,卸载rJava,重新安装rJava,然后重新安装coreNLP。
在 RStudio 中设置特定版本的 java
dyn.load('/Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home/jre/lib/server/libjvm.dylib')
remove.packages("rJava")
install.packages("rJava")
ipak <- function(pkg){
new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
if (length(new.pkg))
install.packages(new.pkg, dependencies = TRUE)
sapply(pkg, require, character.only = TRUE)
}
# usage
packages <- c("NLP", "coreNLP", "rJava")
ipak(packages)
.jinit()
.jcall("java/lang/System","S","getProperty","java.version")
# run the follwoing command once
# downloadCoreNLP() # <- Takes a while...
initCoreNLP()
example(getSentiment)
sIn <- "Mother died today. Or, maybe, yesterday; I can't be sure."
annoObj <- annotateString(sIn)
关于java - 无法在 R 中初始化 CoreNLP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48495923/