TextValueEncoder extends FeatureVectorEncoder { @Override public void addToVector(byte[] originalForm, double weight, Vector data) { addText(originalForm); flush(weight, data); } TextValueEncoder(String name); @Override void addToVector(byte[] originalForm, double weight, Vector data); void addText(byte[] originalForm); void addText(CharSequence text); void flush(double weight, Vector data); @Override String asString(String originalForm); final void setWordEncoder(FeatureVectorEncoder wordEncoder);  }
@Test public void testAddToVector() { TextValueEncoder enc = new TextValueEncoder("text"); Vector v1 = new DenseVector(200); enc.addToVector("test1 and more", v1); enc.flush(1, v1); assertEquals(6.0, v1.norm(1), 0); assertEquals(1.0, v1.maxValue(), 0); StaticWordValueEncoder w = new StaticWordValueEncoder("text"); w.setDictionary(ImmutableMap.<String, Double>of("word1", 3.0, "word2", 1.5)); enc.setWordEncoder(w); Vector v2 = new DenseVector(200); enc.addToVector("test1 and more", v2); enc.flush(1, v2); Vector v3 = new DenseVector(200); w.addToVector("test1", v3); w.addToVector("and", v3); w.addToVector("more", v3); assertEquals(0, v3.minus(v2).norm(1), 0); assertEquals(v3.zSum(), v3.dot(v1), 0); }