use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.View in project cogcomp-nlp by CogComp.
the class TestWordTypeInformation method test.
@Test
public final void test() throws EdisonException {
log.debug("WordTypeInformation");
// Using the first TA and a constituent between span of 0 - 20 as a test
TextAnnotation ta = tas.get(1);
View TOKENS = ta.getView("TOKENS");
log.debug("GOT TOKENS FROM TEXTAnn");
List<Constituent> testlist = TOKENS.getConstituentsCoveringSpan(0, 20);
String[] teststrings = new String[5];
int i = 0, start = 1, end = 6;
for (Constituent c : testlist) {
log.debug(c.getSurfaceForm());
if (i >= start && i < end) {
teststrings[i - start] = c.getSurfaceForm();
}
i++;
}
log.debug("Testlist size is " + testlist.size());
Constituent test = testlist.get(3);
log.debug("The constituent we are extracting features from in this test is: " + test.getSurfaceForm());
WordTypeInformation wti = new WordTypeInformation("WordTypeInformation");
log.debug("Startspan is " + test.getStartSpan() + " and Endspan is " + test.getEndSpan());
Set<Feature> feats = wti.getFeatures(test);
String[] expected_outputs = { "WordTypeInformation:c0(false)", "WordTypeInformation:d0(false)", "WordTypeInformation:c1(false)", "WordTypeInformation:d1(false)", "WordTypeInformation:c2(false)", "WordTypeInformation:d2(false)", "WordTypeInformation:c2(true)", "WordTypeInformation:c3(false)", "WordTypeInformation:d3(false)", "WordTypeInformation:c4(false)", "WordTypeInformation:d4(false)", "WordTypeInformation:c4(true)" };
Set<String> __result = new LinkedHashSet<String>();
String __id;
String __value;
String classifier = "WordTypeInformation";
if (feats == null) {
log.debug("Feats are returning NULL.");
assertFalse(true);
}
log.debug("Printing Set of Features");
for (Feature f : feats) {
log.debug(f.getName());
assert (ArrayUtils.contains(expected_outputs, f.getName()));
}
for (; (start < end && teststrings[start - 1] != null); start++) {
boolean allCapitalized = true, allDigits = true, allNonLetters = true;
for (int j = 0; j < teststrings[start - 1].length(); ++j) {
allCapitalized &= Character.isUpperCase(teststrings[start - 1].charAt(j));
allDigits &= Character.isDigit(teststrings[start - 1].charAt(j));
allNonLetters &= !Character.isLetter(teststrings[start - 1].charAt(j));
}
__id = classifier + ":" + ("c" + (start - 1));
__value = "(" + (allCapitalized) + ")";
__result.add(__id + __value);
__id = classifier + ":" + ("d" + (start - 1));
__value = "(" + (allDigits) + ")";
__result.add(__id + __value);
__id = classifier + ":" + ("c" + (start - 1));
__value = "(" + (allNonLetters) + ")";
__result.add(__id + __value);
}
for (Feature feat : feats) {
if (!__result.contains(feat.getName())) {
assertFalse(true);
}
}
// System.exit(0);
}
use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.View in project cogcomp-nlp by CogComp.
the class TestSrlNomArgumentFeatures 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);
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 + "/Nom/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();
SrlNomArgumentFeatures af = new SrlNomArgumentFeatures();
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 TestSrlNomClassifierPredicateFeatures 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("PredicateFeatures 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 + "/Nom/Classifier/predicate-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();
SrlNomClassifierPredicateFeatures pf = new SrlNomClassifierPredicateFeatures();
for (Constituent test : testlist) {
assertTrue(SRLFeaturesComparator.isEqual(test, fex, pf));
}
}
use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.View in project cogcomp-nlp by CogComp.
the class TestSrlNomHeadWordFeatures method test.
public final void test() throws Exception {
logger.info("HeadWordFeatures 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 TOKENS = ta.getView("TOKENS");
List<Constituent> testlist = TOKENS.getConstituentsCoveringSpan(10, 13);
testlist.addAll(TOKENS.getConstituentsCoveringSpan(26, 27));
FeatureManifest featureManifest;
FeatureExtractor fex;
String fileName = Constant.prefix + "/Nom/Identifier/head-word-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();
SrlNomHeadWordFeatures hwf = new SrlNomHeadWordFeatures();
for (Constituent test : testlist) {
assertTrue(SRLFeaturesComparator.isEqual(test, fex, hwf));
}
}
use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.View in project cogcomp-nlp by CogComp.
the class TestSrlNomIdentifierPredicateFeatures method test.
public final void test() throws Exception {
logger.info("PredicateFeatures 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 TOKENS = ta.getView("TOKENS");
List<Constituent> testlist = TOKENS.getConstituentsCoveringSpan(10, 13);
testlist.addAll(TOKENS.getConstituentsCoveringSpan(26, 27));
FeatureManifest featureManifest;
FeatureExtractor fex;
String fileName = Constant.prefix + "/Nom/Identifier/predicate-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();
SrlNomIdentifierPredicateFeatures pf = new SrlNomIdentifierPredicateFeatures();
for (Constituent test : testlist) {
assertTrue(SRLFeaturesComparator.isEqual(test, fex, pf));
}
}
Aggregations