Search in sources :

Example 26 with Comma

use of edu.illinois.cs.cogcomp.comma.datastructures.Comma in project cogcomp-nlp by CogComp.

the class LocativePairConstrainedCommaClassifier method discreteValue.

public String discreteValue(Object __example) {
    if (!(__example instanceof Comma)) {
        String type = __example == null ? "null" : __example.getClass().getName();
        System.err.println("Classifier 'LocativePairConstrainedCommaClassifier(Comma)' defined on line 276 of CommaClassifier.lbj received '" + type + "' as input.");
        new Exception().printStackTrace();
        System.exit(1);
    }
    CommaSRLSentence head = LocativePairConstrainedInference.findHead((Comma) __example);
    LocativePairConstrainedInference inference = (LocativePairConstrainedInference) InferenceManager.get("edu.illinois.cs.cogcomp.comma.lbj.LocativePairConstrainedInference", head);
    if (inference == null) {
        inference = new LocativePairConstrainedInference(head);
        InferenceManager.put(inference);
    }
    String result = null;
    try {
        result = inference.valueOf(__LocalCommaClassifier, __example);
    } catch (Exception e) {
        System.err.println("LBJava ERROR: Fatal error while evaluating classifier LocativePairConstrainedCommaClassifier: " + e);
        e.printStackTrace();
        System.exit(1);
    }
    return result;
}
Also used : Comma(edu.illinois.cs.cogcomp.comma.datastructures.Comma) CommaSRLSentence(edu.illinois.cs.cogcomp.comma.datastructures.CommaSRLSentence)

Example 27 with Comma

use of edu.illinois.cs.cogcomp.comma.datastructures.Comma in project cogcomp-nlp by CogComp.

the class OxfordCommaConstrainedCommaClassifier method discreteValue.

public String discreteValue(Object __example) {
    if (!(__example instanceof Comma)) {
        String type = __example == null ? "null" : __example.getClass().getName();
        System.err.println("Classifier 'OxfordCommaConstrainedCommaClassifier(Comma)' defined on line 260 of CommaClassifier.lbj received '" + type + "' as input.");
        new Exception().printStackTrace();
        System.exit(1);
    }
    CommaSRLSentence head = OxfordCommaConstrainedInference.findHead((Comma) __example);
    OxfordCommaConstrainedInference inference = (OxfordCommaConstrainedInference) InferenceManager.get("edu.illinois.cs.cogcomp.comma.lbj.OxfordCommaConstrainedInference", head);
    if (inference == null) {
        inference = new OxfordCommaConstrainedInference(head);
        InferenceManager.put(inference);
    }
    String result = null;
    try {
        result = inference.valueOf(__LocalCommaClassifier, __example);
    } catch (Exception e) {
        System.err.println("LBJava ERROR: Fatal error while evaluating classifier OxfordCommaConstrainedCommaClassifier: " + e);
        e.printStackTrace();
        System.exit(1);
    }
    return result;
}
Also used : Comma(edu.illinois.cs.cogcomp.comma.datastructures.Comma) CommaSRLSentence(edu.illinois.cs.cogcomp.comma.datastructures.CommaSRLSentence)

Example 28 with Comma

use of edu.illinois.cs.cogcomp.comma.datastructures.Comma in project cogcomp-nlp by CogComp.

the class ParentSiblingPhraseFeatures method classify.

public FeatureVector classify(Object __example) {
    if (!(__example instanceof Comma)) {
        String type = __example == null ? "null" : __example.getClass().getName();
        System.err.println("Classifier 'ParentSiblingPhraseFeatures(Comma)' defined on line 47 of CommaClassifier.lbj received '" + type + "' as input.");
        new Exception().printStackTrace();
        System.exit(1);
    }
    Comma c = (Comma) __example;
    FeatureVector __result;
    __result = new FeatureVector();
    String __id;
    String __value;
    String[] ngrams = c.getParentSiblingPhraseNgrams();
    for (int i = 0; i < ngrams.length; i++) {
        __id = "" + (ngrams[i]);
        __value = "true";
        __result.addFeature(new DiscretePrimitiveStringFeature(this.containingPackage, this.name, __id, __value, valueIndexOf(__value), (short) 0));
    }
    return __result;
}
Also used : Comma(edu.illinois.cs.cogcomp.comma.datastructures.Comma)

Example 29 with Comma

use of edu.illinois.cs.cogcomp.comma.datastructures.Comma in project cogcomp-nlp by CogComp.

the class ClassifierComparison method getBayraktarBaselinePerformance.

/**
     * prints Bayraktar baseline performance based on only those commas whose Bayraktar patterns
     * have been annotated
     */
public static EvaluateDiscrete getBayraktarBaselinePerformance(Parser parser, boolean testOnGold) {
    parser.reset();
    EvaluateDiscrete bayraktarEvaluation = new EvaluateDiscrete();
    Comma comma;
    while ((comma = (Comma) parser.next()) != null) {
        if (!BayraktarPatternLabeler.isLabelAvailable(comma))
            continue;
        Comma.useGoldFeatures(true);
        String goldLabel = comma.getLabel();
        Comma.useGoldFeatures(testOnGold);
        String bayraktarPrediction = comma.getBayraktarLabel();
        bayraktarEvaluation.reportPrediction(bayraktarPrediction, goldLabel);
    }
    return bayraktarEvaluation;
}
Also used : Comma(edu.illinois.cs.cogcomp.comma.datastructures.Comma) EvaluateDiscrete(edu.illinois.cs.cogcomp.comma.utils.EvaluateDiscrete)

Example 30 with Comma

use of edu.illinois.cs.cogcomp.comma.datastructures.Comma in project cogcomp-nlp by CogComp.

the class CommaLabeler method addView.

@Override
public void addView(TextAnnotation ta) throws AnnotatorException {
    // Check that we have the required views
    for (String requiredView : requiredViews) {
        if (!ta.hasView(requiredView))
            throw new AnnotatorException("Missing required view " + requiredView);
    }
    // Create the Comma structure
    CommaSRLSentence sentence = new CommaSRLSentence(ta, ta);
    PredicateArgumentView srlView = new PredicateArgumentView(viewName, "illinois-comma", ta, 1.0d);
    for (Comma comma : sentence.getCommas()) {
        String label = classifier.discreteValue(comma);
        int position = comma.getPosition();
        Constituent predicate = new Constituent("Predicate:" + label, viewName, ta, position, position + 1);
        predicate.addAttribute(PredicateArgumentView.SenseIdentifer, label);
        srlView.addConstituent(predicate);
        Constituent leftArg = comma.getPhraseToLeftOfComma(1);
        if (leftArg != null) {
            Constituent leftArgConst = new Constituent(leftArg.getLabel(), viewName, ta, leftArg.getStartSpan(), leftArg.getEndSpan());
            srlView.addConstituent(leftArgConst);
            srlView.addRelation(new Relation("LeftOf" + label, predicate, leftArgConst, 1.0d));
        }
        Constituent rightArg = comma.getPhraseToRightOfComma(1);
        if (rightArg != null) {
            Constituent rightArgConst = new Constituent(rightArg.getLabel(), viewName, ta, rightArg.getStartSpan(), rightArg.getEndSpan());
            srlView.addConstituent(rightArgConst);
            srlView.addRelation(new Relation("RightOf" + label, predicate, rightArgConst, 1.0d));
        }
    }
    ta.addView(viewName, srlView);
}
Also used : Comma(edu.illinois.cs.cogcomp.comma.datastructures.Comma) Relation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation) AnnotatorException(edu.illinois.cs.cogcomp.annotation.AnnotatorException) CommaSRLSentence(edu.illinois.cs.cogcomp.comma.datastructures.CommaSRLSentence) PredicateArgumentView(edu.illinois.cs.cogcomp.core.datastructures.textannotation.PredicateArgumentView) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)

Aggregations

Comma (edu.illinois.cs.cogcomp.comma.datastructures.Comma)35 CommaSRLSentence (edu.illinois.cs.cogcomp.comma.datastructures.CommaSRLSentence)18 AnnotatorException (edu.illinois.cs.cogcomp.annotation.AnnotatorException)1 EvaluateDiscrete (edu.illinois.cs.cogcomp.comma.utils.EvaluateDiscrete)1 Constituent (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)1 PredicateArgumentView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.PredicateArgumentView)1 Relation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Relation)1 SpanLabelView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.SpanLabelView)1 TextAnnotation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation)1 TokenLabelView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TokenLabelView)1 TreeView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TreeView)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1