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 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);
}
}
}
}
use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation in project cogcomp-nlp by CogComp.
the class TestSyntacticFrame method testFex.
private void testFex(FeatureExtractor fex) throws Exception {
for (TextAnnotation ta : tas) {
if (!ta.hasView(ViewNames.PARSE_CHARNIAK))
continue;
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);
assertEquals(3, features.size());
}
}
}
}
use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation in project cogcomp-nlp by CogComp.
the class StanfordOpenIEHandler method addView.
@Override
protected void addView(TextAnnotation ta) throws AnnotatorException {
Annotation document = new Annotation(ta.text);
pipeline.annotate(document);
SpanLabelView vu = new SpanLabelView(viewName, ta);
for (CoreMap sentence : document.get(CoreAnnotations.SentencesAnnotation.class)) {
Collection<RelationTriple> triples = sentence.get(NaturalLogicAnnotations.RelationTriplesAnnotation.class);
for (RelationTriple triple : triples) {
Constituent subject = getConstituent(triple.subjectGloss(), triple.subjectTokenSpan(), sentence, ta);
subject.addAttribute("subjectGloss", triple.subjectGloss());
subject.addAttribute("subjectLemmaGloss", triple.subjectLemmaGloss());
subject.addAttribute("subjectLink", triple.subjectLink());
Constituent object = getConstituent(triple.objectGloss(), triple.objectTokenSpan(), sentence, ta);
object.addAttribute("objectGloss", triple.objectGloss());
object.addAttribute("objectLemmaGloss", triple.objectLemmaGloss());
object.addAttribute("objectLink", triple.objectLink());
Constituent relation = getConstituent(triple.relationGloss(), triple.relationTokenSpan(), sentence, ta);
relation.addAttribute("relationGloss", triple.relationGloss());
relation.addAttribute("relationLemmaGloss", triple.relationLemmaGloss());
Relation subj = new Relation("subj", relation, subject, triple.confidence);
Relation obj = new Relation("obj", relation, object, triple.confidence);
vu.addRelation(subj);
vu.addRelation(obj);
vu.addConstituent(subject);
vu.addConstituent(object);
vu.addConstituent(relation);
}
}
ta.addView(viewName, vu);
}
Aggregations