@Test public void testNull() throws Exception { NGramFeatureGenerator generator = new NGramFeatureGenerator(); try { generator.extractFeatures(null, Collections.emptyMap()); Assert.fail("NullPointerException must be thrown"); } catch (NullPointerException expected) { } }
public Collection<String> extractFeatures(String[] text, Map<String, Object> extraInfo) { Objects.requireNonNull(text, "text must not be null"); List<String> features = new ArrayList<>(); for (int i = 0; i <= text.length - minGram; i++) { final StringBuilder sb = new StringBuilder(); sb.append("ng="); for (int y = 0; y < maxGram && i + y < text.length; y++) { sb.append(":"); sb.append(text[i + y]); int gramCount = y + 1; if (maxGram >= gramCount && gramCount >= minGram) { features.add(sb.toString()); } } } return features; }
NGramFeatureGenerator implements FeatureGenerator { public Collection<String> extractFeatures(String[] text, Map<String, Object> extraInfo) { Objects.requireNonNull(text, "text must not be null"); List<String> features = new ArrayList<>(); for (int i = 0; i <= text.length - minGram; i++) { final StringBuilder sb = new StringBuilder(); sb.append("ng="); for (int y = 0; y < maxGram && i + y < text.length; y++) { sb.append(":"); sb.append(text[i + y]); int gramCount = y + 1; if (maxGram >= gramCount && gramCount >= minGram) { features.add(sb.toString()); } } } return features; } }
NGramFeatureGenerator implements FeatureGenerator { public Collection<String> extractFeatures(String[] text, Map<String, Object> extraInfo) { Objects.requireNonNull(text, "text must not be null"); List<String> features = new ArrayList<>(); for (int i = 0; i <= text.length - minGram; i++) { final StringBuilder sb = new StringBuilder(); sb.append("ng="); for (int y = 0; y < maxGram && i + y < text.length; y++) { sb.append(":"); sb.append(text[i + y]); int gramCount = y + 1; if (maxGram >= gramCount && gramCount >= minGram) { features.add(sb.toString()); } } } return features; } NGramFeatureGenerator(int minGram, int maxGram);  NGramFeatureGenerator(); }
NGramFeatureGenerator implements FeatureGenerator { public Collection<String> extractFeatures(String[] text, Map<String, Object> extraInfo) { Objects.requireNonNull(text, "text must not be null"); List<String> features = new ArrayList<>(); for (int i = 0; i <= text.length - minGram; i++) { final StringBuilder sb = new StringBuilder(); sb.append("ng="); for (int y = 0; y < maxGram && i + y < text.length; y++) { sb.append(":"); sb.append(text[i + y]); int gramCount = y + 1; if (maxGram >= gramCount && gramCount >= minGram) { features.add(sb.toString()); } } } return features; } NGramFeatureGenerator(int minGram, int maxGram);  NGramFeatureGenerator(); Collection<String> extractFeatures(String[] text, Map<String, Object> extraInfo); }
NGramFeatureGenerator implements FeatureGenerator { public Collection<String> extractFeatures(String[] text, Map<String, Object> extraInfo) { Objects.requireNonNull(text, "text must not be null"); List<String> features = new ArrayList<>(); for (int i = 0; i <= text.length - minGram; i++) { final StringBuilder sb = new StringBuilder(); sb.append("ng="); for (int y = 0; y < maxGram && i + y < text.length; y++) { sb.append(":"); sb.append(text[i + y]); int gramCount = y + 1; if (maxGram >= gramCount && gramCount >= minGram) { features.add(sb.toString()); } } } return features; } NGramFeatureGenerator(int minGram, int maxGram);  NGramFeatureGenerator(); Collection<String> extractFeatures(String[] text, Map<String, Object> extraInfo);  }