首页 > 解决方案 > 使用 Java/R 接口进行文本挖掘

问题描述

我正在尝试使用 JRI 对我的文件进行文本挖掘,这是我第一次这样做。所以这是我的代码:

    Rengine rengine = new Rengine(new String[]{"--vanilla"}, false, null);
    // TODO Auto-generated method stub

    rengine.eval("library(\"tm\")");


    rengine.eval("filePath <- \"C:\\\\Users\\\\acer\\\\Desktop\\\\tp_ged\\\\doc1\\\\f1.txt\"");

    rengine.eval("text <- readLines(filePath)");

    rengine.eval("docs <- Corpus(VectorSource(text))");

     rengine.eval("docs <- tm_map(docs, content_transformer(tolower))");
     rengine.eval("docs <- tm_map(docs, removeNumbers)");
     rengine.eval("docs <- tm_map(docs, removeWords, stopwords(\"english\"))");
     rengine.eval("docs <- tm_map(docs, removePunctuation)");
     rengine.eval("docs <- tm_map(docs, stripWhitespace)");
     //String[] result = rengine.eval("docs<- Corpus(VectorSource(text))").asStringArray();
     System.out.println("---"+rengine.eval("inspect(docs)")));

但我得到null的结果是,我认为 tm 库没有加载或其他东西,正如我之前所说,这是我第一次这样做。

标签: javarfiletext-miningjri

解决方案


推荐阅读