use of edu.illinois.cs.cogcomp.edison.utilities.EdisonException in project cogcomp-nlp by CogComp.
the class TestContextFeatureExtractor method testGetFeaturesNoIndexWithConstituent.
@Test
public void testGetFeaturesNoIndexWithConstituent() throws EdisonException {
ContextFeatureExtractor fex = new ContextFeatureExtractor(2, false, false);
fex.addFeatureExtractor(new WordFeatureExtractor() {
@Override
public Set<Feature> getWordFeatures(TextAnnotation ta, int wordPosition) throws EdisonException {
String s = WordHelpers.getWord(ta, wordPosition).toLowerCase();
Set<String> ss = new HashSet<>();
ss.add(s);
return FeatureUtilities.getFeatures(ss);
}
});
TextAnnotation ta = TextAnnotationUtilities.createFromTokenizedString("This is a test for the feature extractor .");
Constituent c1 = new Constituent("", "", ta, 2, 3);
Set<String> c1fs = new HashSet<>();
c1fs.addAll(Arrays.asList("context:#word#:this", "context:#word#:is", "context:#word#:a", "context:#word#:test", "context:#word#:for"));
Set<Feature> c1f = FeatureUtilities.getFeatures(c1fs);
c1f.removeAll(fex.getFeatures(c1));
assertEquals(0, c1f.size());
Constituent c2 = new Constituent("", "", ta, 2, 4);
Set<String> c2fs = new HashSet<>();
c2fs.addAll(Arrays.asList("context:#word#:this", "context:#word#:is", "context:#word#:a", "context:#word#:test", "context:#word#:for", "context:#word#:the"));
Set<Feature> c2f = FeatureUtilities.getFeatures(c2fs);
c2f.removeAll(fex.getFeatures(c2));
assertEquals(0, c2f.size());
}
use of edu.illinois.cs.cogcomp.edison.utilities.EdisonException in project cogcomp-nlp by CogComp.
the class TestContextFeatureExtractor method testGetFeaturesNoIndexWithoutConstituent.
@Test
public void testGetFeaturesNoIndexWithoutConstituent() throws EdisonException {
ContextFeatureExtractor fex = new ContextFeatureExtractor(2, false, true);
fex.addFeatureExtractor(new WordFeatureExtractor() {
@Override
public Set<Feature> getWordFeatures(TextAnnotation ta, int wordPosition) throws EdisonException {
String s = WordHelpers.getWord(ta, wordPosition).toLowerCase();
Set<String> ss = new HashSet<>();
ss.add(s);
return FeatureUtilities.getFeatures(ss);
}
});
TextAnnotation ta = TextAnnotationUtilities.createFromTokenizedString("This is a test for the feature extractor .");
Constituent c1 = new Constituent("", "", ta, 2, 3);
Set<String> c1fs = new HashSet<>();
c1fs.addAll(Arrays.asList("context:#word#:this", "context:#word#:is", "context:#word#:test", "context:#word#:for"));
Set<Feature> c1f = FeatureUtilities.getFeatures(c1fs);
c1f.removeAll(fex.getFeatures(c1));
assertEquals(0, c1f.size());
Constituent c2 = new Constituent("", "", ta, 2, 4);
Set<String> c2fs = new HashSet<>();
c2fs.addAll(Arrays.asList("context:#word#:this", "context:#word#:is", "context:#word#:for", "context:#word#:the"));
Set<Feature> c2f = FeatureUtilities.getFeatures(c2fs);
c2f.removeAll(fex.getFeatures(c2));
assertEquals(0, c2f.size());
}
use of edu.illinois.cs.cogcomp.edison.utilities.EdisonException in project cogcomp-nlp by CogComp.
the class TestContextFeatureExtractor method testGetFeaturesIndexWithConstituent.
@Test
public void testGetFeaturesIndexWithConstituent() throws EdisonException {
ContextFeatureExtractor fex = new ContextFeatureExtractor(2, true, false);
fex.addFeatureExtractor(new WordFeatureExtractor() {
@Override
public Set<Feature> getWordFeatures(TextAnnotation ta, int wordPosition) throws EdisonException {
String s = WordHelpers.getWord(ta, wordPosition).toLowerCase();
Set<Feature> ss = new HashSet<>();
ss.add(DiscreteFeature.create(s));
return ss;
}
});
TextAnnotation ta = TextAnnotationUtilities.createFromTokenizedString("This is a test for the feature extractor .");
Constituent c1 = new Constituent("", "", ta, 2, 3);
Set<String> c1fs = new HashSet<>();
c1fs.addAll(Arrays.asList("context-2:#word#:this", "context-1:#word#:is", "context*:#word#:a", "context1:#word#:test", "context2:#word#:for"));
Set<Feature> c1f = FeatureUtilities.getFeatures(c1fs);
Set<Feature> features = fex.getFeatures(c1);
c1f.removeAll(features);
assertEquals(0, c1f.size());
Constituent c2 = new Constituent("", "", ta, 2, 4);
Set<String> c2fs = new HashSet<>();
c2fs.addAll(Arrays.asList("context-2:#word#:this", "context-1:#word#:is", "context*:#word#:a", "context*:#word#:test", "context1:#word#:for", "context2:#word#:the"));
Set<Feature> c2f = FeatureUtilities.getFeatures(c2fs);
c2f.removeAll(fex.getFeatures(c2));
assertEquals(0, c2f.size());
}
use of edu.illinois.cs.cogcomp.edison.utilities.EdisonException in project cogcomp-nlp by CogComp.
the class TestParseFeatures method testSampleAnnotation.
// protected void setUp() throws Exception {
// super.setUp();
// }
@Test
public final void testSampleAnnotation() throws Exception {
TextAnnotation ta = tas.get(annotatedTAIndex);
if (!ta.toString().equals(annotatedString)) {
logger.info("Text Annotation string: \n" + ta.toString());
logger.info("Reference String: \n" + annotatedString);
throw new Exception("The text in the Text Annotation doesn't match the Reference String");
}
if (!ta.hasView(ViewNames.SRL_VERB))
throw new EdisonException("SRL_VERB view is missing");
}
use of edu.illinois.cs.cogcomp.edison.utilities.EdisonException in project cogcomp-nlp by CogComp.
the class FeatureManifest method processConjunction.
private FeatureExtractor processConjunction(Tree<String> tree, Map<String, FeatureExtractor> cf) throws EdisonException {
String uniqueLabel = uniquify(tree);
if (cf.containsKey(uniqueLabel))
return cf.get(uniqueLabel);
if (tree.getNumberOfChildren() == 0) {
throw new EdisonException("Invalid conjunction " + tree);
}
FeatureExtractor fex = createFex(tree.getChild(0), cf);
for (int i = 1; i < tree.getNumberOfChildren(); i++) {
fex = FeatureUtilities.conjoin(fex, createFex(tree.getChild(i), cf));
}
CachedFeatureCollection f = new CachedFeatureCollection("", fex);
cf.put(uniqueLabel, f);
return f;
}
Aggregations