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;
}
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;
}
Aggregations