Search in sources :

Example 1 with CommaSRLSentence

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

the class substitutePairFirstComma method makeConstraint.

public FirstOrderConstraint makeConstraint(Object __example) {
    if (!(__example instanceof CommaSRLSentence)) {
        String type = __example == null ? "null" : __example.getClass().getName();
        System.err.println("Constraint 'substitutePairFirstComma(CommaSRLSentence)' defined on line 194 of CommaClassifier.lbj received '" + type + "' as input.");
        new Exception().printStackTrace();
        System.exit(1);
    }
    CommaSRLSentence s = (CommaSRLSentence) __example;
    FirstOrderConstraint __result = new FirstOrderConstant(true);
    {
        Object[] LBJ$constraint$context = new Object[1];
        LBJ$constraint$context[0] = s;
        FirstOrderConstraint LBJava$constraint$result$0 = null;
        {
            FirstOrderConstraint LBJava$constraint$result$1 = null;
            {
                FirstOrderConstraint LBJava$constraint$result$2 = null;
                {
                    EqualityArgumentReplacer LBJ$EAR = new EqualityArgumentReplacer(LBJ$constraint$context, true) {

                        public Object getLeftObject() {
                            Comma c = (Comma) quantificationVariables.get(0);
                            return c;
                        }
                    };
                    LBJava$constraint$result$2 = new FirstOrderEqualityWithValue(true, new FirstOrderVariable(__LocalCommaClassifier, null), "" + ("Substitute"), LBJ$EAR);
                }
                FirstOrderConstraint LBJava$constraint$result$3 = null;
                {
                    EqualityArgumentReplacer LBJ$EAR = new EqualityArgumentReplacer(LBJ$constraint$context, true) {

                        public Object getLeftObject() {
                            CommaSRLSentence s = (CommaSRLSentence) context[0];
                            Comma c = (Comma) quantificationVariables.get(0);
                            return s.getNextSiblingComma(c);
                        }
                    };
                    LBJava$constraint$result$3 = new FirstOrderEqualityWithValue(true, new FirstOrderVariable(__LocalCommaClassifier, null), "" + ("Substitute"), LBJ$EAR);
                }
                LBJava$constraint$result$1 = new FirstOrderImplication(LBJava$constraint$result$2, LBJava$constraint$result$3);
            }
            LBJava$constraint$result$0 = new UniversalQuantifier("c", s.getFirstSiblingCommasWhichAreNotLast(), LBJava$constraint$result$1);
        }
        __result = new FirstOrderConjunction(__result, LBJava$constraint$result$0);
    }
    return __result;
}
Also used : Comma(edu.illinois.cs.cogcomp.comma.datastructures.Comma) CommaSRLSentence(edu.illinois.cs.cogcomp.comma.datastructures.CommaSRLSentence)

Example 2 with CommaSRLSentence

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

the class substitutePairFirstComma method discreteValue.

public String discreteValue(Object __example) {
    if (!(__example instanceof CommaSRLSentence)) {
        String type = __example == null ? "null" : __example.getClass().getName();
        System.err.println("Constraint 'substitutePairFirstComma(CommaSRLSentence)' defined on line 194 of CommaClassifier.lbj received '" + type + "' as input.");
        new Exception().printStackTrace();
        System.exit(1);
    }
    CommaSRLSentence s = (CommaSRLSentence) __example;
    {
        boolean LBJava$constraint$result$0;
        {
            LBJava$constraint$result$0 = true;
            for (java.util.Iterator __I0 = (s.getFirstSiblingCommasWhichAreNotLast()).iterator(); __I0.hasNext() && LBJava$constraint$result$0; ) {
                Comma c = (Comma) __I0.next();
                {
                    boolean LBJava$constraint$result$1;
                    LBJava$constraint$result$1 = ("" + (__LocalCommaClassifier.discreteValue(c))).equals("" + ("Substitute"));
                    if (LBJava$constraint$result$1)
                        LBJava$constraint$result$0 = ("" + (__LocalCommaClassifier.discreteValue(s.getNextSiblingComma(c)))).equals("" + ("Substitute"));
                    else
                        LBJava$constraint$result$0 = true;
                }
            }
        }
        if (!LBJava$constraint$result$0)
            return "false";
    }
    return "true";
}
Also used : Comma(edu.illinois.cs.cogcomp.comma.datastructures.Comma) CommaSRLSentence(edu.illinois.cs.cogcomp.comma.datastructures.CommaSRLSentence)

Example 3 with CommaSRLSentence

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

the class substitutePairMiddleCommas method makeConstraint.

public FirstOrderConstraint makeConstraint(Object __example) {
    if (!(__example instanceof CommaSRLSentence)) {
        String type = __example == null ? "null" : __example.getClass().getName();
        System.err.println("Constraint 'substitutePairMiddleCommas(CommaSRLSentence)' defined on line 200 of CommaClassifier.lbj received '" + type + "' as input.");
        new Exception().printStackTrace();
        System.exit(1);
    }
    CommaSRLSentence s = (CommaSRLSentence) __example;
    FirstOrderConstraint __result = new FirstOrderConstant(true);
    {
        Object[] LBJ$constraint$context = new Object[1];
        LBJ$constraint$context[0] = s;
        FirstOrderConstraint LBJava$constraint$result$0 = null;
        {
            FirstOrderConstraint LBJava$constraint$result$1 = null;
            {
                FirstOrderConstraint LBJava$constraint$result$2 = null;
                {
                    EqualityArgumentReplacer LBJ$EAR = new EqualityArgumentReplacer(LBJ$constraint$context, true) {

                        public Object getLeftObject() {
                            Comma c = (Comma) quantificationVariables.get(0);
                            return c;
                        }
                    };
                    LBJava$constraint$result$2 = new FirstOrderEqualityWithValue(true, new FirstOrderVariable(__LocalCommaClassifier, null), "" + ("Substitute"), LBJ$EAR);
                }
                FirstOrderConstraint LBJava$constraint$result$3 = null;
                {
                    FirstOrderConstraint LBJava$constraint$result$4 = null;
                    {
                        EqualityArgumentReplacer LBJ$EAR = new EqualityArgumentReplacer(LBJ$constraint$context, true) {

                            public Object getLeftObject() {
                                CommaSRLSentence s = (CommaSRLSentence) context[0];
                                Comma c = (Comma) quantificationVariables.get(0);
                                return s.getNextSiblingComma(c);
                            }
                        };
                        LBJava$constraint$result$4 = new FirstOrderEqualityWithValue(true, new FirstOrderVariable(__LocalCommaClassifier, null), "" + ("Substitute"), LBJ$EAR);
                    }
                    FirstOrderConstraint LBJava$constraint$result$5 = null;
                    {
                        EqualityArgumentReplacer LBJ$EAR = new EqualityArgumentReplacer(LBJ$constraint$context, true) {

                            public Object getLeftObject() {
                                CommaSRLSentence s = (CommaSRLSentence) context[0];
                                Comma c = (Comma) quantificationVariables.get(0);
                                return s.getPreviousSiblingComma(c);
                            }
                        };
                        LBJava$constraint$result$5 = new FirstOrderEqualityWithValue(true, new FirstOrderVariable(__LocalCommaClassifier, null), "" + ("Substitute"), LBJ$EAR);
                    }
                    LBJava$constraint$result$3 = new FirstOrderDisjunction(LBJava$constraint$result$4, LBJava$constraint$result$5);
                }
                LBJava$constraint$result$1 = new FirstOrderImplication(LBJava$constraint$result$2, LBJava$constraint$result$3);
            }
            LBJava$constraint$result$0 = new UniversalQuantifier("c", s.getMiddleSiblingCommas(), LBJava$constraint$result$1);
        }
        __result = new FirstOrderConjunction(__result, LBJava$constraint$result$0);
    }
    return __result;
}
Also used : CommaSRLSentence(edu.illinois.cs.cogcomp.comma.datastructures.CommaSRLSentence) Comma(edu.illinois.cs.cogcomp.comma.datastructures.Comma)

Example 4 with CommaSRLSentence

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

the class PrettyCorpusReader method readData.

private void readData(String annotationFileName) throws Exception {
    PreProcessor preProcessor = new PreProcessor();
    sentences = new ArrayList<>();
    Map<String, TextAnnotation> taMap = getTAMap();
    Scanner scanner;
    scanner = new Scanner(new File(annotationFileName));
    int count = 0;
    int failures = 0, skipped = 0;
    while (scanner.hasNext()) {
        count++;
        // wsj pentreebank sentence id
        String textId = scanner.nextLine().trim();
        assert textId.startsWith("wsj") : textId;
        String[] tokens = scanner.nextLine().trim().split("\\s+");
        String[] cleanedTokens = cleanTokens(tokens);
        String blankLine = scanner.nextLine();
        assert blankLine.trim().length() == 0 : String.format("line is not blank:%s", blankLine);
        // should we skip this sentence due to some error?
        boolean skip = false;
        TextAnnotation goldTa = null, ta = null;
        if (taMap.containsKey(textId)) {
            goldTa = taMap.get(textId);
            try {
                ta = preProcessor.preProcess(Collections.singletonList(cleanedTokens));
            } catch (Exception e) {
                e.printStackTrace();
                skip = true;
                failures++;
            }
        } else {
            System.out.println("No gold standard annotation available for:" + textId);
            skip = true;
            skipped++;
        }
        if (!skip) {
            List<List<String>> commaLabels = new ArrayList<>();
            for (String token : tokens) {
                if (token.matches(",\\[.*\\]")) {
                    String labels = token.substring(2, token.length() - 1);
                    List<String> commaLabelsForIdx = Arrays.asList(labels.split(","));
                    commaLabels.add(commaLabelsForIdx);
                } else if (token.equals(",")) {
                    // add null for commas which have not been annotated.
                    // The sentence constructor will optionally discard
                    // these or convert them to Other labels based on
                    // comma.properties.INCLUDE_NULL_LABEL_COMMAS
                    commaLabels.add(null);
                }
            }
            try {
                CommaSRLSentence sentence = new CommaSRLSentence(ta, goldTa, commaLabels);
                sentences.add(sentence);
            } catch (Exception e) {
                e.printStackTrace();
                failures++;
            }
        }
        System.out.print(count);
        if (skipped > 0)
            System.out.print(" SKIPPED(" + skipped + ")");
        if (failures > 0)
            System.out.print(" ANNOTATION FAILED(" + failures + ")");
    }
    scanner.close();
}
Also used : CommaSRLSentence(edu.illinois.cs.cogcomp.comma.datastructures.CommaSRLSentence) PreProcessor(edu.illinois.cs.cogcomp.comma.annotators.PreProcessor) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) File(java.io.File)

Example 5 with CommaSRLSentence

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

the class CommaIOManager method readProblem.

public static SLProblem readProblem(List<CommaSRLSentence> sentences, Lexiconer lexicon, List<Classifier> lbjExtractors, Classifier lbjLabeler) {
    if (lexicon.isAllowNewFeatures())
        lexicon.addFeature(unknownFeature);
    // lexicon.addLabel("occupy-zero-label-for-some-reason");
    SLProblem sp = new SLProblem();
    // READ PROBLEM
    for (CommaSRLSentence sentence : sentences) {
        List<CommaSequence> commaSequences = getCommaSequences(sentence, lexicon, lbjExtractors);
        for (CommaSequence commaSequence : commaSequences) {
            CommaLabelSequence labelSequence = new CommaLabelSequence(commaSequence, lexicon, lbjLabeler);
            sp.addExample(commaSequence, labelSequence);
        }
    }
    return sp;
}
Also used : SLProblem(edu.illinois.cs.cogcomp.sl.core.SLProblem) 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