Search in sources :

Example 6 with Constituent

use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent in project cogcomp-nlp by CogComp.

the class FeatureUtilities method getFeaturesFromTextAnnotation.

public static List<String> getFeaturesFromTextAnnotation(final FeatureExtractor fex, TextAnnotation s) {
    List<Constituent> cons = s.getView(ViewNames.TOKENS).getConstituents();
    List<String> features = new ArrayList<>();
    for (Constituent c : cons) {
        try {
            features.addAll(getFeatureSet(fex, c));
        } catch (EdisonException e) {
            e.printStackTrace();
        }
    }
    return features;
}
Also used : ByteString(edu.illinois.cs.cogcomp.lbjava.util.ByteString) EdisonException(edu.illinois.cs.cogcomp.edison.utilities.EdisonException) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)

Example 7 with Constituent

use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent in project cogcomp-nlp by CogComp.

the class ParseHeadWordFeatureExtractor method getFeatures.

@Override
public Set<Feature> getFeatures(Constituent c) throws EdisonException {
    TextAnnotation ta = c.getTextAnnotation();
    TreeView tree = (TreeView) ta.getView(parseViewName);
    Constituent phrase;
    try {
        phrase = tree.getParsePhrase(c);
    } catch (Exception e) {
        throw new EdisonException(e);
    }
    Set<Feature> features = new LinkedHashSet<>();
    int head = CollinsHeadFinder.getInstance().getHeadWordPosition(phrase);
    Constituent c1 = new Constituent("", "", ta, head, head + 1);
    features.addAll(fex.getFeatures(c1));
    return features;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) TreeView(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TreeView) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) EdisonException(edu.illinois.cs.cogcomp.edison.utilities.EdisonException) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent) EdisonException(edu.illinois.cs.cogcomp.edison.utilities.EdisonException)

Example 8 with Constituent

use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent in project cogcomp-nlp by CogComp.

the class ContextFeatureExtractor method getFeatures.

@Override
public Set<Feature> getFeatures(Constituent c) throws EdisonException {
    TextAnnotation ta = c.getTextAnnotation();
    int start = c.getStartSpan() - contextSize;
    int end = c.getEndSpan() + contextSize;
    if (start < 0)
        start = 0;
    if (end >= ta.size())
        end = ta.size();
    Set<Feature> features = new LinkedHashSet<>();
    for (int i = start; i < end; i++) {
        if (ignoreConstituent)
            if (c.getStartSpan() <= i && i < c.getEndSpan())
                continue;
        for (FeatureExtractor f : this.generators) {
            Constituent neighbor = new Constituent("TMP", "TMP", ta, i, i + 1);
            Set<Feature> feats = f.getFeatures(neighbor);
            for (Feature feat : feats) {
                String preamble = "context";
                if (specifyIndex) {
                    String index = "*";
                    if (i < c.getStartSpan())
                        index = (i - c.getStartSpan()) + "";
                    else if (i >= c.getEndSpan())
                        index = (i - c.getEndSpan() + 1) + "";
                    preamble += index;
                }
                preamble += ":";
                features.add(feat.prefixWith(preamble + f.getName()));
            }
        }
    }
    return features;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)

Example 9 with Constituent

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

Example 10 with Constituent

use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent in project cogcomp-nlp by CogComp.

the class FeatureCollection method getFeatures.

public Set<Feature> getFeatures(Constituent c) throws EdisonException {
    boolean hasName = this.getName().length() > 0;
    Set<Feature> features = new LinkedHashSet<>();
    if (this.inputTransformer == FeatureInputTransformer.identity) {
        getFeatures(hasName, features, c);
    } else {
        List<Constituent> input = inputTransformer.transform(c);
        if (input == null || input.size() == 0) {
            features.add(NULL_INPUT);
        } else {
            for (Constituent in : input) {
                getFeatures(hasName, features, in);
            }
        }
        features = FeatureUtilities.prefix(this.inputTransformer.name(), features);
    }
    return features;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)

Aggregations

Constituent (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)227 TextAnnotation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation)121 View (edu.illinois.cs.cogcomp.core.datastructures.textannotation.View)66 Feature (edu.illinois.cs.cogcomp.edison.features.Feature)44 Test (org.junit.Test)43 ArrayList (java.util.ArrayList)37 Relation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation)28 EdisonException (edu.illinois.cs.cogcomp.edison.utilities.EdisonException)25 SpanLabelView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.SpanLabelView)22 LinkedHashSet (java.util.LinkedHashSet)22 TreeView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TreeView)21 DiscreteFeature (edu.illinois.cs.cogcomp.edison.features.DiscreteFeature)20 AnnotatorException (edu.illinois.cs.cogcomp.annotation.AnnotatorException)18 IntPair (edu.illinois.cs.cogcomp.core.datastructures.IntPair)18 FeatureExtractor (edu.illinois.cs.cogcomp.edison.features.FeatureExtractor)17 ProjectedPath (edu.illinois.cs.cogcomp.edison.features.lrec.ProjectedPath)16 FeatureManifest (edu.illinois.cs.cogcomp.edison.features.manifest.FeatureManifest)16 FileInputStream (java.io.FileInputStream)16 PredicateArgumentView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.PredicateArgumentView)14 HashSet (java.util.HashSet)13