Search in sources :

Example 61 with Feature

use of edu.illinois.cs.cogcomp.edison.features.Feature 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 62 with Feature

use of edu.illinois.cs.cogcomp.edison.features.Feature in project cogcomp-nlp by CogComp.

the class LabeledDepFeatureGenerator method featureVectorBufferFromFeature.

private FeatureVectorBuffer featureVectorBufferFromFeature(Set<Feature> features) {
    Map<String, Float> featureMap = new HashMap<>();
    for (Feature f : features) {
        if (lm.containFeature(f.getName()))
            featureMap.put(f.getName(), f.getValue());
    }
    SparseFeatureVector sfv = (SparseFeatureVector) lm.convertToFeatureVector(featureMap);
    return new FeatureVectorBuffer(sfv);
}
Also used : SparseFeatureVector(edu.illinois.cs.cogcomp.sl.util.SparseFeatureVector) HashMap(java.util.HashMap) FeatureVectorBuffer(edu.illinois.cs.cogcomp.sl.util.FeatureVectorBuffer) Feature(edu.illinois.cs.cogcomp.edison.features.Feature) DiscreteFeature(edu.illinois.cs.cogcomp.edison.features.DiscreteFeature)

Example 63 with Feature

use of edu.illinois.cs.cogcomp.edison.features.Feature in project cogcomp-nlp by CogComp.

the class LabeledDepFeatureGenerator method SuffixConj.

private Set<Feature> SuffixConj(int head, int dep, DepInst sent, String deprel) {
    String header = "Suffix: ";
    String suffixhead = sent.strLemmas[head].substring(Math.max(sent.strLemmas[head].length() - 3, 0)) + " ";
    String suffixdep = sent.strLemmas[dep].substring(Math.max(sent.strLemmas[dep].length() - 3, 0)) + " ";
    String poshead = sent.strPos[head] + " ";
    String posdep = sent.strPos[dep] + " ";
    String arcdir = "Arc-dir: " + (head < dep) + " ";
    Set<Feature> feats = new HashSet<>();
    feats.add(new DiscreteFeature(header + suffixhead + posdep + arcdir + deprel));
    feats.add(new DiscreteFeature(header + poshead + suffixdep + arcdir + deprel));
    feats.add(new DiscreteFeature(header + suffixhead + suffixdep + arcdir + deprel));
    return feats;
}
Also used : DiscreteFeature(edu.illinois.cs.cogcomp.edison.features.DiscreteFeature) Feature(edu.illinois.cs.cogcomp.edison.features.Feature) DiscreteFeature(edu.illinois.cs.cogcomp.edison.features.DiscreteFeature) HashSet(java.util.HashSet)

Example 64 with Feature

use of edu.illinois.cs.cogcomp.edison.features.Feature in project cogcomp-nlp by CogComp.

the class BrownClusterFeatureExtractor method getWordFeatures.

@Override
public Set<Feature> getWordFeatures(TextAnnotation ta, int wordPosition) throws EdisonException {
    lazyLoadClusters(brownClustersFile);
    if (!ta.hasView(viewGenerator.getViewName())) {
        synchronized (BrownClusterFeatureExtractor.class) {
            View view = null;
            try {
                view = viewGenerator.getView(ta);
            } catch (AnnotatorException e) {
                e.printStackTrace();
                throw new EdisonException(e.getMessage());
            }
            ta.addView(viewGenerator.getViewName(), view);
        }
    }
    SpanLabelView view = (SpanLabelView) ta.getView(viewGenerator.getViewName());
    String word = ta.getToken(wordPosition);
    // What follows has a subtle bug: view.getLabel only gets the first
    // label for the word. A word can have multiple brown clusters though!
    // This has been fixed below.
    // String cluster = view.getLabel(wordPosition);
    //
    // return getBrownClusters(word, cluster);
    Set<Feature> features = new LinkedHashSet<>();
    for (Constituent c : view.getConstituentsCoveringToken(wordPosition)) {
        String cluster = c.getLabel();
        features.addAll(getBrownClusters(word, cluster));
    }
    return features;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AnnotatorException(edu.illinois.cs.cogcomp.annotation.AnnotatorException) EdisonException(edu.illinois.cs.cogcomp.edison.utilities.EdisonException) SpanLabelView(edu.illinois.cs.cogcomp.core.datastructures.textannotation.SpanLabelView) View(edu.illinois.cs.cogcomp.core.datastructures.textannotation.View) SpanLabelView(edu.illinois.cs.cogcomp.core.datastructures.textannotation.SpanLabelView) 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 65 with Feature

use of edu.illinois.cs.cogcomp.edison.features.Feature in project cogcomp-nlp by CogComp.

the class ParsePhraseTypeOnly 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<>();
    if (phrase != null)
        features.add(DiscreteFeature.create(phrase.getLabel()));
    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) 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)

Aggregations

Feature (edu.illinois.cs.cogcomp.edison.features.Feature)71 TextAnnotation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation)48 Constituent (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)44 DiscreteFeature (edu.illinois.cs.cogcomp.edison.features.DiscreteFeature)41 LinkedHashSet (java.util.LinkedHashSet)24 View (edu.illinois.cs.cogcomp.core.datastructures.textannotation.View)22 EdisonException (edu.illinois.cs.cogcomp.edison.utilities.EdisonException)17 Test (org.junit.Test)13 TreeView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TreeView)12 HashSet (java.util.HashSet)11 Relation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation)10 ArrayList (java.util.ArrayList)9 PredicateArgumentView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.PredicateArgumentView)8 RealFeature (edu.illinois.cs.cogcomp.edison.features.RealFeature)8 Set (java.util.Set)6 TokenLabelView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TokenLabelView)5 POSBaseLineCounter (edu.illinois.cs.cogcomp.edison.utilities.POSBaseLineCounter)5 POSMikheevCounter (edu.illinois.cs.cogcomp.edison.utilities.POSMikheevCounter)5 ModelInfo (edu.illinois.cs.cogcomp.verbsense.core.ModelInfo)3 List (java.util.List)3