@Test public void testEnd() { final int testTokenIndex = 4; AdaptiveFeatureGenerator generator = new TrigramNameFeatureGenerator(); generator.createFeatures(features, testSentence, testTokenIndex, null); Assert.assertEquals(2, features.size()); Assert.assertEquals("ppw,pw,w=an,example,sentence", features.get(0)); Assert.assertEquals("ppwc,pwc,wc=lc,lc,lc", features.get(1)); }
public void createFeatures(List<String> features, String[] tokens, int index, String[] previousOutcomes) { String wc = FeatureGeneratorUtil.tokenFeature(tokens[index]); if (index > 1) { features.add("ppw,pw,w=" + tokens[index - 2] + "," + tokens[index - 1] + "," + tokens[index]); String pwc = FeatureGeneratorUtil.tokenFeature(tokens[index - 1]); String ppwc = FeatureGeneratorUtil.tokenFeature(tokens[index - 2]); features.add("ppwc,pwc,wc=" + ppwc + "," + pwc + "," + wc); } if (index + 2 < tokens.length) { features.add("w,nw,nnw=" + tokens[index] + "," + tokens[index + 1] + "," + tokens[index + 2]); String nwc = FeatureGeneratorUtil.tokenFeature(tokens[index + 1]); String nnwc = FeatureGeneratorUtil.tokenFeature(tokens[index + 2]); features.add("wc,nwc,nnwc=" + wc + "," + nwc + "," + nnwc); } }
TrigramNameFeatureGenerator implements AdaptiveFeatureGenerator { public void createFeatures(List<String> features, String[] tokens, int index, String[] previousOutcomes) { String wc = FeatureGeneratorUtil.tokenFeature(tokens[index]); if (index > 1) { features.add("ppw,pw,w=" + tokens[index - 2] + "," + tokens[index - 1] + "," + tokens[index]); String pwc = FeatureGeneratorUtil.tokenFeature(tokens[index - 1]); String ppwc = FeatureGeneratorUtil.tokenFeature(tokens[index - 2]); features.add("ppwc,pwc,wc=" + ppwc + "," + pwc + "," + wc); } if (index + 2 < tokens.length) { features.add("w,nw,nnw=" + tokens[index] + "," + tokens[index + 1] + "," + tokens[index + 2]); String nwc = FeatureGeneratorUtil.tokenFeature(tokens[index + 1]); String nnwc = FeatureGeneratorUtil.tokenFeature(tokens[index + 2]); features.add("wc,nwc,nnwc=" + wc + "," + nwc + "," + nnwc); } } }
TrigramNameFeatureGenerator implements AdaptiveFeatureGenerator { public void createFeatures(List<String> features, String[] tokens, int index, String[] previousOutcomes) { String wc = FeatureGeneratorUtil.tokenFeature(tokens[index]); if (index > 1) { features.add("ppw,pw,w=" + tokens[index - 2] + "," + tokens[index - 1] + "," + tokens[index]); String pwc = FeatureGeneratorUtil.tokenFeature(tokens[index - 1]); String ppwc = FeatureGeneratorUtil.tokenFeature(tokens[index - 2]); features.add("ppwc,pwc,wc=" + ppwc + "," + pwc + "," + wc); } if (index + 2 < tokens.length) { features.add("w,nw,nnw=" + tokens[index] + "," + tokens[index + 1] + "," + tokens[index + 2]); String nwc = FeatureGeneratorUtil.tokenFeature(tokens[index + 1]); String nnwc = FeatureGeneratorUtil.tokenFeature(tokens[index + 2]); features.add("wc,nwc,nnwc=" + wc + "," + nwc + "," + nnwc); } }  }
TrigramNameFeatureGenerator implements AdaptiveFeatureGenerator { public void createFeatures(List<String> features, String[] tokens, int index, String[] previousOutcomes) { String wc = FeatureGeneratorUtil.tokenFeature(tokens[index]); if (index > 1) { features.add("ppw,pw,w=" + tokens[index - 2] + "," + tokens[index - 1] + "," + tokens[index]); String pwc = FeatureGeneratorUtil.tokenFeature(tokens[index - 1]); String ppwc = FeatureGeneratorUtil.tokenFeature(tokens[index - 2]); features.add("ppwc,pwc,wc=" + ppwc + "," + pwc + "," + wc); } if (index + 2 < tokens.length) { features.add("w,nw,nnw=" + tokens[index] + "," + tokens[index + 1] + "," + tokens[index + 2]); String nwc = FeatureGeneratorUtil.tokenFeature(tokens[index + 1]); String nnwc = FeatureGeneratorUtil.tokenFeature(tokens[index + 2]); features.add("wc,nwc,nnwc=" + wc + "," + nwc + "," + nnwc); } }  void createFeatures(List<String> features, String[] tokens, int index,
      String[] previousOutcomes); }
TrigramNameFeatureGenerator implements AdaptiveFeatureGenerator { public void createFeatures(List<String> features, String[] tokens, int index, String[] previousOutcomes) { String wc = FeatureGeneratorUtil.tokenFeature(tokens[index]); if (index > 1) { features.add("ppw,pw,w=" + tokens[index - 2] + "," + tokens[index - 1] + "," + tokens[index]); String pwc = FeatureGeneratorUtil.tokenFeature(tokens[index - 1]); String ppwc = FeatureGeneratorUtil.tokenFeature(tokens[index - 2]); features.add("ppwc,pwc,wc=" + ppwc + "," + pwc + "," + wc); } if (index + 2 < tokens.length) { features.add("w,nw,nnw=" + tokens[index] + "," + tokens[index + 1] + "," + tokens[index + 2]); String nwc = FeatureGeneratorUtil.tokenFeature(tokens[index + 1]); String nnwc = FeatureGeneratorUtil.tokenFeature(tokens[index + 2]); features.add("wc,nwc,nnwc=" + wc + "," + nwc + "," + nnwc); } }  void createFeatures(List<String> features, String[] tokens, int index,
      String[] previousOutcomes);  }