* @param vector the string feature vector.
* @return the sparse feature vector converted from the string feature vector.
*/
public SparseFeatureVector toSparseFeatureVector(StringFeatureVector vector)
{
SparseFeatureVector sparse = new SparseFeatureVector(vector.hasWeight());
int i, index, size = vector.size();
ObjectIntOpenHashMap<String> map;
String type, value;
for (i=0; i<size; i++)
{
type = vector.getType(i);
value = vector.getValue(i);
if ((map = m_features.get(type)) != null && (index = map.get(value)) > 0)
{
if (sparse.hasWeight())
sparse.addFeature(index, vector.getWeight(i));
else
sparse.addFeature(index);
}
}
sparse.trimToSize();
return sparse;
}