use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.View in project cogcomp-nlp by CogComp.
the class TestSrlVerbArgumentFeatures method test.
/**
* Only in and out relations in the SRL_VERB view are used for the purpose of testing.
*
*/
public final void test() throws Exception {
logger.info("ArgumentFeatures Feature Extractor");
String[] viewsToAdd = { ViewNames.POS, ViewNames.LEMMA, ViewNames.SHALLOW_PARSE, ViewNames.PARSE_GOLD, ViewNames.SRL_VERB, ViewNames.PARSE_STANFORD, ViewNames.NER_CONLL };
TextAnnotation ta = DummyTextAnnotationGenerator.generateAnnotatedTextAnnotation(viewsToAdd, true, 3);
int i = 0;
ta.addView(ClauseViewGenerator.STANFORD);
ta.addView(PseudoParse.STANFORD);
logger.info("This textannotation annotates the text: \n" + ta.getText());
View SRL_VERB = ta.getView("SRL_VERB");
List<Constituent> testlist = SRL_VERB.getConstituentsCoveringSpan(10, 13);
testlist.addAll(SRL_VERB.getConstituentsCoveringSpan(26, 27));
FeatureManifest featureManifest;
FeatureExtractor fex;
String fileName = Constant.prefix + "/Verb/Classifier/arg-features.fex";
featureManifest = new FeatureManifest(new FileInputStream(fileName));
FeatureManifest.setFeatureExtractor("hyphen-argument-feature", FeatureGenerators.hyphenTagFeature);
FeatureManifest.setTransformer("parse-left-sibling", FeatureGenerators.getParseLeftSibling(ViewNames.PARSE_STANFORD));
FeatureManifest.setTransformer("parse-right-sibling", FeatureGenerators.getParseRightSibling(ViewNames.PARSE_STANFORD));
FeatureManifest.setFeatureExtractor("pp-features", FeatureGenerators.ppFeatures(ViewNames.PARSE_STANFORD));
FeatureManifest.setFeatureExtractor("projected-path", new ProjectedPath(ViewNames.PARSE_STANFORD));
featureManifest.useCompressedName();
featureManifest.setVariable("*default-parser*", ViewNames.PARSE_STANFORD);
fex = featureManifest.createFex();
SrlVerbArgumentFeatures af = new SrlVerbArgumentFeatures();
for (Constituent test : testlist) {
assertTrue(SRLFeaturesComparator.isEqual(test, fex, af));
}
}
use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.View in project cogcomp-nlp by CogComp.
the class TestSrlVerbIdentifierArgumentFeatures method test.
/**
* Only in and out relations in the SRL_VERB view are used for the purpose of testing.
*
*/
public final void test() throws Exception {
logger.info("ArgumentFeatures Feature Extractor");
String[] viewsToAdd = { ViewNames.POS, ViewNames.LEMMA, ViewNames.SHALLOW_PARSE, ViewNames.PARSE_GOLD, ViewNames.SRL_VERB, ViewNames.PARSE_STANFORD, ViewNames.NER_CONLL };
TextAnnotation ta = DummyTextAnnotationGenerator.generateAnnotatedTextAnnotation(viewsToAdd, true, 3);
int i = 0;
ta.addView(ClauseViewGenerator.STANFORD);
ta.addView(PseudoParse.STANFORD);
logger.info("This textannotation annotates the text: \n" + ta.getText());
View SRL_VERB = ta.getView("SRL_VERB");
List<Constituent> testlist = SRL_VERB.getConstituentsCoveringSpan(10, 13);
testlist.addAll(SRL_VERB.getConstituentsCoveringSpan(26, 27));
FeatureManifest featureManifest;
FeatureExtractor fex;
String fileName = Constant.prefix + "/Verb/Identifier/arg-features.fex";
featureManifest = new FeatureManifest(new FileInputStream(fileName));
FeatureManifest.setFeatureExtractor("hyphen-argument-feature", FeatureGenerators.hyphenTagFeature);
FeatureManifest.setTransformer("parse-left-sibling", FeatureGenerators.getParseLeftSibling(ViewNames.PARSE_STANFORD));
FeatureManifest.setTransformer("parse-right-sibling", FeatureGenerators.getParseRightSibling(ViewNames.PARSE_STANFORD));
FeatureManifest.setFeatureExtractor("pp-features", FeatureGenerators.ppFeatures(ViewNames.PARSE_STANFORD));
FeatureManifest.setFeatureExtractor("projected-path", new ProjectedPath(ViewNames.PARSE_STANFORD));
featureManifest.useCompressedName();
featureManifest.setVariable("*default-parser*", ViewNames.PARSE_STANFORD);
fex = featureManifest.createFex();
SrlVerbIdentifierArgumentFeatures af = new SrlVerbIdentifierArgumentFeatures();
for (Constituent test : testlist) {
assertTrue(SRLFeaturesComparator.isNoCacheEqual(test, fex, af));
}
}
use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.View in project cogcomp-nlp by CogComp.
the class TestPOSWindow method test.
@Test
public final void test() throws Exception {
logger.info("POSWindow 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());
POSBaseLineCounter posBaseLine = new POSBaseLineCounter("posBaseLine");
posBaseLine.buildTable(TestPosHelper.corpus);
POSMikheevCounter posMikheev = new POSMikheevCounter("posMikheev");
posMikheev.buildTable(TestPosHelper.corpus);
POSWindow posWindowPOS = new POSWindow("posWindowPOS");
POSWindow posWindowPOSBaseLine = new POSWindow("posWindowPOSBaseLine", posBaseLine);
POSWindow posWindowPOSMikheev = new POSWindow("posWindowPOSMikheev", posMikheev);
// Test when using POS View
ArrayList<Set<Feature>> featslist = new ArrayList<>();
for (Constituent test : testlist) featslist.add(posWindowPOS.getFeatures(test));
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) {
logger.info("\n");
for (Feature f : feats) logger.info(f.getName());
}
// Test when using POS baseline Counting
featslist.clear();
for (Constituent test : testlist) featslist.add(posWindowPOSBaseLine.getFeatures(test));
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) {
logger.info("\n");
for (Feature f : feats) logger.info(f.getName());
}
// Test when using POS Mikheev Counting
featslist.clear();
for (Constituent test : testlist) featslist.add(posWindowPOSMikheev.getFeatures(test));
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) {
logger.info("\n");
for (Feature f : feats) logger.info(f.getName());
}
logger.info("GOT FEATURES YES!");
}
use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.View in project cogcomp-nlp by CogComp.
the class TestPOSandPositionWindowThree method test.
@Test
public final void test() throws EdisonException {
log.debug("POSWindowpp 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");
log.debug("GOT TOKENS FROM TEXTAnn");
List<Constituent> testlist = TOKENS.getConstituentsCoveringSpan(0, 20);
for (Constituent c : testlist) {
log.debug(c.getSurfaceForm());
}
log.debug("Testlist size is " + testlist.size());
Constituent test = testlist.get(1);
log.debug("The constituent we are extracting features from in this test is: " + test.getSurfaceForm());
POSandPositionWindowThree POSWpp = new POSandPositionWindowThree("POSandPositionWindowThree");
// Formpp.initViews(test);
log.debug("Startspan is " + test.getStartSpan() + " and Endspan is " + test.getEndSpan());
Set<Feature> feats = POSWpp.getFeatures(test);
String[] expected_outputs = { "POSandPositionWindowThree:0_0(DT)", "POSandPositionWindowThree:1_0(VBZ)", "POSandPositionWindowThree:2_0(DT)", "POSandPositionWindowThree:3_0(NN)", "POSandPositionWindowThree:4_0(.)", "POSandPositionWindowThree:5_0(null)", "POSandPositionWindowThree:6_0(null)", "POSandPositionWindowThree:0_1(DT_VBZ)", "POSandPositionWindowThree:1_1(VBZ_DT)", "POSandPositionWindowThree:2_1(DT_NN)", "POSandPositionWindowThree:3_1(NN_.)", "POSandPositionWindowThree:4_1(._null)", "POSandPositionWindowThree:5_1(null_null)", "POSandPositionWindowThree:6_1(null)", "POSandPositionWindowThree:0_2(DT_VBZ_DT)", "POSandPositionWindowThree:1_2(VBZ_DT_NN)", "POSandPositionWindowThree:2_2(DT_NN_.)", "POSandPositionWindowThree:3_2(NN_._null)", "POSandPositionWindowThree:4_2(._null_null)", "POSandPositionWindowThree:5_2(null_null)", "POSandPositionWindowThree:6_2(null)" };
if (feats == null) {
log.debug("Feats are returning NULL.");
}
log.debug("Printing Set of Features");
for (Feature f : feats) {
log.debug(f.getName());
assert (ArrayUtils.contains(expected_outputs, f.getName()));
}
log.debug("GOT FEATURES YES!");
// System.exit(0);
}
Aggregations