ConstantValueEncoder extends CachingValueEncoder { @Override public void addToVector(byte[] originalForm, double weight, Vector data) { int probes = getProbes(); String name = getName(); for (int i = 0; i < probes; i++) { int n = hashForProbe(originalForm, data.size(), name, i); if (isTraceEnabled()) { trace((String) null, n); } data.set(n, data.get(n) + getWeight(originalForm,weight)); } } ConstantValueEncoder(String name); @Override void addToVector(byte[] originalForm, double weight, Vector data); @Override String asString(String originalForm);  }
@Test public void testAddToVector() { FeatureVectorEncoder enc = new ConstantValueEncoder("foo"); Vector v1 = new DenseVector(20); enc.addToVector((byte[]) null, -123, v1); assertEquals(-123, v1.minValue(), 0); assertEquals(0, v1.maxValue(), 0); assertEquals(123, v1.norm(1), 0); v1 = new DenseVector(20); enc.addToVector((byte[]) null, 123, v1); assertEquals(123, v1.maxValue(), 0); assertEquals(0, v1.minValue(), 0); assertEquals(123, v1.norm(1), 0); Vector v2 = new DenseVector(20); enc.setProbes(2); enc.addToVector((byte[]) null, 123, v2); assertEquals(123, v2.maxValue(), 0); assertEquals(2 * 123, v2.norm(1), 0); v1 = v2.minus(v1); assertEquals(123, v1.maxValue(), 0); assertEquals(123, v1.norm(1), 0); Vector v3 = new DenseVector(20); enc.setProbes(2); enc.addToVector((byte[]) null, 100, v3); v1 = v2.minus(v3); assertEquals(23, v1.maxValue(), 0); assertEquals(2 * 23, v1.norm(1), 0); enc.addToVector((byte[]) null, 7, v1); assertEquals(30, v1.maxValue(), 0); assertEquals(2 * 30, v1.norm(1), 0); assertEquals(30, v1.get(9), 0); assertEquals(30, v1.get(10), 0); }