Search in sources :

Example 1 with AnswerAnnotation

use of edu.stanford.nlp.ling.CoreAnnotations.AnswerAnnotation in project cogcomp-nlp by CogComp.

the class StanfordParser method constructLabel.

/**
 * Determine what to return. If the input value is "O", and the prediction is
 * not, return the prediction (less the "B-" or "I-"). If the input is a hit,
 * and the prediction is a different ,
 * @param hits the phrase match including all tokens.
 * @return the list of labels.
 */
private String constructLabel(ArrayList<CoreLabel> hits) {
    final Class<AnswerAnnotation> cls = CoreAnnotations.AnswerAnnotation.class;
    final Class<GoldAnswerAnnotation> gcls = CoreAnnotations.GoldAnswerAnnotation.class;
    String firstLabel = hits.get(0).get(cls);
    String goldLabel = hits.get(0).get(gcls);
    // just make sure the programming logic is correct, we should never see mixed tokens.
    for (int i = 0; i < hits.size(); i++) {
        CoreLabel cl = hits.get(i);
        if (!cl.get(cls).equals(cl.get(gcls))) {
            // didn't match, decide what to return, make sure it doesn't match.
            if (goldLabel.equals("O"))
                return prune(firstLabel);
            else {
                String pruneGoldLabel = prune(goldLabel);
                String pruneAnswerLabel = prune(firstLabel);
                if (pruneGoldLabel.equals(pruneAnswerLabel)) {
                    // well, we can return a correct value here because we are not correct
                    return "O";
                } else {
                    return pruneAnswerLabel;
                }
            }
        }
    }
    return prune(firstLabel);
}
Also used : CoreLabel(edu.stanford.nlp.ling.CoreLabel) AnswerAnnotation(edu.stanford.nlp.ling.CoreAnnotations.AnswerAnnotation) GoldAnswerAnnotation(edu.stanford.nlp.ling.CoreAnnotations.GoldAnswerAnnotation) GoldAnswerAnnotation(edu.stanford.nlp.ling.CoreAnnotations.GoldAnswerAnnotation)

Aggregations

AnswerAnnotation (edu.stanford.nlp.ling.CoreAnnotations.AnswerAnnotation)1 GoldAnswerAnnotation (edu.stanford.nlp.ling.CoreAnnotations.GoldAnswerAnnotation)1 CoreLabel (edu.stanford.nlp.ling.CoreLabel)1