List<SparseVector> res = new ArrayList<SparseVector>();
BreakIterator wordIt = BreakIterator.getWordInstance();
for (String text : texts) {
SparseVector fv = new SparseVector();
res.add(fv);
wordIt.setText(text);
int start = wordIt.first();
int end = wordIt.next();
while (end != BreakIterator.DONE) {
String word = text.substring(start,end);
if (Character.isLetterOrDigit(word.charAt(0))) {
// Get the int key for the word
Integer key = word2index.get(word);
if (key == null) {
key = new Integer(word2index.size()+1);
word2index.put(word, key);
}
fv.setValue(key, fv.getValue(key) + 1); // increase count
}
start = end;
end = wordIt.next();
}
}