use of edu.illinois.cs.cogcomp.edison.utilities.EdisonException in project cogcomp-nlp by CogComp.
the class FeatureManifest method trigrams.
private FeatureExtractor trigrams(Tree<String> tree, Map<String, FeatureExtractor> cf) throws EdisonException {
String uniqueLabel = uniquify(tree);
if (cf.containsKey(uniqueLabel))
return cf.get(uniqueLabel);
if (tree.getNumberOfChildren() != 1) {
throw new EdisonException("trigrams takes exactly one argument\n" + tree);
}
FeatureExtractor fex = NgramFeatureExtractor.trigrams(getWordFex(createFex(tree.getChild(0), cf)));
CachedFeatureCollection cfx = new CachedFeatureCollection("", fex);
cf.put(uniquify(tree), cfx);
return cfx;
}
use of edu.illinois.cs.cogcomp.edison.utilities.EdisonException in project cogcomp-nlp by CogComp.
the class TestParseFeatures method testFex.
private void testFex(FeatureExtractor fex, boolean printBoth, Set<String> validResponses) throws EdisonException {
TextAnnotation ta = tas.get(annotatedTAIndex);
if (!ta.hasView(ViewNames.SRL_VERB))
throw new EdisonException("SRL_VERB view is missing");
PredicateArgumentView pav = (PredicateArgumentView) ta.getView(ViewNames.SRL_VERB);
for (Constituent predicate : pav.getPredicates()) {
Constituent p = predicate.cloneForNewView("dummy");
for (Relation argument : pav.getArguments(predicate)) {
Constituent c = argument.getTarget().cloneForNewView("dummy");
Relation r = new Relation("", p, c, 1);
String response = (printBoth ? r : c) + "\t" + fex.getFeatures(c);
assertTrue("Response should be one of the valid responses", validResponses.contains(response));
}
}
}
use of edu.illinois.cs.cogcomp.edison.utilities.EdisonException in project cogcomp-nlp by CogComp.
the class TestContextFeatureExtractor method testGetFeaturesIndexWithoutConstituent.
@Test
public void testGetFeaturesIndexWithoutConstituent() throws EdisonException {
ContextFeatureExtractor fex = new ContextFeatureExtractor(2, true, true);
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", "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", "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 LBJavaFeatureExtractor method classify.
@Override
public FeatureVector classify(Object o) {
// Make sure the object is a Constituent
if (!(o instanceof Constituent))
throw new IllegalArgumentException("Instance must be of type Constituent");
Constituent instance = (Constituent) o;
FeatureVector featureVector;
try {
featureVector = FeatureUtilities.getLBJFeatures(getFeatures(instance));
} catch (EdisonException e) {
throw new RuntimeException(e);
}
return featureVector;
}
use of edu.illinois.cs.cogcomp.edison.utilities.EdisonException in project cogcomp-nlp by CogComp.
the class TestLabelOneAfter method test.
public final void test() {
logger.info("LabelOneAfter Feature Extractor");
// Using the first TA and a constituent between span of 30-40 as a test
TextAnnotation ta = tas.get(2);
View TOKENS = ta.getView("TOKENS");
logger.info("GOT TOKENS FROM TEXTAnn");
List<Constituent> testlist = TOKENS.getConstituentsCoveringSpan(0, 20);
for (Constituent c : testlist) {
logger.info(c.getSurfaceForm());
}
logger.info("Testlist size is " + testlist.size());
// Constituent test = testlist.get(1);
// logger.info("The constituent we are extracting features from
// in this test is: " + test.getSurfaceForm());
// String fileName =
// "C:\\Users\\Jason\\Desktop\\UIUC 2015 Fall\\Cogcomp\\pos-translation\\pos";
POSBaseLineCounter posBaseLine = new POSBaseLineCounter("posBaseLine");
try {
posBaseLine.buildTable(TestPosHelper.corpus);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
POSMikheevCounter posMikheev = new POSMikheevCounter("posMikheev");
try {
posMikheev.buildTable(TestPosHelper.corpus);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
LabelOneAfter l1aPOS = new LabelOneAfter("l1aPOS");
LabelOneAfter l1aPOSBaseLine = new LabelOneAfter("l1aPOSBaseLine", posBaseLine);
LabelOneAfter l1aPOSMikheev = new LabelOneAfter("l1aPOSMikheev", posMikheev);
// Test when using POS View
ArrayList<Set<Feature>> featslist = new ArrayList<>();
for (Constituent test : testlist) try {
featslist.add(l1aPOS.getFeatures(test));
} catch (EdisonException e) {
fail(e.getMessage());
}
if (featslist.isEmpty()) {
logger.info("Feats list is returning NULL.");
}
logger.info("\n" + "Test when using POS View");
logger.info("Printing list of Feature set");
for (Set<Feature> feats : featslist) {
for (Feature f : feats) logger.info(f.getName());
}
// Test when using POS baseline Counting
featslist.clear();
for (Constituent test : testlist) try {
featslist.add(l1aPOSBaseLine.getFeatures(test));
} catch (EdisonException e) {
e.printStackTrace();
fail(e.getMessage());
}
if (featslist.isEmpty()) {
logger.info("Feats list is returning NULL.");
}
logger.info("\n" + "Test when using POS baseline Counting");
logger.info("Printing list of Feature set");
for (Set<Feature> feats : featslist) {
for (Feature f : feats) logger.info(f.getName());
}
// Test when using POS Mikheev Counting
featslist.clear();
for (Constituent test : testlist) try {
featslist.add(l1aPOSMikheev.getFeatures(test));
} catch (EdisonException e) {
e.printStackTrace();
fail(e.getMessage());
}
if (featslist.isEmpty()) {
logger.info("Feats list is returning NULL.");
}
logger.info("\n" + "Test when using POS Mikheev Counting");
logger.info("Printing list of Feature set");
for (Set<Feature> feats : featslist) {
for (Feature f : feats) logger.info(f.getName());
}
logger.info("GOT FEATURES YES!");
}
Aggregations