Code with Finding: |
class QueryTermVector {
private void processTerms(String[] queryTerms) {
if (queryTerms != null) {
Arrays.sort(queryTerms);
Map tmpSet = new HashMap(queryTerms.length);
//filter out duplicates
List tmpList = new ArrayList(queryTerms.length);
List tmpFreqs = new ArrayList(queryTerms.length);
int j = 0;
for (int i = 0; i < queryTerms.length; i++) {
String term = queryTerms[i];
Integer position = (Integer)tmpSet.get(term);
if (position == null) {
tmpSet.put(term, new Integer(j++));
tmpList.add(term);
tmpFreqs.add(new Integer(1));
}
else {
Integer integer = (Integer)tmpFreqs.get(position.intValue());
tmpFreqs.set(position.intValue(), new Integer(integer.intValue() + 1));
}
}
terms = (String[])tmpList.toArray(terms);
//termFreqs = (int[])tmpFreqs.toArray(termFreqs);
termFreqs = new int[tmpFreqs.size()];
int i = 0;
for (Iterator iter = tmpFreqs.iterator(); iter.hasNext();) {
Integer integer = (Integer) iter.next();
termFreqs[i++] = integer.intValue();
}
}
}
}
|