(Tuple input)
| 46 | private static final int _ngramSizeLimit = 2; |
| 47 | |
| 48 | public DataBag exec(Tuple input) throws IOException { |
| 49 | if (input == null || input.size() == 0) |
| 50 | return null; |
| 51 | try{ |
| 52 | DataBag output = DefaultBagFactory.getInstance().newDefaultBag(); |
| 53 | String query = (String)input.get(0); |
| 54 | String[] words = TutorialUtil.splitToWords(query); |
| 55 | Set<String> ngrams = new HashSet<String>(); |
| 56 | TutorialUtil.makeNGram(words, ngrams, _ngramSizeLimit); |
| 57 | for (String ngram : ngrams) { |
| 58 | Tuple t = TupleFactory.getInstance().newTuple(1); |
| 59 | t.set(0, ngram); |
| 60 | output.add(t); |
| 61 | } |
| 62 | return output; |
| 63 | }catch(Exception e){ |
| 64 | System.err.println("NGramGenerator: failed to process input; error - " + e.getMessage()); |
| 65 | return null; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | /** |
nothing calls this directly
no test coverage detected