长时间的用户,但新的海报,我有一个非常令人沮丧的问题,我似乎无法调试。我有一个程序在进行理论练习的语音搜索。输入通过标准输入接收。 所以,
Java MyAppication Jones Smith Andrews < NAMES.TXT
从那里,搜索项被推入Hashmap,NAMES.TXT也被推入HashMap。对剥离某些字符(如元音)的值执行操作。
例如:Jones作为目录[“Jones”] = Jns存储在Directory Hashmap中 搜索词哈希映射也是如此。
这是搜索方法,
private static String search(){
Iterator<String> searchKeyIterator = search.keySet().iterator();
Iterator<String> directoryKeyIterator = directory.keySet().iterator();
String output = new String();
//Loop through the search terms
while(searchKeyIterator.hasNext()){
String searchkey = searchKeyIterator.next();
Pattern searchRegex = Pattern.compile(regexBuild(search.get(searchkey)));
output += "\n" + searchkey + ": ";
while(directoryKeyIterator.hasNext()){
String directorykey = directoryKeyIterator.next();
Matcher m = searchRegex.matcher(directory.get(directorykey));
boolean b = m.matches();
if(b == true){
output += directorykey + ", ";
}
}
output = output.substring(0, output.length() - 2);
}
return output;}
它通过遍历搜索目录并为每个术语形成正则表达式模式(这是因为对等效字符的约束)。然后将此正则表达式与目录进行匹配。
例如,琼斯的输入变为Jns,这个的正则表达式变为[CGJKQSXYZcgjkqsxyz] [MNmn] [CGJKQSXYZcgjkqsxyz],这意味着任何匹配JNS,SNS,Cng的东西都会匹配。
然而,它似乎不匹配。 这是存储的数据集
key: Smith value: Smt
key: Johnson value: Jnsn
key: Ericsson value: Ercssn
key: Smyth value: Smt
key: Macdonald value: Mcdnld
key: Smid value: Smd
key: Schmidt value: Scmdt
key: Smithers value: Smtrs
key: Jonas value: Jns
key: Nest O'Malett value: Nst Mltt
key: Smythe value: Smt
key: Van Damme value: Vn Dmm
key: Erikson value: Erksn
key: Saunas value: Sns
key: Johns value: Jns
但结果似乎表明尽管看到列表中有一个,但没有匹配。
java.util.regex.Matcher[pattern=[CGJKQSXYZcgjkqsxyz][MNmn][CGJKQSXYZcgjkqsxyz] region=0,3 lastmatch=]
java.util.regex.Matcher[pattern=[CGJKQSXYZcgjkqsxyz][MNmn][CGJKQSXYZcgjkqsxyz] region=0,5 lastmatch=]
java.util.regex.Matcher[pattern=[CGJKQSXYZcgjkqsxyz][MNmn][CGJKQSXYZcgjkqsxyz] region=0,7 lastmatch=]
java.util.regex.Matcher[pattern=[CGJKQSXYZcgjkqsxyz][MNmn][CGJKQSXYZcgjkqsxyz] region=0,3 lastmatch=]
java.util.regex.Matcher[pattern=[CGJKQSXYZcgjkqsxyz][MNmn][CGJKQSXYZcgjkqsxyz] region=0,7 lastmatch=]
java.util.regex.Matcher[pattern=[CGJKQSXYZcgjkqsxyz][MNmn][CGJKQSXYZcgjkqsxyz] region=0,4 lastmatch=]
java.util.regex.Matcher[pattern=[CGJKQSXYZcgjkqsxyz][MNmn][CGJKQSXYZcgjkqsxyz] region=0,6 lastmatch=]
java.util.regex.Matcher[pattern=[CGJKQSXYZcgjkqsxyz][MNmn][CGJKQSXYZcgjkqsxyz] region=0,6 lastmatch=]
java.util.regex.Matcher[pattern=[CGJKQSXYZcgjkqsxyz][MNmn][CGJKQSXYZcgjkqsxyz] region=0,4 lastmatch=]
java.util.regex.Matcher[pattern=[CGJKQSXYZcgjkqsxyz][MNmn][CGJKQSXYZcgjkqsxyz] region=0,9 lastmatch=]
java.util.regex.Matcher[pattern=[CGJKQSXYZcgjkqsxyz][MNmn][CGJKQSXYZcgjkqsxyz] region=0,4 lastmatch=]
java.util.regex.Matcher[pattern=[CGJKQSXYZcgjkqsxyz][MNmn][CGJKQSXYZcgjkqsxyz] region=0,6 lastmatch=]
java.util.regex.Matcher[pattern=[CGJKQSXYZcgjkqsxyz][MNmn][CGJKQSXYZcgjkqsxyz] region=0,6 lastmatch=]
java.util.regex.Matcher[pattern=[CGJKQSXYZcgjkqsxyz][MNmn][CGJKQSXYZcgjkqsxyz] region=0,4 lastmatch=]
java.util.regex.Matcher[pattern=[CGJKQSXYZcgjkqsxyz][MNmn][CGJKQSXYZcgjkqsxyz] region=0,4 lastmatch=]
非常感谢任何帮助。