I am having an error in the following java method. pipeline <- javaMethod('createCoreNLP', 'edu.stanford.nlp.pipeline.StanfordCoreNLP', 'en') Error in javaMethod("createCoreNLP", "edu.stanford.nlp.pipeline.StanfordCoreNLP", : could not find function "javaMethod" Here is my codes: Sys.setenv(JAVA_HOME='C:\\Program Files\\Java\\jdk-18.0.1.1') library(rJava) library(coreNLP) options( java.parameters = "-Xmx6g" ) #Set up the environment for Java #Init Java #.jinit(classpath = c(file.path(Sys.getenv('HOME'), '/Downloads/stanford-corenlp-full-2018-02-27/stanford-corenlp-3.9.1.jar'), file.path(Sys.getenv('HOME'), '/Downloads/stanford-corenlp-full-2018-02-27/slf4j-simple.jar'), file.path(Sys.getenv('HOME'), '/Downloads/stanford-corenlp-full-2018-02-27/slf4j-api.jar')), boundaries = '- Xmx5120m') .jinit(classpath = c(file.path(Sys.getenv('HOME'), '~/IS 688/stanford-corenlp-4.4.0/stanford-corenlp-4.4.0.jar'), file.path(Sys.getenv('HOME'), '~/IS 688/stanford-corenlp-4.4.0/slf4j-simple.jar'), file.path(Sys.getenv('HOME'), '~/IS 688/stanford-corenlp-4.4.0/ slf4j-api.jar')), boundaries = '- Xmx6g') #initCoreNLP("~/IS688/stanford-corenlp-4.4.0/",mem = "6g",parameterFile="~/IS688/stanford-corenlp-4.4.0/corenlp.properties") #Create thesentiment analyzer sentimentAnalyzer <- function(doc){ #Create an empty list sentimentList <- list() #Create a CoreNLP pipeline pipeline <- javaMethod('createCoreNLP', 'edu.stanford.nlp.pipeline.StanfordCoreNLP', 'en') #Annotate the document annotation <- javaMethod('process', 'edu.stanford.nlp.util.CoreMap', pipeline, doc) #Get the sentiment of the first sentence sentiment <- javaMethod('get', 'edu.stanford.nlp.ling.CoreAnnotations$SentimentClass', annotation$get('sentences')[1]) #Add the sentiment to the list sentimentList$sentiment <- sentiment #Get the tokens of the first sentence tokens <- javaMethod('get', 'edu.stanford.nlp.ling.CoreAnnotations$TokensAnnotation', annotation$get('sentences')[1]) #Add the tokens to the list sentimentList$tokens <- tokens #Return the list return(sentimentList) }
I am having an error in the following java method.
pipeline <- javaMethod('createCoreNLP', 'edu.stanford.nlp.pipeline.StanfordCoreNLP', 'en')
Error in javaMethod("createCoreNLP", "edu.stanford.nlp.pipeline.StanfordCoreNLP", :
could not find function "javaMethod"
Here is my codes:
Sys.setenv(JAVA_HOME='C:\\Program Files\\Java\\jdk-18.0.1.1')
library(rJava)
library(coreNLP)
options( java.parameters = "-Xmx6g" )
#Set up the environment for Java
#Init Java
#.jinit(classpath = c(file.path(Sys.getenv('HOME'), '/Downloads/stanford-corenlp-full-2018-02-27/stanford-corenlp-3.9.1.jar'), file.path(Sys.getenv('HOME'), '/Downloads/stanford-corenlp-full-2018-02-27/slf4j-simple.jar'), file.path(Sys.getenv('HOME'), '/Downloads/stanford-corenlp-full-2018-02-27/slf4j-api.jar')), boundaries = '- Xmx5120m')
.jinit(classpath = c(file.path(Sys.getenv('HOME'), '~/IS 688/stanford-corenlp-4.4.0/stanford-corenlp-4.4.0.jar'), file.path(Sys.getenv('HOME'), '~/IS 688/stanford-corenlp-4.4.0/slf4j-simple.jar'), file.path(Sys.getenv('HOME'), '~/IS 688/stanford-corenlp-4.4.0/ slf4j-api.jar')), boundaries = '- Xmx6g')
#initCoreNLP("~/IS688/stanford-corenlp-4.4.0/",mem = "6g",parameterFile="~/IS688/stanford-corenlp-4.4.0/corenlp.properties")
#Create thesentiment analyzer
sentimentAnalyzer <- function(doc){
#Create an empty list
sentimentList <- list()
#Create a CoreNLP pipeline
pipeline <- javaMethod('createCoreNLP', 'edu.stanford.nlp.pipeline.StanfordCoreNLP', 'en')
#Annotate the document
annotation <- javaMethod('process', 'edu.stanford.nlp.util.CoreMap', pipeline, doc)
#Get the sentiment of the first sentence
sentiment <- javaMethod('get', 'edu.stanford.nlp.ling.CoreAnnotations$SentimentClass', annotation$get('sentences')[1])
#Add the sentiment to the list
sentimentList$sentiment <- sentiment
#Get the tokens of the first sentence
tokens <- javaMethod('get', 'edu.stanford.nlp.ling.CoreAnnotations$TokensAnnotation', annotation$get('sentences')[1])
#Add the tokens to the list
sentimentList$tokens <- tokens
#Return the list
return(sentimentList)
}
Step by step
Solved in 2 steps