@Test public void testForCorrectFeatures() { AdaptiveFeatureGenerator windowFeatureGenerator = new WindowFeatureGenerator( new IdentityFeatureGenerator(), 2, 2); int testTokenIndex = 3; windowFeatureGenerator.createFeatures(features, testSentence, testTokenIndex, null); Assert.assertEquals(5, features.size()); Assert.assertEquals("d", features.get(0)); Assert.assertEquals("p1c", features.get(1)); Assert.assertEquals("p2b", features.get(2)); Assert.assertEquals("n1e", features.get(3)); Assert.assertEquals("n2f", features.get(4)); }
public void createFeatures(List<String> features, String[] tokens, int index, String[] preds) { generator.createFeatures(features, tokens, index, preds); for (int i = 1; i < prevWindowSize + 1; i++) { if (index - i >= 0) { List<String> prevFeatures = new ArrayList<>(); generator.createFeatures(prevFeatures, tokens, index - i, preds); for (String prevFeature : prevFeatures) { features.add(PREV_PREFIX + i + prevFeature); } } } for (int i = 1; i < nextWindowSize + 1; i++) { if (i + index < tokens.length) { List<String> nextFeatures = new ArrayList<>(); generator.createFeatures(nextFeatures, tokens, index + i, preds); for (String nextFeature : nextFeatures) { features.add(NEXT_PREFIX + i + nextFeature); } } } }
WindowFeatureGenerator implements AdaptiveFeatureGenerator { public void createFeatures(List<String> features, String[] tokens, int index, String[] preds) { generator.createFeatures(features, tokens, index, preds); for (int i = 1; i < prevWindowSize + 1; i++) { if (index - i >= 0) { List<String> prevFeatures = new ArrayList<>(); generator.createFeatures(prevFeatures, tokens, index - i, preds); for (String prevFeature : prevFeatures) { features.add(PREV_PREFIX + i + prevFeature); } } } for (int i = 1; i < nextWindowSize + 1; i++) { if (i + index < tokens.length) { List<String> nextFeatures = new ArrayList<>(); generator.createFeatures(nextFeatures, tokens, index + i, preds); for (String nextFeature : nextFeatures) { features.add(NEXT_PREFIX + i + nextFeature); } } } } }
WindowFeatureGenerator implements AdaptiveFeatureGenerator { public void createFeatures(List<String> features, String[] tokens, int index, String[] preds) { generator.createFeatures(features, tokens, index, preds); for (int i = 1; i < prevWindowSize + 1; i++) { if (index - i >= 0) { List<String> prevFeatures = new ArrayList<>(); generator.createFeatures(prevFeatures, tokens, index - i, preds); for (String prevFeature : prevFeatures) { features.add(PREV_PREFIX + i + prevFeature); } } } for (int i = 1; i < nextWindowSize + 1; i++) { if (i + index < tokens.length) { List<String> nextFeatures = new ArrayList<>(); generator.createFeatures(nextFeatures, tokens, index + i, preds); for (String nextFeature : nextFeatures) { features.add(NEXT_PREFIX + i + nextFeature); } } } } WindowFeatureGenerator(AdaptiveFeatureGenerator generator, int prevWindowSize,  int nextWindowSize);  WindowFeatureGenerator(int prevWindowSize, int nextWindowSize,
      AdaptiveFeatureGenerator... generators);  WindowFeatureGenerator(AdaptiveFeatureGenerator generator);  WindowFeatureGenerator(AdaptiveFeatureGenerator... generators); }
WindowFeatureGenerator implements AdaptiveFeatureGenerator { public void createFeatures(List<String> features, String[] tokens, int index, String[] preds) { generator.createFeatures(features, tokens, index, preds); for (int i = 1; i < prevWindowSize + 1; i++) { if (index - i >= 0) { List<String> prevFeatures = new ArrayList<>(); generator.createFeatures(prevFeatures, tokens, index - i, preds); for (String prevFeature : prevFeatures) { features.add(PREV_PREFIX + i + prevFeature); } } } for (int i = 1; i < nextWindowSize + 1; i++) { if (i + index < tokens.length) { List<String> nextFeatures = new ArrayList<>(); generator.createFeatures(nextFeatures, tokens, index + i, preds); for (String nextFeature : nextFeatures) { features.add(NEXT_PREFIX + i + nextFeature); } } } } WindowFeatureGenerator(AdaptiveFeatureGenerator generator, int prevWindowSize,  int nextWindowSize);  WindowFeatureGenerator(int prevWindowSize, int nextWindowSize,
      AdaptiveFeatureGenerator... generators);  WindowFeatureGenerator(AdaptiveFeatureGenerator generator);  WindowFeatureGenerator(AdaptiveFeatureGenerator... generators); void createFeatures(List<String> features, String[] tokens, int index, String[] preds); void updateAdaptiveData(String[] tokens, String[] outcomes); void clearAdaptiveData(); @Override String toString(); }
WindowFeatureGenerator implements AdaptiveFeatureGenerator { public void createFeatures(List<String> features, String[] tokens, int index, String[] preds) { generator.createFeatures(features, tokens, index, preds); for (int i = 1; i < prevWindowSize + 1; i++) { if (index - i >= 0) { List<String> prevFeatures = new ArrayList<>(); generator.createFeatures(prevFeatures, tokens, index - i, preds); for (String prevFeature : prevFeatures) { features.add(PREV_PREFIX + i + prevFeature); } } } for (int i = 1; i < nextWindowSize + 1; i++) { if (i + index < tokens.length) { List<String> nextFeatures = new ArrayList<>(); generator.createFeatures(nextFeatures, tokens, index + i, preds); for (String nextFeature : nextFeatures) { features.add(NEXT_PREFIX + i + nextFeature); } } } } WindowFeatureGenerator(AdaptiveFeatureGenerator generator, int prevWindowSize,  int nextWindowSize);  WindowFeatureGenerator(int prevWindowSize, int nextWindowSize,
      AdaptiveFeatureGenerator... generators);  WindowFeatureGenerator(AdaptiveFeatureGenerator generator);  WindowFeatureGenerator(AdaptiveFeatureGenerator... generators); void createFeatures(List<String> features, String[] tokens, int index, String[] preds); void updateAdaptiveData(String[] tokens, String[] outcomes); void clearAdaptiveData(); @Override String toString(); static final String PREV_PREFIX; static final String NEXT_PREFIX; }