@Override
    public SparseArray apply(String text) {
        TreeMap<Integer, Integer> bag = new TreeMap<>();
        for (String word : tokenizer.apply(text)) {
            int h = MurmurHash3.hash32(word, 0);
            // abs(-2 * * 31)is undefined behavior
            int index = h == -2147483648 ? (2147483647 - (numFeatures - 1)) % numFeatures : Math.abs(h) % numFeatures;

            // improve inner product preservation in the hashed space
            int value = alternateSign && h < 0 ? -1 : 1;
            bag.merge(index, value, Integer::sum);
        }

        SparseArray features = new SparseArray();
        bag.forEach(features::append);
        return features;
    }
@Test
    public void testFeature() throws IOException {
        System.out.println("feature");
        String[][] text = smile.util.Paths.getTestDataLines("text/movie.txt")
                .map(String::trim)
                .filter(line -> !line.isEmpty())
                .map(line -> line.split("\\s+", 2))
                .toArray(String[][]::new);

        HashEncoder hashing = new HashEncoder(tokenizer, 1000);

        SparseArray[] x = new SparseArray[text.length];
        for (int i = 0; i < text.length; i++) {
            x[i] = hashing.apply(text[i][1]);
        }

        System.out.println(x[0]);
        assertEquals(289, x[0].size());
        System.out.println(x[1999]);
        assertEquals(345, x[1999].size());
    }