@Override
protected void parseLineInternal(String line) {
List<String> entries = tokenize(line);
double len = 0;
TIntFloatHashMap values = new TIntFloatHashMap();
LabelList labels = null;
String curterm = null;
for(int i = 0; i < entries.size(); i++) {
if(curterm == null) {
curterm = entries.get(i);
}
else {
try {
float attribute = Float.valueOf(entries.get(i));
Integer curdim = keymap.get(curterm);
if(curdim == null) {
curdim = maxdim + 1;
keymap.put(curterm, curdim);
maxdim += 1;
}
values.put(curdim, attribute);
len += attribute;
curterm = null;
}
catch(NumberFormatException e) {
if(curterm != null) {
if(labels == null) {
labels = new LabelList(1);
}
labels.add(curterm);
}
curterm = entries.get(i);
}
}
}
if(curterm != null) {
if(labels == null) {
labels = new LabelList(1);
}
labels.add(curterm);
}
if(normalize) {
if(Math.abs(len - 1.0) > 1E-10 && len > 1E-10) {
for(TIntFloatIterator iter = values.iterator(); iter.hasNext();) {
iter.advance();
iter.setValue((float) (iter.value() / len));
}
}
}