Search in sources :

Example 1 with QueryableList

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

the class ChunkEmbedding method getFeatures.

@Override
public Set<Feature> getFeatures(Constituent c) throws EdisonException {
    View constituents = c.getTextAnnotation().getView(viewName);
    IQueryable<Constituent> shallowParseContained = constituents.where(Queries.containedInConstituent(c));
    int numChunks = ((QueryableList<Constituent>) shallowParseContained).size();
    Set<Feature> features = new LinkedHashSet<>();
    if (numChunks > 0)
        features.add(RealFeature.create("nchnks", numChunks));
    if (numChunks == 1) {
        features.add(DiscreteFeature.create("nchnks-th:1"));
    } else if (numChunks == 2) {
        features.add(DiscreteFeature.create("nchnks-th:2"));
    } else if (numChunks >= 3) {
        features.add(DiscreteFeature.create("nchnks-th:many"));
    }
    Counter<String> counter = new Counter<>();
    Predicate<Constituent> condition = Queries.containedInConstituentExclusive(c);
    addFeatures(features, constituents, condition, counter, "cont-in");
    condition = Queries.containsConstituent(c);
    addFeatures(features, constituents, condition, counter, "contains");
    condition = Queries.sameSpanAsConstituent(c);
    addFeatures(features, constituents, condition, counter, "=span");
    condition = Queries.exclusivelyOverlaps(c);
    addFeatures(features, constituents, condition, counter, "ex-ovlp");
    condition = Queries.hasOverlap(c);
    addFeatures(features, constituents, condition, counter, "has-ovlp");
    // condition = Queries.hasNoOverlap(c);
    // addFeatures(features, constituents, condition, counter,
    // "has-no-overlap");
    condition = Queries.sameStartSpanAs(c);
    addFeatures(features, constituents, condition, counter, "=start");
    condition = Queries.sameEndSpanAs(c);
    addFeatures(features, constituents, condition, counter, "=end");
    features.addAll(FeatureUtilities.getFeatures(counter));
    return features;
}
Also used : QueryableList(edu.illinois.cs.cogcomp.core.datastructures.QueryableList) LinkedHashSet(java.util.LinkedHashSet) Counter(edu.illinois.cs.cogcomp.core.stats.Counter) View(edu.illinois.cs.cogcomp.core.datastructures.textannotation.View) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)

Aggregations

QueryableList (edu.illinois.cs.cogcomp.core.datastructures.QueryableList)1 Constituent (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)1 View (edu.illinois.cs.cogcomp.core.datastructures.textannotation.View)1 Counter (edu.illinois.cs.cogcomp.core.stats.Counter)1 LinkedHashSet (java.util.LinkedHashSet)1