use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation in project cogcomp-nlp by CogComp.
the class SubcategorizationFrame method getFeatures.
@Override
public Set<Feature> getFeatures(Constituent c) throws EdisonException {
Set<Feature> features = new LinkedHashSet<>();
TreeView view = (TreeView) c.getTextAnnotation().getView(parseViewName);
Constituent phrase;
try {
phrase = view.getParsePhrase(c);
} catch (Exception e) {
throw new EdisonException(e);
}
List<Relation> incomingRelations = phrase.getIncomingRelations();
if (incomingRelations == null) {
features.add(DiscreteFeature.create("root"));
} else {
Constituent parent = incomingRelations.get(0).getSource();
StringBuilder subcat = new StringBuilder();
subcat.append(parent.getLabel()).append(">");
for (Relation r : parent.getOutgoingRelations()) {
if (r.getTarget() == phrase) {
subcat.append("(").append(r.getTarget().getLabel()).append(")");
} else {
subcat.append(r.getTarget().getLabel());
}
}
features.add(DiscreteFeature.create(subcat.toString()));
}
return features;
}
use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation in project cogcomp-nlp by CogComp.
the class CandidateBoundaryTransformer method transform.
@Override
public List<Constituent> transform(Constituent input) {
TextAnnotation ta = input.getTextAnnotation();
Constituent ce = new Constituent("", "", ta, input.getEndSpan() - 1, input.getEndSpan());
Constituent cs = new Constituent("", "", ta, input.getStartSpan(), input.getStartSpan() + 1);
new Relation("", cs, ce, 0);
return Collections.singletonList(ce);
}
use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation in project cogcomp-nlp by CogComp.
the class DependencyPathNgrams method getFeatures.
@Override
public Set<Feature> getFeatures(Constituent c) throws EdisonException {
TextAnnotation ta = c.getTextAnnotation();
Set<Feature> features = new LinkedHashSet<>();
TreeView parse = (TreeView) ta.getView(dependencyViewName);
// get equivalent of c in the parse view
Constituent c2 = parse.getConstituentsCoveringToken(c.getStartSpan()).get(0);
List<Relation> incomingRelations = c2.getIncomingRelations();
if (incomingRelations.size() > 0) {
Constituent c1 = parse.getConstituentsCoveringToken(incomingRelations.get(0).getSource().getStartSpan()).get(0);
Pair<List<Constituent>, List<Constituent>> paths = PathFeatureHelper.getPathsToCommonAncestor(c1, c2, 400);
List<String> path = new ArrayList<>();
List<String> pos = new ArrayList<>();
for (int i = 0; i < paths.getFirst().size() - 1; i++) {
Constituent cc = paths.getFirst().get(i);
path.add(cc.getIncomingRelations().get(0).getRelationName() + PathFeatureHelper.PATH_UP_STRING);
pos.add(WordHelpers.getPOS(ta, cc.getStartSpan()) + ":" + cc.getIncomingRelations().get(0).getRelationName() + PathFeatureHelper.PATH_UP_STRING);
}
Constituent top = paths.getFirst().get(paths.getFirst().size() - 1);
pos.add(WordHelpers.getPOS(ta, top.getStartSpan()) + ":*");
path.add("*");
if (paths.getSecond().size() > 1) {
for (int i = paths.getSecond().size() - 2; i >= 0; i--) {
Constituent cc = paths.getSecond().get(i);
pos.add(WordHelpers.getPOS(ta, cc.getStartSpan()) + ":" + PathFeatureHelper.PATH_DOWN_STRING);
path.add(PathFeatureHelper.PATH_DOWN_STRING);
}
}
features.addAll(getNgrams(path, ""));
features.addAll(getNgrams(pos, "pos"));
}
return features;
}
use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation in project cogcomp-nlp by CogComp.
the class LinearPosition method getFeatures.
@Override
public Set<Feature> getFeatures(Constituent c) throws EdisonException {
List<Relation> incomingRelation = c.getIncomingRelations();
Set<Feature> features = new LinkedHashSet<>();
if (incomingRelation.size() > 0) {
Constituent predicate = incomingRelation.get(0).getSource();
if (predicate.getStartSpan() >= c.getEndSpan())
features.add(BEFORE);
else if (c.getStartSpan() >= predicate.getEndSpan())
features.add(AFTER);
else
features.add(CONTAINS);
}
return features;
}
use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation in project cogcomp-nlp by CogComp.
the class PrepSRLFeatures method addIncomingRelation.
private static Constituent addIncomingRelation(Constituent input, Constituent c) {
Constituent i = input.cloneForNewView("");
Constituent c1 = c.cloneForNewView("");
new Relation("", i, c1, 0d);
return c1;
}
Aggregations