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)
}
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)