我有一個野趣的臭蟲程序達到此行Java字符串比較有趣的bug
System.out.println("!tempLine.equals(raf.readLine().toString())");
每次在迴路中的隨機指數。 不知道tempLine如何可能不等於raf.readLine()。toString(),其中前一個分配始終處於平穩狀態。 另一個有趣的(不確定它是相關的)是在某些時候raf.readLine()和raf.readLine()。toString()有兩個不同的值。 Deperate幫忙:-)
private static Map<String, List<KeyPhraseAnnotation>> getKeyPhrasesFromNewNlp(String filename) throws Exception
{
String manualMemoPrefix = "Caller/Customer Name:";
FreeTextProcessingPipeline nlpPipeline = springContext.getBean(FreeTextProcessingPipeline.class);
nlpPipeline.initialize();
Map<String, List<KeyPhraseAnnotation>> kpMatrix = new HashMap<String, List<KeyPhraseAnnotation>>();
//Map<String, FreeTextProcessingResult> results = nlpPipeline.processFiles(folder, "en-US");
Random rand = new Random();
BufferedReader br = new BufferedReader(new FileReader(filename));
RandomAccessFile raf = new RandomAccessFile(filename,"rw");
String line;
long counter = 0;
int lines = 0;
int k = 0;
int s_max = 0;
int s_min = 0;
int t = 0;
int hit=0;
double e ;
int max_num_of_documents = 500;
String[] parts = null;
while (br.readLine() != null) lines++;
t = (int) Math.floor((lines/max_num_of_documents));
k = t;
e = 0.1 * k;
String tempLine = null;
String memo_manual = null;
int current_num_docs = 0;
while (current_num_docs<max_num_of_documents){
System.out.println("this is u in beginning of loop: " + current_num_docs);
tempLine = null;
s_max = (int) (k+e);
s_min = (int) (k-e);
hit = s_min + (int)(Math.random() * ((s_max - s_min) + 1)) ;
if(hit<lines && hit>0){
raf.seek(hit);
}
else{
break;
}
tempLine = raf.readLine().toString();
if (!tempLine.equals(raf.readLine().toString()))
{
System.out.println("!tempLine.equals(raf.readLine().toString())");
}
parts = tempLine.split("\\|");
//String sessionId = parts[0];
if(parts.length == 21){
memo_manual = parts[15];
}
else {
memo_manual="";
System.out.println(raf.readLine() + " " + tempLine);
}
if (memo_manual.toLowerCase().contains(manualMemoPrefix.toLowerCase())){
FreeTextProcessingRequest request = new FreeTextProcessingRequest();
request.setText(memo_manual);
FreeTextProcessingResult result = nlpPipeline.processRequest(request);
List<KeyPhraseAnnotation> list = Arrays.asList(result.getDefaultView().getKeyPhraseAnnotations());
kpMatrix.put(Long.toString(counter), list);
for (KeyPhraseAnnotation kp : list){
System.out.println(kp.getValue() +" : " +kp.getImportance());
}
//t += s_max+1;
current_num_docs++;
k = k + t;
}
System.out.println("this is u in end of loop: " + current_num_docs);
}
System.out.println("OUT OF FOR");
/*while ((line = br.readLine()) != null && DocCounter < 50000) {
String[] parts = line.split("\\|");
//String sessionId = parts[0];
String memo_manual = parts[15];
//String category = parts[2];
//String AccountBalance = "2139";
String manualMemoPrefix = "Caller/Customer Name:";
//if (category.equals(AccountBalance) && memo_manual.toLowerCase().contains(manualMemoPrefix.toLowerCase())){
if (memo_manual.toLowerCase().contains(manualMemoPrefix.toLowerCase())){
DocCounter ++ ;
FreeTextProcessingRequest request = new FreeTextProcessingRequest();
request.setText(memo_manual);
FreeTextProcessingResult result = nlpPipeline.processRequest(request);
List<KeyPhraseAnnotation> list = Arrays.asList(result.getDefaultView().getKeyPhraseAnnotations());
kpMatrix.put(Long.toString(counter), list);
for (KeyPhraseAnnotation kp : list){
System.out.println(kp.getValue() +" : " +kp.getImportance());
}
}
counter++;
}*/
br.close();
}
你可以粘貼輸出 – 2014-09-05 11:22:55