Search in sources :

Example 11 with Comma

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

the class StrippedParseTreeFeature method discreteValue.

public String discreteValue(Object __example) {
    if (!(__example instanceof Comma)) {
        String type = __example == null ? "null" : __example.getClass().getName();
        System.err.println("Classifier 'StrippedParseTreeFeature(Comma)' defined on line 112 of CommaClassifier.lbj received '" + type + "' as input.");
        new Exception().printStackTrace();
        System.exit(1);
    }
    Comma c = (Comma) __example;
    String tree = "";
    int distance = 0;
    String phrase;
    do {
        phrase = c.getStrippedNotation(c.getPhraseToLeftOfParent(distance));
        tree = phrase + tree;
        distance++;
    } while (!phrase.equals("NULL"));
    String commaLevelPhrases = "";
    distance = 0;
    do {
        phrase = c.getStrippedNotation(c.getPhraseToLeftOfComma(distance));
        commaLevelPhrases = phrase + commaLevelPhrases;
        distance++;
    } while (!phrase.equals("NULL"));
    distance = 1;
    do {
        phrase = c.getStrippedNotation(c.getPhraseToRightOfComma(distance));
        commaLevelPhrases = commaLevelPhrases + phrase;
        distance++;
    } while (!phrase.equals("NULL"));
    tree += "(" + commaLevelPhrases + ")";
    distance = 1;
    do {
        phrase = c.getStrippedNotation(c.getPhraseToRightOfParent(distance));
        tree = tree + phrase;
        distance++;
    } while (!phrase.equals("NULL"));
    return "" + (tree);
}
Also used : Comma(edu.illinois.cs.cogcomp.comma.datastructures.Comma)

Example 12 with Comma

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

the class SubstitutePairConstrainedCommaClassifier method discreteValue.

public String discreteValue(Object __example) {
    if (!(__example instanceof Comma)) {
        String type = __example == null ? "null" : __example.getClass().getName();
        System.err.println("Classifier 'SubstitutePairConstrainedCommaClassifier(Comma)' defined on line 268 of CommaClassifier.lbj received '" + type + "' as input.");
        new Exception().printStackTrace();
        System.exit(1);
    }
    CommaSRLSentence head = SubstitutePairConstrainedInference.findHead((Comma) __example);
    SubstitutePairConstrainedInference inference = (SubstitutePairConstrainedInference) InferenceManager.get("edu.illinois.cs.cogcomp.comma.lbj.SubstitutePairConstrainedInference", head);
    if (inference == null) {
        inference = new SubstitutePairConstrainedInference(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 SubstitutePairConstrainedCommaClassifier: " + 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 13 with Comma

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

the class WordFeatures method classify.

public FeatureVector classify(Object __example) {
    if (!(__example instanceof Comma)) {
        String type = __example == null ? "null" : __example.getClass().getName();
        System.err.println("Classifier 'WordFeatures(Comma)' defined on line 19 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.getWordNgrams();
    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 14 with Comma

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

the class POSFeatures method classify.

public FeatureVector classify(Object __example) {
    if (!(__example instanceof Comma)) {
        String type = __example == null ? "null" : __example.getClass().getName();
        System.err.println("Classifier 'POSFeatures(Comma)' defined on line 26 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.getPOSNgrams();
    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 15 with Comma

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

the class CommaTest method setUp.

@Override
public void setUp() throws Exception {
    String[] tokens = "Says Gayle Key , a mathematics teacher , `` Hello world . ''".split("\\s+");
    TextAnnotation ta = BasicTextAnnotationBuilder.createTextAnnotationFromTokens(Collections.singletonList(tokens));
    TokenLabelView tlv = new TokenLabelView(ViewNames.POS, "Test", ta, 1.0);
    tlv.addTokenLabel(0, "VBZ", 1d);
    tlv.addTokenLabel(1, "NNP", 1d);
    tlv.addTokenLabel(2, "NNP", 1d);
    tlv.addTokenLabel(3, ",", 1d);
    tlv.addTokenLabel(4, "DT", 1d);
    tlv.addTokenLabel(5, "NN", 1d);
    tlv.addTokenLabel(6, "NN", 1d);
    tlv.addTokenLabel(7, ",", 1d);
    tlv.addTokenLabel(8, "``", 1d);
    tlv.addTokenLabel(9, "UH", 1d);
    tlv.addTokenLabel(10, "NN", 1d);
    tlv.addTokenLabel(11, ".", 1d);
    tlv.addTokenLabel(12, "''", 1d);
    TreeView parse = new TreeView(ViewNames.PARSE_STANFORD, "Test", ta, 1.0);
    String treeString = "(ROOT" + "  (SINV" + "    (VP (VBZ Says))" + "    (NP (NNP Gayle) (NNP Key))" + "    (, ,)" + "    (S" + "      (NP (DT a) (NNS mathematics))" + "      (VP (VBZ teacher) (, ,) (`` ``)" + "        (NP" + "          (INTJ (UH Hello))" + "          (NP (NN world)))))" + "    (. .) ('' '')))";
    parse.setParseTree(0, TreeParserFactory.getStringTreeParser().parse(treeString));
    SpanLabelView ner = new SpanLabelView(ViewNames.NER_CONLL, "Test", ta, 1.0);
    ner.addSpanLabel(1, 3, "PER", 1.0);
    SpanLabelView shallowParse = new SpanLabelView(ViewNames.SHALLOW_PARSE, "Test", ta, 1.0);
    shallowParse.addSpanLabel(0, 3, "NP", 1.0);
    shallowParse.addSpanLabel(4, 7, "NP", 1.0);
    shallowParse.addSpanLabel(9, 11, "NP", 1.0);
    // TODO dependency parse
    // TODO SRL view
    ta.addView(tlv.getViewName(), tlv);
    ta.addView(parse.getViewName(), parse);
    ta.addView(ner.getViewName(), ner);
    ta.addView(shallowParse.getViewName(), shallowParse);
    List<String> firstCommasRefinedLabels = Collections.singletonList("Substitute");
    List<String> secondCommasRefinedLabels = Arrays.asList("Substitute", "Quotation");
    CommaSRLSentence sentence = new CommaSRLSentence(ta, null, Arrays.asList(firstCommasRefinedLabels, secondCommasRefinedLabels));
    List<Comma> sentenceCommas = sentence.getCommas();
    commas = sentenceCommas.toArray(new Comma[sentenceCommas.size()]);
}
Also used : Comma(edu.illinois.cs.cogcomp.comma.datastructures.Comma) TokenLabelView(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TokenLabelView) CommaSRLSentence(edu.illinois.cs.cogcomp.comma.datastructures.CommaSRLSentence) TreeView(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TreeView) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) SpanLabelView(edu.illinois.cs.cogcomp.core.datastructures.textannotation.SpanLabelView)

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