2

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.

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'!.

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.

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!

Contents of coreNLP R Package folder

tsouchlarakis
  • 1,499
  • 3
  • 23
  • 44
  • Please see the following stack overflow answer. This worked for me. https://stackoverflow.com/questions/34716207/installing-corenlp-in-r – Technophobe01 Feb 03 '18 at 01:21
  • Thank you for your response. I'm confused about the version of Java that is necessary. I am on a Mac, so my solution I believe is a bit different from that answer, but I might be wrong. I have both `jdk-9.0.4.jdk` and `jdk1.8.0_162.jdk`. That answer says to have Java 8. When I go to download Java 8 from [this link](http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html), it fails because I have a more up-to-date version of Java (Java 9). Is "Java 1.8" already "Java 8"? Thanks for your help. I am very confused as I know nothing about Java but need it to work! – tsouchlarakis Feb 04 '18 at 00:54
  • 1.8 is Java 8, yes – RolandASc Feb 04 '18 at 12:54
  • Followup question would be, do you know where `libjvm.so` is located on the mac installation of Java 8? I'm unable to follow the answer entirely because I can't follow the Ubuntu path `/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so`. – tsouchlarakis Feb 04 '18 at 19:28

1 Answers1

1

Per our discussion.

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

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

Setup a particular version of java in RStudio

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)
Technophobe01
  • 8,212
  • 3
  • 32
  • 59
  • Following your code, when I run `initCoreNLP()` it halts at this error `Error in rJava::.jnew("edu.stanford.nlp.pipeline.StanfordCoreNLP", basename(path)) : edu.stanford.nlp.util.ReflectionLoading$ReflectionLoadingException: Error creating edu.stanford.nlp.time.TimeExpressionExtractorImpl` – tsouchlarakis Feb 04 '18 at 19:19
  • I notice that you're running `9.0.1`. My outputs for those `system()` commands are `javac 9.0.4` and `java version "9.0.4" Java(TM) SE Runtime Environment (build 9.0.4+11) Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)`, respectively. Would you recommend uninstalling 9.0.4 and installing 9.0.1, or should it not matter? I am able to run `example(getSentiment)` successfully, but when I try to run another function like `annotateString()`, I get the error `Must initilize with 'initCoreNLP'!`. Any idea what's causing this? – tsouchlarakis Feb 04 '18 at 19:22
  • I reinstalled `rJava` from source and tried initializing `coreNLP`, and I'm getting the same error as before! – tsouchlarakis Feb 04 '18 at 19:36
  • Would you recommend completely uninstalling all necessary elements and trying again? coreNLP, rJava, devtools, Java 9.0.4, ...? I have devtools installed, but I do not have xcode, and I am not sure about gcc or fortran – tsouchlarakis Feb 04 '18 at 19:37
  • Output after I run `library(rJava)` followed by `.jinit()` followed by `.jcall(...)` --> `[1] "9.0.4"` – tsouchlarakis Feb 04 '18 at 19:44
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/164504/discussion-between-technophobe01-and-tsouchlarakis). – Technophobe01 Feb 04 '18 at 19:46
  • 1
    Thank you very much. The problem for any future solution-seekers was pointing to the correct version of Java using `dyn.load()` BEFORE loading `rJava`. So at the top of your script `dyn.load(...); library(rJava); library(coreNLP)` – tsouchlarakis Feb 04 '18 at 21:37