Search in sources :

Example 1 with Relation

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

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

the class ExtentTester method getFullMention.

/**
 * Gets the full mention of the given  head
 * @param classifier The extent classifier
 * @param head The head Constituent
 * @param gazetteers gazetteers
 * @param brownClusters brownclusters
 * @param wordnet wordnet
 * @return A Constituent of a full mention (extent included)
 * @Note The returned Constituent has Attributes "EntityHeadStartSpan" and "EntityHeadEndSpan"
 */
public static Constituent getFullMention(extent_classifier classifier, Constituent head, Gazetteers gazetteers, BrownClusters brownClusters, WordNetManager wordnet) {
    addHeadAttributes(head, gazetteers, brownClusters, wordnet);
    View tokenView = head.getTextAnnotation().getView(ViewNames.TOKENS);
    int leftIdx = head.getStartSpan() - 1;
    while (leftIdx >= tokenView.getStartSpan()) {
        Constituent cur = tokenView.getConstituentsCoveringToken(leftIdx).get(0);
        addExtentAttributes(cur, gazetteers, brownClusters, wordnet);
        Relation candidate = new Relation("UNKNOWN", cur, head, 1.0f);
        String prediction = classifier.discreteValue(candidate);
        if (prediction.equals("false")) {
            leftIdx++;
            break;
        }
        leftIdx--;
    }
    if (leftIdx < tokenView.getStartSpan()) {
        leftIdx = tokenView.getStartSpan();
    }
    int rightIdx = head.getEndSpan();
    while (rightIdx < tokenView.getEndSpan()) {
        Constituent cur = tokenView.getConstituentsCoveringToken(rightIdx).get(0);
        addExtentAttributes(cur, gazetteers, brownClusters, wordnet);
        Relation candidate = new Relation("UNKNOWN", cur, head, 1.0f);
        String prediction = classifier.discreteValue(candidate);
        if (prediction.equals("false")) {
            rightIdx--;
            break;
        }
        rightIdx++;
    }
    if (rightIdx >= tokenView.getEndSpan()) {
        rightIdx = tokenView.getEndSpan() - 1;
    }
    Constituent fullMention = new Constituent(head.getLabel(), 1.0f, ViewNames.MENTION, head.getTextAnnotation(), leftIdx, rightIdx + 1);
    fullMention.addAttribute("EntityHeadStartSpan", Integer.toString(head.getStartSpan()));
    fullMention.addAttribute("EntityHeadEndSpan", Integer.toString(head.getEndSpan()));
    fullMention.addAttribute("EntityType", head.getAttribute("EntityType"));
    fullMention.addAttribute("EntityMentionType", head.getAttribute("EntityMentionType"));
    return fullMention;
}
Also used : Relation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation) View(edu.illinois.cs.cogcomp.core.datastructures.textannotation.View) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)

Example 3 with Relation

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

the class TextAnnotationLabelCounter method populateLabelCounts.

/**
 * generate the target label/feature counts.
 * @param annotationViews map from doc id to set of views containing the annotations (constituents, relations)
 *                        that will be split.
 */
@Override
public void populateLabelCounts(Map<String, Set<View>> annotationViews) {
    for (String docId : annotationViews.keySet()) {
        Counter<String> docLabelCount = new Counter<>();
        labelCounts.put(docId, docLabelCount);
        for (View v : annotationViews.get(docId)) {
            for (Relation r : v.getRelations()) {
                String label = r.getRelationName();
                if (useAllLabels || labelsToConsider.contains(label)) {
                    docLabelCount.incrementCount(label);
                    labelTotals.incrementCount(label);
                }
            }
            for (Constituent c : v.getConstituents()) {
                String label = c.getLabel();
                if (useAllLabels || labelsToConsider.contains(label)) {
                    docLabelCount.incrementCount(label);
                    labelTotals.incrementCount(label);
                }
            }
        }
    }
}
Also used : Relation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation) 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)

Example 4 with Relation

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

the class ParsePhraseTypeOnlyTest method setUp.

@Before
public void setUp() throws Exception {
    String[] viewsToAdd = { ViewNames.PARSE_STANFORD, ViewNames.PARSE_CHARNIAK, ViewNames.PARSE_GOLD, ViewNames.SRL_VERB };
    TextAnnotation ta = DummyTextAnnotationGenerator.generateAnnotatedTextAnnotation(viewsToAdd, false, 3);
    PredicateArgumentView srlView = (PredicateArgumentView) ta.getView(ViewNames.SRL_VERB);
    predicate = srlView.getPredicates().get(0);
    List<Relation> arguments = new ArrayList<>(srlView.getArguments(predicate));
    // Making the order of arg1 and arg2 deterministic by sorting them according to their relation target.
    arguments.sort((o1, o2) -> Integer.compare(o1.getTarget().getStartSpan(), o2.getTarget().getStartSpan()));
    arg1 = arguments.get(0).getTarget();
    arg2 = arguments.get(1).getTarget();
}
Also used : Relation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation) ArrayList(java.util.ArrayList) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) PredicateArgumentView(edu.illinois.cs.cogcomp.core.datastructures.textannotation.PredicateArgumentView) Before(org.junit.Before)

Example 5 with Relation

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

the class TestClauseFeatureExtractor method testFex.

private void testFex(FeatureExtractor fex) throws Exception {
    for (TextAnnotation ta : tas) {
        if (!ta.hasView(ViewNames.PARSE_CHARNIAK))
            continue;
        ta.addView(ClauseViewGenerator.CHARNIAK);
        ta.addView(PseudoParse.CHARNIAK);
        PredicateArgumentView pav = (PredicateArgumentView) ta.getView(ViewNames.SRL_VERB);
        for (Constituent predicate : pav.getPredicates()) {
            Constituent p = predicate.cloneForNewView("dummy");
            for (Relation arg : pav.getArguments(predicate)) {
                Constituent c = arg.getTarget().cloneForNewView("dummy");
                new Relation("", p, c, 1.0);
                Set<Feature> features = fex.getFeatures(c);
                logger.info(c + "\t" + features);
            }
        }
    }
}
Also used : Relation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) Feature(edu.illinois.cs.cogcomp.edison.features.Feature) 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