@Test public void generateCharTest1() { final char[] input = "Test".toCharArray(); final int window = 1; final String separator = "-"; final List<String> ngrams = NGramGenerator.generate(input, window, separator); Assert.assertEquals(4, ngrams.size()); Assert.assertEquals("T", ngrams.get(0)); Assert.assertEquals("e", ngrams.get(1)); Assert.assertEquals("s", ngrams.get(2)); Assert.assertEquals("t", ngrams.get(3)); }
public static List<String> generate(List<String> input, int n, String separator) { List<String> outGrams = new ArrayList<>(); for (int i = 0; i < input.size() - (n - 1); i++) { final StringBuilder sb = new StringBuilder(); for (int x = i; x < (n + i); x++) { sb.append(input.get(x)); sb.append(separator); } String gram = sb.toString(); gram = gram.substring(0, gram.lastIndexOf(separator)); outGrams.add(gram); } return outGrams; }
NGramGenerator { public static List<String> generate(List<String> input, int n, String separator) { List<String> outGrams = new ArrayList<>(); for (int i = 0; i < input.size() - (n - 1); i++) { final StringBuilder sb = new StringBuilder(); for (int x = i; x < (n + i); x++) { sb.append(input.get(x)); sb.append(separator); } String gram = sb.toString(); gram = gram.substring(0, gram.lastIndexOf(separator)); outGrams.add(gram); } return outGrams; } }
NGramGenerator { public static List<String> generate(List<String> input, int n, String separator) { List<String> outGrams = new ArrayList<>(); for (int i = 0; i < input.size() - (n - 1); i++) { final StringBuilder sb = new StringBuilder(); for (int x = i; x < (n + i); x++) { sb.append(input.get(x)); sb.append(separator); } String gram = sb.toString(); gram = gram.substring(0, gram.lastIndexOf(separator)); outGrams.add(gram); } return outGrams; }  }
NGramGenerator { public static List<String> generate(List<String> input, int n, String separator) { List<String> outGrams = new ArrayList<>(); for (int i = 0; i < input.size() - (n - 1); i++) { final StringBuilder sb = new StringBuilder(); for (int x = i; x < (n + i); x++) { sb.append(input.get(x)); sb.append(separator); } String gram = sb.toString(); gram = gram.substring(0, gram.lastIndexOf(separator)); outGrams.add(gram); } return outGrams; }  static List<String> generate(List<String> input, int n, String separator); static List<String> generate(char[] input, int n, String separator); }
NGramGenerator { public static List<String> generate(List<String> input, int n, String separator) { List<String> outGrams = new ArrayList<>(); for (int i = 0; i < input.size() - (n - 1); i++) { final StringBuilder sb = new StringBuilder(); for (int x = i; x < (n + i); x++) { sb.append(input.get(x)); sb.append(separator); } String gram = sb.toString(); gram = gram.substring(0, gram.lastIndexOf(separator)); outGrams.add(gram); } return outGrams; }  static List<String> generate(List<String> input, int n, String separator); static List<String> generate(char[] input, int n, String separator);  }