Search in sources :

Example 6 with ClassLabel

use of edu.cmu.minorthird.classify.ClassLabel in project lucida by claritylab.

the class ScoreNormalizationFilter method apply.

/**
	 * Normalizes the scores of the factoid answers, using the features
	 * specified in <code>SELECTED_FEATURES</code> and the classifier specified
	 * in <code>classifier</code>.
	 * 
	 * @param results array of <code>Result</code> objects
	 * @return array of <code>Result</code> objects with normalized scores
	 */
public Result[] apply(Result[] results) {
    // classifier not loaded
    if (classifier == null)
        return results;
    for (Result result : results) {
        // only factoid answers with 1 extraction technique
        if (result.getScore() <= 0 || result.getScore() == Float.POSITIVE_INFINITY || result.getExtractionTechniques() == null || result.getExtractionTechniques().length != 1)
            continue;
        // create instance with selected features
        Instance instance = createInstance(SELECTED_FEATURES, result, results);
        // classify instance
        ClassLabel label = classifier.classification(instance);
        // get weight of positive class as result score
        double weight = label.posProbability();
        result.setNormScore((float) weight);
    }
    // preserve original order of results
    //		results = preserveOrderResorting(results);
    //		results = preserveOrderAveraging(results);
    results = preserveOrderTop(results);
    return results;
}
Also used : ClassLabel(edu.cmu.minorthird.classify.ClassLabel) MutableInstance(edu.cmu.minorthird.classify.MutableInstance) Instance(edu.cmu.minorthird.classify.Instance) Result(info.ephyra.search.Result)

Example 7 with ClassLabel

use of edu.cmu.minorthird.classify.ClassLabel in project lucida by claritylab.

the class FeatureExtractor method createExample.

/**
     * Creates an edu.cmu.minorthird.classify.Example object from one line
     * of a dataset file using {@link #createInstance(String, String)}.
     * 
     * @param datasetLine the line from the dataset file from which to create
     * the Example 
     * @return the Example created
     * @throws Exception
     */
public Example[] createExample(String datasetLine) throws Exception {
    Matcher m = datasetExamplePattern.matcher(datasetLine);
    if (!m.matches())
        throw new Exception("Malformed dataset line:\n" + datasetLine);
    String[] aTypes = null;
    aTypes = m.group(labelPosition).replaceAll(",$", "").replaceAll(",", ".").split("\\|");
    String question = m.group(questionPosition);
    String sentParse = null;
    if (parsePosition > -1)
        sentParse = m.group(parsePosition);
    Instance instance = createInstance(question, sentParse);
    Example[] result = new Example[aTypes.length];
    //create example(s) and add it to list
    for (int i = 0; i < aTypes.length; i++) {
        String newATypeName = HierarchicalClassifier.getHierarchicalClassName(aTypes[i], classLevels, useClassLevels);
        result[i] = new Example(instance, new ClassLabel(newATypeName));
    }
    return result;
}
Also used : ClassLabel(edu.cmu.minorthird.classify.ClassLabel) Matcher(java.util.regex.Matcher) Instance(edu.cmu.minorthird.classify.Instance) Example(edu.cmu.minorthird.classify.Example)

Aggregations

ClassLabel (edu.cmu.minorthird.classify.ClassLabel)7 Example (edu.cmu.minorthird.classify.Example)3 Instance (edu.cmu.minorthird.classify.Instance)3 Classifier (edu.cmu.minorthird.classify.Classifier)2 MutableInstance (edu.cmu.minorthird.classify.MutableInstance)2 ClassifierLearner (edu.cmu.minorthird.classify.ClassifierLearner)1 AnswerType (info.ephyra.questionanalysis.atype.AnswerType)1 Result (info.ephyra.search.Result)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1