RogetThesaurusFeatures implements FeatureExtractor { @Override public Set<Feature> getFeatures(Constituent c) throws EdisonException { if (!loaded) { try { loadFromDatastore(); } catch (Exception e) { throw new EdisonException(e); } } String s = c.getTokenizedSurfaceForm().trim(); Set<Feature> features = new LinkedHashSet<>(); if (map.containsKey(s)) { for (int i : map.get(s)) { features.add(DiscreteFeature.create(this.id2ClassName.get(i))); } } else if (map.containsKey(s.toLowerCase())) { for (int i : map.get(s.toLowerCase())) { features.add(DiscreteFeature.create(this.id2ClassName.get(i))); } } return features; } RogetThesaurusFeatures(); @Override Set<Feature> getFeatures(Constituent c); @Override String getName(); static final RogetThesaurusFeatures INSTANCE; }
@Test public final void test() throws Exception { RogetThesaurusFeatures fe = RogetThesaurusFeatures.INSTANCE; for (Constituent c : ta.getView(ViewNames.TOKENS)) { if(goldAns.containsKey(c.getSurfaceForm().toLowerCase())) { assertTrue(goldAns.get(c.getSurfaceForm().toLowerCase()).toString().equals(fe.getFeatures(c).toString())); } } }