use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation in project cogcomp-nlp by CogComp.
the class DependencyModifierFeatureExtractor method getFeatures.
@Override
public Set<Feature> getFeatures(Constituent c) throws EdisonException {
List<Constituent> parents = dependencyHeadIdentifier.transform(c);
Set<Feature> features = new LinkedHashSet<>();
if (parents.size() == 0) {
Constituent parent = parents.get(0);
for (Relation out : parent.getOutgoingRelations()) {
String label = out.getRelationName();
if (label.contains("det") || label.contains("mod") || label.contains("number")) {
features.addAll(FeatureUtilities.prefix(label, baseFex.getFeatures(out.getTarget())));
}
}
}
return features;
}
use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation in project cogcomp-nlp by CogComp.
the class ExtentTester method getFullMention.
/**
* Gets the full mention of the given head
* @param classifier The extent classifier
* @param head The head Constituent
* @param gazetteers gazetteers
* @param brownClusters brownclusters
* @param wordnet wordnet
* @return A Constituent of a full mention (extent included)
* @Note The returned Constituent has Attributes "EntityHeadStartSpan" and "EntityHeadEndSpan"
*/
public static Constituent getFullMention(extent_classifier classifier, Constituent head, Gazetteers gazetteers, BrownClusters brownClusters, WordNetManager wordnet) {
addHeadAttributes(head, gazetteers, brownClusters, wordnet);
View tokenView = head.getTextAnnotation().getView(ViewNames.TOKENS);
int leftIdx = head.getStartSpan() - 1;
while (leftIdx >= tokenView.getStartSpan()) {
Constituent cur = tokenView.getConstituentsCoveringToken(leftIdx).get(0);
addExtentAttributes(cur, gazetteers, brownClusters, wordnet);
Relation candidate = new Relation("UNKNOWN", cur, head, 1.0f);
String prediction = classifier.discreteValue(candidate);
if (prediction.equals("false")) {
leftIdx++;
break;
}
leftIdx--;
}
if (leftIdx < tokenView.getStartSpan()) {
leftIdx = tokenView.getStartSpan();
}
int rightIdx = head.getEndSpan();
while (rightIdx < tokenView.getEndSpan()) {
Constituent cur = tokenView.getConstituentsCoveringToken(rightIdx).get(0);
addExtentAttributes(cur, gazetteers, brownClusters, wordnet);
Relation candidate = new Relation("UNKNOWN", cur, head, 1.0f);
String prediction = classifier.discreteValue(candidate);
if (prediction.equals("false")) {
rightIdx--;
break;
}
rightIdx++;
}
if (rightIdx >= tokenView.getEndSpan()) {
rightIdx = tokenView.getEndSpan() - 1;
}
Constituent fullMention = new Constituent(head.getLabel(), 1.0f, ViewNames.MENTION, head.getTextAnnotation(), leftIdx, rightIdx + 1);
fullMention.addAttribute("EntityHeadStartSpan", Integer.toString(head.getStartSpan()));
fullMention.addAttribute("EntityHeadEndSpan", Integer.toString(head.getEndSpan()));
fullMention.addAttribute("EntityType", head.getAttribute("EntityType"));
fullMention.addAttribute("EntityMentionType", head.getAttribute("EntityMentionType"));
return fullMention;
}
use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation in project cogcomp-nlp by CogComp.
the class TextAnnotationLabelCounter method populateLabelCounts.
/**
* generate the target label/feature counts.
* @param annotationViews map from doc id to set of views containing the annotations (constituents, relations)
* that will be split.
*/
@Override
public void populateLabelCounts(Map<String, Set<View>> annotationViews) {
for (String docId : annotationViews.keySet()) {
Counter<String> docLabelCount = new Counter<>();
labelCounts.put(docId, docLabelCount);
for (View v : annotationViews.get(docId)) {
for (Relation r : v.getRelations()) {
String label = r.getRelationName();
if (useAllLabels || labelsToConsider.contains(label)) {
docLabelCount.incrementCount(label);
labelTotals.incrementCount(label);
}
}
for (Constituent c : v.getConstituents()) {
String label = c.getLabel();
if (useAllLabels || labelsToConsider.contains(label)) {
docLabelCount.incrementCount(label);
labelTotals.incrementCount(label);
}
}
}
}
}
use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation in project cogcomp-nlp by CogComp.
the class ParsePhraseTypeOnlyTest method setUp.
@Before
public void setUp() throws Exception {
String[] viewsToAdd = { ViewNames.PARSE_STANFORD, ViewNames.PARSE_CHARNIAK, ViewNames.PARSE_GOLD, ViewNames.SRL_VERB };
TextAnnotation ta = DummyTextAnnotationGenerator.generateAnnotatedTextAnnotation(viewsToAdd, false, 3);
PredicateArgumentView srlView = (PredicateArgumentView) ta.getView(ViewNames.SRL_VERB);
predicate = srlView.getPredicates().get(0);
List<Relation> arguments = new ArrayList<>(srlView.getArguments(predicate));
// Making the order of arg1 and arg2 deterministic by sorting them according to their relation target.
arguments.sort((o1, o2) -> Integer.compare(o1.getTarget().getStartSpan(), o2.getTarget().getStartSpan()));
arg1 = arguments.get(0).getTarget();
arg2 = arguments.get(1).getTarget();
}
use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation in project cogcomp-nlp by CogComp.
the class TestClauseFeatureExtractor method testFex.
private void testFex(FeatureExtractor fex) throws Exception {
for (TextAnnotation ta : tas) {
if (!ta.hasView(ViewNames.PARSE_CHARNIAK))
continue;
ta.addView(ClauseViewGenerator.CHARNIAK);
ta.addView(PseudoParse.CHARNIAK);
PredicateArgumentView pav = (PredicateArgumentView) ta.getView(ViewNames.SRL_VERB);
for (Constituent predicate : pav.getPredicates()) {
Constituent p = predicate.cloneForNewView("dummy");
for (Relation arg : pav.getArguments(predicate)) {
Constituent c = arg.getTarget().cloneForNewView("dummy");
new Relation("", p, c, 1.0);
Set<Feature> features = fex.getFeatures(c);
logger.info(c + "\t" + features);
}
}
}
}
Aggregations