Search in sources :

Example 31 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 32 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 33 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 34 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 35 with Relation

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

the class TestChunkFeatures method testFex.

private void testFex(FeatureExtractor fex, boolean printBoth, String... viewNames) throws EdisonException {
    for (TextAnnotation ta : tas) {
        for (String viewName : viewNames) if (ta.hasView(viewName))
            logger.info(ta.getView(viewName).toString());
        if (!ta.hasView(ViewNames.SRL_VERB))
            continue;
        PredicateArgumentView pav = (PredicateArgumentView) ta.getView(ViewNames.SRL_VERB);
        for (Constituent predicate : pav.getPredicates()) {
            Constituent p = predicate.cloneForNewView("dummy");
            for (Relation argument : pav.getArguments(predicate)) {
                Constituent c = argument.getTarget().cloneForNewView("dummy");
                Relation r = new Relation("", p, c, 1);
                logger.info((printBoth ? r : c) + "\t" + fex.getFeatures(c));
            }
        }
    }
}
Also used : Relation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) PredicateArgumentView(edu.illinois.cs.cogcomp.core.datastructures.textannotation.PredicateArgumentView) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)

Aggregations

Relation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation)36 Constituent (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)28 TextAnnotation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation)18 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 View (edu.illinois.cs.cogcomp.core.datastructures.textannotation.View)5 BatchTrainer (edu.illinois.cs.cogcomp.lbjava.learn.BatchTrainer)5 Learner (edu.illinois.cs.cogcomp.lbjava.learn.Learner)5 Lexicon (edu.illinois.cs.cogcomp.lbjava.learn.Lexicon)5 LbjGen.relation_classifier (org.cogcomp.re.LbjGen.relation_classifier)4 Test (org.junit.Test)3 JsonObject (com.google.gson.JsonObject)2 ChunkerAnnotator (edu.illinois.cs.cogcomp.chunker.main.ChunkerAnnotator)2 ChunkerConfigurator (edu.illinois.cs.cogcomp.chunker.main.ChunkerConfigurator)2 SpanLabelView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.SpanLabelView)2