Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Java中使用RapidMiner文本处理插件-无法在代码中使用“Document”对象_Java_Groovy_Rapidminer - Fatal编程技术网

在Java中使用RapidMiner文本处理插件-无法在代码中使用“Document”对象

在Java中使用RapidMiner文本处理插件-无法在代码中使用“Document”对象,java,groovy,rapidminer,Java,Groovy,Rapidminer,我使用的是RapidMiner5。我想制作一个文本预处理模块,用于分类系统。我用这些步骤在RapidMiner中创建了一个流程 标记化 转换案例 堵塞 过滤停止字 生成n-gram 我想写一个脚本来纠正这些单词的拼写。因此,我使用了“Execute Script”操作符,并从这里编写了一个groovy脚本。这是我在RapidMiner的执行脚本操作符中编写的RapidMiner社区帮助编写的代码 Document doc=input[0] List<Token> newTokens

我使用的是RapidMiner5。我想制作一个文本预处理模块,用于分类系统。我用这些步骤在RapidMiner中创建了一个流程

标记化 转换案例 堵塞 过滤停止字 生成n-gram 我想写一个脚本来纠正这些单词的拼写。因此,我使用了“Execute Script”操作符,并从这里编写了一个groovy脚本。这是我在RapidMiner的执行脚本操作符中编写的RapidMiner社区帮助编写的代码

Document doc=input[0]

List<Token> newTokens = new LinkedList<Token>();
nWords=train("set2.txt")
for (Token token : doc.getTokenSequence()) {

    //String output=correct((String)token.getToken(),nWords) 
    println token.getToken();
    Token nToken = new Token(correct("garbge",nWords), token);
    newTokens.add(nToken);

}
doc.setTokenSequence(newTokens);
return doc;
这是拼写更正的代码。多亏了

我在调用edits方法时遇到字符串索引越界异常。 而且,我不知道如何调试它,因为rapidminer只是告诉我执行脚本操作符中有一个问题,没有说明是哪行脚本导致了这个问题

因此,我计划通过在Java中创建一个操作符来做同样的事情,正如这里提到的-

我所做的事情:

将RapidMiner Lib文件夹C:\Program files x86\Rapid-I\RapidMiner5\Lib中的所有jar文件包含到我的java项目的构建路径中

使用与上面给出的链接相同的指南开始编码

我的操作员的输入是一个文档com.rapidminer.operator.text.Document 就像剧本里说的那样

但是,我无法在此代码中使用此文档对象。你能告诉我为什么吗?文本处理jar位于哪里


对于使用插件JAR,我们是否应该在构建路径中添加一些其他位置?

我们是否必须猜测您得到的错误和您编写的代码?好的。我想我问的问题太多了。我正在重新表述这个问题。我在你发布的代码中看不到编辑方法?你也可以发布你得到的全部错误吗?
    import com.rapidminer.operator.text.Document;
import com.rapidminer.operator.text.Token;

import java.util.List;
import java.util.LinkedList;
def train(f){
    def n = [:]
    new File(f).eachLine{it.toLowerCase().eachMatch(/\w+/){n[it]=n[it]?n[it]+1:1}}
    n
}

def edits(word) {
    def result = [], n = word.length()-1
    for(i in 0..n) result.add(word[0..<i] + word.substring(i+1))
    for(i in 0..n-1) result.add(word[0..<i] + word[i+1] + word[i, i+1] + word.substring(i+2))
    for(i in 0..n) for(c in 'a'..'z') result.add(word[0..<i] + c + word.substring(i+1))
    for(i in 0..n) for(c in 'a'..'z') result.add(word[0..<i] + c + word.substring(i))
    result
}

def correct(word, nWords) {
    if(nWords[word]) return word
    def list = edits(word), candidates = [:]
    for(s in list) if(nWords[s]) candidates[nWords[s]] = s
    if(candidates.size() > 0) return candidates[candidates.keySet().max()]
    for(s in list) for(w in edits(s)) if(nWords[w]) candidates[nWords[w]] = w
    return candidates.size() > 0 ? candidates[candidates.keySet().max()] : word
}