Search in sources :

Example 31 with CommaSRLSentence

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

the class ClassifierComparison method structuredCVal.

public static EvaluateDiscrete structuredCVal(StructuredCommaClassifier model, Parser parser, boolean useGoldFeatures, boolean testOnTrain) throws Exception {
    Comma.useGoldFeatures(useGoldFeatures);
    int k = 5;
    parser.reset();
    FoldParser foldParser = new FoldParser(parser, k, SplitPolicy.sequential, 0, false);
    EvaluateDiscrete cvalResult = new EvaluateDiscrete();
    for (int i = 0; i < k; foldParser.setPivot(++i)) {
        foldParser.setFromPivot(false);
        foldParser.reset();
        LinkedHashSet<CommaSRLSentence> trainSentences = new LinkedHashSet<>();
        for (Object comma = foldParser.next(); comma != null; comma = foldParser.next()) {
            trainSentences.add(((Comma) comma).getSentence());
        }
        model.train(new ArrayList<>(trainSentences), null);
        if (!testOnTrain)
            foldParser.setFromPivot(true);
        foldParser.reset();
        LinkedHashSet<CommaSRLSentence> testSentences = new LinkedHashSet<>();
        for (Object comma = foldParser.next(); comma != null; comma = foldParser.next()) {
            testSentences.add(((Comma) comma).getSentence());
        }
        EvaluateDiscrete evaluator = model.test(new ArrayList<>(testSentences), null);
        cvalResult.reportAll(evaluator);
    }
    cvalResult.printPerformance(System.out);
    return cvalResult;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) EvaluateDiscrete(edu.illinois.cs.cogcomp.comma.utils.EvaluateDiscrete) CommaSRLSentence(edu.illinois.cs.cogcomp.comma.datastructures.CommaSRLSentence) FoldParser(edu.illinois.cs.cogcomp.lbjava.parse.FoldParser)

Example 32 with CommaSRLSentence

use of edu.illinois.cs.cogcomp.comma.datastructures.CommaSRLSentence 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)

Example 33 with CommaSRLSentence

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

the class ListCommasConstrainedInference$subjectto method makeConstraint.

public FirstOrderConstraint makeConstraint(Object __example) {
    if (!(__example instanceof CommaSRLSentence)) {
        String type = __example == null ? "null" : __example.getClass().getName();
        System.err.println("Constraint 'ListCommasConstrainedInference$subjectto(CommaSRLSentence)' defined on line 280 of CommaClassifier.lbj received '" + type + "' as input.");
        new Exception().printStackTrace();
        System.exit(1);
    }
    CommaSRLSentence s = (CommaSRLSentence) __example;
    FirstOrderConstraint __result = new FirstOrderConstant(true);
    {
        FirstOrderConstraint LBJava$constraint$result$0 = null;
        LBJava$constraint$result$0 = __listCommas.makeConstraint(s);
        __result = new FirstOrderConjunction(__result, LBJava$constraint$result$0);
    }
    return __result;
}
Also used : CommaSRLSentence(edu.illinois.cs.cogcomp.comma.datastructures.CommaSRLSentence)

Aggregations

CommaSRLSentence (edu.illinois.cs.cogcomp.comma.datastructures.CommaSRLSentence)33 Comma (edu.illinois.cs.cogcomp.comma.datastructures.Comma)18 TextAnnotation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation)2 AnnotatorException (edu.illinois.cs.cogcomp.annotation.AnnotatorException)1 PreProcessor (edu.illinois.cs.cogcomp.comma.annotators.PreProcessor)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 TokenLabelView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TokenLabelView)1 TreeView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TreeView)1 FoldParser (edu.illinois.cs.cogcomp.lbjava.parse.FoldParser)1 SLProblem (edu.illinois.cs.cogcomp.sl.core.SLProblem)1 File (java.io.File)1 LinkedHashSet (java.util.LinkedHashSet)1