MCPcopy Create free account
hub / github.com/apache/pig / makeNGram

Method makeNGram

tutorial/src/org/apache/pig/tutorial/TutorialUtil.java:48–61  ·  view source on GitHub ↗

This is a simple utility function that make word-level ngrams from a set of words @param words @param ngrams @param size

(String[] words, Set<String> ngrams, int size)

Source from the content-addressed store, hash-verified

46 * @param size
47 */
48 protected static void makeNGram(String[] words, Set<String> ngrams, int size) {
49 int stop = words.length - size + 1;
50 for (int i = 0; i < stop; i++) {
51 StringBuilder sb = new StringBuilder();
52 for (int j = 0; j < size; j++) {
53 sb.append(words[i + j]).append(" ");
54 }
55 sb.deleteCharAt(sb.length() - 1);
56 ngrams.add(sb.toString());
57 }
58 if (size > 1) {
59 makeNGram(words, ngrams, size - 1);
60 }
61 }
62
63}

Callers 1

execMethod · 0.95

Calls 4

lengthMethod · 0.80
appendMethod · 0.65
addMethod · 0.65
toStringMethod · 0.45

Tested by

no test coverage detected