Search in sources :

Example 81 with Constituent

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

the class Contains method getFeatures.

@Override
public Set<Feature> getFeatures(Constituent instance) throws EdisonException {
    Set<Feature> features = new LinkedHashSet<Feature>();
    TextAnnotation ta = instance.getTextAnnotation();
    View view = ta.getView(viewName);
    List<Constituent> lsc = view.getConstituentsCovering(instance);
    if (lsc.size() == 0) {
        features.add(N);
        return features;
    }
    boolean contains = false;
    for (Constituent c : lsc) if (contained.contains(c.getTokenizedSurfaceForm()) || contained.contains(c.getLabel())) {
        contains = true;
        break;
    }
    if (contains)
        features.add(Y);
    else
        features.add(N);
    return features;
}
Also used : TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) DiscreteFeature(edu.illinois.cs.cogcomp.edison.features.DiscreteFeature) Feature(edu.illinois.cs.cogcomp.edison.features.Feature) View(edu.illinois.cs.cogcomp.core.datastructures.textannotation.View) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)

Example 82 with Constituent

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

the class SpanFeaturesUnordered method getFeatures.

@Override
public Set<Feature> getFeatures(Constituent c) throws EdisonException {
    SpanLabelView chunks = (SpanLabelView) c.getTextAnnotation().getView(viewName);
    List<Constituent> list = SpanLabelsHelper.getConstituentsInBetween(chunks, c.getStartSpan(), c.getEndSpan());
    Collections.sort(list, TextAnnotationUtilities.constituentStartComparator);
    return FeatureNGramUtility.getLabelNgramsUnordered(list, ngramLength);
}
Also used : SpanLabelView(edu.illinois.cs.cogcomp.core.datastructures.textannotation.SpanLabelView) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)

Example 83 with Constituent

use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent 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 84 with Constituent

use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent 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 85 with Constituent

use of edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent 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)

Aggregations

Constituent (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)176 TextAnnotation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation)95 View (edu.illinois.cs.cogcomp.core.datastructures.textannotation.View)51 Feature (edu.illinois.cs.cogcomp.edison.features.Feature)44 Test (org.junit.Test)39 ArrayList (java.util.ArrayList)29 Relation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation)25 EdisonException (edu.illinois.cs.cogcomp.edison.utilities.EdisonException)24 LinkedHashSet (java.util.LinkedHashSet)22 TreeView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TreeView)20 DiscreteFeature (edu.illinois.cs.cogcomp.edison.features.DiscreteFeature)20 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 IntPair (edu.illinois.cs.cogcomp.core.datastructures.IntPair)14 PredicateArgumentView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.PredicateArgumentView)13 SpanLabelView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.SpanLabelView)12 HashSet (java.util.HashSet)12 AnnotatorException (edu.illinois.cs.cogcomp.annotation.AnnotatorException)11