Java Wrapper using rJava in R

I am using rJava to create a wrapper for a Java implementation in R. Currently, I want to create a wrapper for only two methods (put and search) of the GeneralizedSuffixTree class that are present in the specified Java implementation.

search()Class method signatureGeneralizedSuffixTree

public Collection<Integer> search(String word){
        return search(word, -1);
    }

Accordingly, I created the following wrapper method:

   callsearch <- function(key){
     hook2 <- .jnew("GeneralizedSuffixTree") # instance of class
     out <- .jcall(hook2,"Ljava/lang/Object","search",as.character(key), evalArray= FALSE, evalString = FALSE)
     return(out)
}

So, whenever I call the search method from rstudio with callsearch("abcdea"), I used the following error:

Error in .jcall(hook2, "Ljava/lang/Object", "search", as.character(key),  : 
  method search with signature (Ljava/lang/String;)Ljava/lang/Object not found

I think I'm doing the wrong casting for the Integer collection in R. Can I find out where I am doing the wrong thing?

The full shell package for development is in the link

+4
1

JNI. , JNI Ljava/util/Collection;

:

callsearch <- function(key){
     hook2 <- .jnew("GeneralizedSuffixTree") # instance of class
     out <- .jcall(hook2,"Ljava/util/Collection;","search",as.character(key), evalArray= FALSE, evalString = FALSE)
     return(out)
}

: java JNI

 javap -s <java-classname>

: javap -s java.util.Collections

+3

Source: https://habr.com/ru/post/1610451/


All Articles