Search in sources :

Example 16 with Relation

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Relation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation) TreeView(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TreeView) EdisonException(edu.illinois.cs.cogcomp.edison.utilities.EdisonException) DiscreteFeature(edu.illinois.cs.cogcomp.edison.features.DiscreteFeature) Feature(edu.illinois.cs.cogcomp.edison.features.Feature) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent) EdisonException(edu.illinois.cs.cogcomp.edison.utilities.EdisonException)

Example 17 with Relation

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);
}
Also used : Relation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)

Example 18 with Relation

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) Feature(edu.illinois.cs.cogcomp.edison.features.Feature) Relation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation) TreeView(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TreeView) ArrayList(java.util.ArrayList) List(java.util.List) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)

Example 19 with Relation

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Relation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation) DiscreteFeature(edu.illinois.cs.cogcomp.edison.features.DiscreteFeature) Feature(edu.illinois.cs.cogcomp.edison.features.Feature) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)

Example 20 with Relation

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;
}
Also used : Relation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)

Aggregations

Relation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation)26 Constituent (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)25 TextAnnotation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation)16 Feature (edu.illinois.cs.cogcomp.edison.features.Feature)10 TreeView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TreeView)9 EdisonException (edu.illinois.cs.cogcomp.edison.utilities.EdisonException)8 DiscreteFeature (edu.illinois.cs.cogcomp.edison.features.DiscreteFeature)7 ArrayList (java.util.ArrayList)7 LinkedHashSet (java.util.LinkedHashSet)7 PredicateArgumentView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.PredicateArgumentView)5 JsonObject (com.google.gson.JsonObject)3 View (edu.illinois.cs.cogcomp.core.datastructures.textannotation.View)3 Test (org.junit.Test)3 JsonParser (com.google.gson.JsonParser)2 SpanLabelView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.SpanLabelView)2 Tree (edu.illinois.cs.cogcomp.core.datastructures.trees.Tree)2 CoreAnnotations (edu.stanford.nlp.ling.CoreAnnotations)2 Annotation (edu.stanford.nlp.pipeline.Annotation)2 CoreMap (edu.stanford.nlp.util.CoreMap)2 HashSet (java.util.HashSet)2