Rabbit3cat
11-09-2005, 06:01 PM
Hi
I am trying to compare words in strings, the strings are stored in hash tables. The first file is stored in testTable and the second in TrainingTable. What i want to do is increment the integer variable "commonWords" by one each time, a word in testTable matches a word in TrainingTable, i have been using the following code to do this, and it does compare the two strings but it does not include duplicates. So if the testTable contains the word "the" four times and trainingTable contains the word "the" two times i want commonwords to return 6 but currently it only returns one. does anybody know how i can solve this problem?
Iterator table1 = testTable.keySet().iterator();
while (table1.hasNext()) {
Object e = table1.next();
Iterator table2 = trainingTable.keySet().iterator();
while(table2.hasNext()) {
Object f = table2.next();
if(f.toString().compareTo(e.toString()) == 0) {
commonWords++;
}
}
}
Thanks
I am trying to compare words in strings, the strings are stored in hash tables. The first file is stored in testTable and the second in TrainingTable. What i want to do is increment the integer variable "commonWords" by one each time, a word in testTable matches a word in TrainingTable, i have been using the following code to do this, and it does compare the two strings but it does not include duplicates. So if the testTable contains the word "the" four times and trainingTable contains the word "the" two times i want commonwords to return 6 but currently it only returns one. does anybody know how i can solve this problem?
Iterator table1 = testTable.keySet().iterator();
while (table1.hasNext()) {
Object e = table1.next();
Iterator table2 = trainingTable.keySet().iterator();
while(table2.hasNext()) {
Object f = table2.next();
if(f.toString().compareTo(e.toString()) == 0) {
commonWords++;
}
}
}
Thanks