无法在R中初始化CoreNLP [英] Cannot Initialize CoreNLP in R

查看:779
本文介绍了无法在R中初始化CoreNLP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在运行High Sierra的Mac上的R中访问 coreNLP 。我不确定问题是什么,但似乎每次我再次尝试让 coreNLP 工作时,我都面临着不同的错误。我有JDK 9.0.4。请参阅下面的代码,了解我正在尝试做什么,以及阻止我的错误。

I am unable to access coreNLP in R on a Mac running High Sierra. I am uncertain what the problem is, but it seems that every time I try again to get coreNLP to work, I am faced with a different error. I have JDK 9.0.4. Please see my code below for what I am attempting to do, and the error that stops me.

我以前的尝试我能够获得 initCoreNLP ()运行并加载包的某些元素,但在其他元素上会失败。当我然后尝试运行 annotateString()时,它会抛出错误错误必须用'int CoreNLP'初始化!

My previous attempt I was able to get initCoreNLP() to run and load some elements of the packages, but it would fail on others. When I then attempted to run annotateString(), it would throw the error Error Must initialize with 'int CoreNLP'!.

我已多次下载并重新下载 coreNLP Java档案,但仍然没有运气!参见位于 /Library/Frameworks/R.framework/Versions/3.4/Resources/library/coreNLP <我 coreNLP ř包文件夹的内容图像/ code>。

I have downloaded and re-downloaded the coreNLP Java archive many times and still no luck! See image for contents of my coreNLP R package folder located at /Library/Frameworks/R.framework/Versions/3.4/Resources/library/coreNLP.

您知道我如何成功初始化 coreNLP

Do you know how I can successfully initialize 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

My sense is your Java / R configuration dependency issue. Thus, it appears that rJava is dependent on the version of java used and coreNLP is dependent on rJava.

java <- rJava <- coreNLP

因此我们可以将dlynlib版本设置为1.8.X,卸载rJava,重新安装rJava然后重新安装coreNLP。

thus we can set the dlynlib version to 1.8.X, uninstall rJava, reinstall rJava then reinstall coreNLP.

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)

这篇关于无法在R中初始化CoreNLP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆