Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.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 如何在我的代码中查找缺少的边案例_Java_Regex_Mapreduce_Pattern Matching - Fatal编程技术网

Java 如何在我的代码中查找缺少的边案例

Java 如何在我的代码中查找缺少的边案例,java,regex,mapreduce,pattern-matching,Java,Regex,Mapreduce,Pattern Matching,我正在使用map reduce作业处理推文。我想做的一件事就是审查滥用语言的行为。当我在本地测试我的代码时,它会按预期工作。但是,当我在一些文本的整个数据集上运行它时,它检查了滥用的单词,但遗漏了一些。现在,由于数据总量为1TB(800个文件),我无法找到原始格式(JSON)的特定tweet数据,因此我可以在本地对其进行测试以发现问题。然而,我有推特文本(不是整个json),它没有被我的MapReduce程序审查。为了进行测试,我尝试将该文本放在其他tweetJSON的tweet文本字段中,程序

我正在使用map reduce作业处理推文。我想做的一件事就是审查滥用语言的行为。当我在本地测试我的代码时,它会按预期工作。但是,当我在一些文本的整个数据集上运行它时,它检查了滥用的单词,但遗漏了一些。现在,由于数据总量为1TB(800个文件),我无法找到原始格式(JSON)的特定tweet数据,因此我可以在本地对其进行测试以发现问题。然而,我有推特文本(不是整个json),它没有被我的MapReduce程序审查。为了进行测试,我尝试将该文本放在其他tweetJSON的tweet文本字段中,程序正确地审查了滥用的单词。你们能提出一些策略让我找到bug吗。或者如果你仅仅通过查看我的代码就发现了一个bug,那就太好了 循环浏览tweet的所有单词的函数(tweet由非字母数字字符分割)

公共静态字符串检查文本(字符串文本,字符串文本字[],设置禁止){ StringBuilder=新的StringBuilder(文本)

textWords=getTextArray(text);
for(int i=0;iPattern p=Pattern.compile((?除了lookahed/lookbehind之外,您不使用任何正则表达式功能。在Java正则表达式搜索中,Lookahead和lookbehind没有优化。您也可以搜索字符串,然后验证前/后字符是否正确

这将节省大量性能:

  • 正则表达式的编译成本很高(与字符串搜索编译相比)
  • 使用正则表达式进行搜索的成本甚至更高(与字符串搜索相比)
因此,如果您想解决这个问题:使用字符串搜索算法(如boyer moore horspool)


如果使用多字符串搜索算法,如set-horspool或wu-manber,则效率更高。这种算法将提供所有单词的所有索引,其性能接近O(n)(n是文本的长度)。

为了使其可读性更好,可以将[^a-zA-Z\\d]替换为\W(无字母数字),对吗?为什么括号中的第一个字符是?
    textWords = getTextArray(text);

    for (int i = 0; i < textWords.length; i++) {

        if (banned.contains(textWords[i].toLowerCase())) {

            String cleanedWord = cencor(textWords[i]);
            // compile a pattern with banned word
            List<Integer> indexList = getIndexes(builder, textWords[i]);
            replaceWithCleanWord(builder, indexList, cleanedWord);
        }
    }

    return builder.toString();
}
//function to find the position of abuse word in the tweet text so     that //can be replaced by censored word
private static List<Integer> getIndexes(StringBuilder builder, String string) {

    List<Integer> indexes = new ArrayList<Integer>();
    String word = "(" + string.charAt(0) + ")" + string.substring(1);
    System.out.println("word to match" +word);
    Pattern p = Pattern.compile("(?<=^|[^a-zA-Z\\d])" + word + "(?=$|[^a-zA-Z\\d])");
    Matcher m = p.matcher(builder.toString());
    while (m.find()) {
        indexes.add(m.start());
    }
    return indexes;
}