@Test(expected = Test.None.class) 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+")) .toArray(String[][]::new); String[] feature = { "outstanding", "wonderfully", "wasted", "lame", "awful", "poorly", "ridiculous", "waste", "worst", "bland", "unfunny", "stupid", "dull", "fantastic", "laughable", "mess", "pointless", "terrific", "memorable", "superb", "boring", "badly", "subtle", "terrible", "excellent", "perfectly", "masterpiece", "realistic", "flaws" }; Bag bag = new Bag(feature); int[][] x = new int[text.length][]; for (int i = 0; i < text.length; i++) { x[i] = bag.apply(text[i]); assertEquals(feature.length, x[i].length); } assertEquals(1, x[0][15]); }
public int[] apply(String[] x) { int[] bag = new int[words.size()]; if (binary) { for (String word : x) { Integer f = words.get(word); if (f != null) { bag[f] = 1; } } } else { for (String word : x) { Integer f = words.get(word); if (f != null) { bag[f]++; } } } return bag; }
Bag { public int[] apply(String[] x) { int[] bag = new int[words.size()]; if (binary) { for (String word : x) { Integer f = words.get(word); if (f != null) { bag[f] = 1; } } } else { for (String word : x) { Integer f = words.get(word); if (f != null) { bag[f]++; } } } return bag; } }
Bag { public int[] apply(String[] x) { int[] bag = new int[words.size()]; if (binary) { for (String word : x) { Integer f = words.get(word); if (f != null) { bag[f] = 1; } } } else { for (String word : x) { Integer f = words.get(word); if (f != null) { bag[f]++; } } } return bag; } Bag(String[] words);  Bag(String[] words, boolean binary); }
Bag { public int[] apply(String[] x) { int[] bag = new int[words.size()]; if (binary) { for (String word : x) { Integer f = words.get(word); if (f != null) { bag[f] = 1; } } } else { for (String word : x) { Integer f = words.get(word); if (f != null) { bag[f]++; } } } return bag; } Bag(String[] words);  Bag(String[] words, boolean binary); int[] apply(String[] x); }
Bag { public int[] apply(String[] x) { int[] bag = new int[words.size()]; if (binary) { for (String word : x) { Integer f = words.get(word); if (f != null) { bag[f] = 1; } } } else { for (String word : x) { Integer f = words.get(word); if (f != null) { bag[f]++; } } } return bag; } Bag(String[] words);  Bag(String[] words, boolean binary); int[] apply(String[] x);  }