@Test public void vectorize() { Map<String, Integer> dict = VectorText.tokenize(sample.split("\\.")[0]).collect( TreeMap::new, (Map<String, Integer> d, String s) -> d.put(s, d.size()), Map::putAll ); dict.remove("5"); dict.put("tiger", dict.size()); int[] v = VectorText.vectorize(dict, sample); assertArrayEquals(new int[]{1, 1, 1, 0, 1, 1, 1}, v); }
public static int[] vectorize(Map<String, Integer> dictionary, String s) { int[] result = new int[dictionary.size()]; VectorText.tokenize(s).forEach(w -> { if (dictionary.containsKey(w)) { result[dictionary.get(w)] = 1; } }); return result; }
VectorText { public static int[] vectorize(Map<String, Integer> dictionary, String s) { int[] result = new int[dictionary.size()]; VectorText.tokenize(s).forEach(w -> { if (dictionary.containsKey(w)) { result[dictionary.get(w)] = 1; } }); return result; } }
VectorText { public static int[] vectorize(Map<String, Integer> dictionary, String s) { int[] result = new int[dictionary.size()]; VectorText.tokenize(s).forEach(w -> { if (dictionary.containsKey(w)) { result[dictionary.get(w)] = 1; } }); return result; }  }
VectorText { public static int[] vectorize(Map<String, Integer> dictionary, String s) { int[] result = new int[dictionary.size()]; VectorText.tokenize(s).forEach(w -> { if (dictionary.containsKey(w)) { result[dictionary.get(w)] = 1; } }); return result; }  @SuppressWarnings("WeakerAccess") static Stream<String> tokenize(CharSequence s); @SuppressWarnings("WeakerAccess") static List<String> tokenizeAsList(CharSequence s); static int[] vectorize(Map<String, Integer> dictionary, String s); static int[] count(Map<String, Integer> dictionary, String s); }
VectorText { public static int[] vectorize(Map<String, Integer> dictionary, String s) { int[] result = new int[dictionary.size()]; VectorText.tokenize(s).forEach(w -> { if (dictionary.containsKey(w)) { result[dictionary.get(w)] = 1; } }); return result; }  @SuppressWarnings("WeakerAccess") static Stream<String> tokenize(CharSequence s); @SuppressWarnings("WeakerAccess") static List<String> tokenizeAsList(CharSequence s); static int[] vectorize(Map<String, Integer> dictionary, String s); static int[] count(Map<String, Integer> dictionary, String s);  }