use of info.ephyra.search.Result in project lucida by claritylab.
the class ScoreNormalizationFilter method addNumAnswersFeature.
/**
* Adds the number of factoid answers from the same extractor as a feature
* to the instance.
*/
private static void addNumAnswersFeature(MutableInstance instance, Result result, Result[] results) {
// get number of factoid answers
int numFactoid = 0;
// String extractor = result.getExtractionTechniques()[0];
for (Result r : results) if (r.getScore() > 0 && r.getScore() < Float.POSITIVE_INFINITY)
// if (r.extractedWith(extractor))
numFactoid++;
Feature feature = new Feature(NUM_ANSWERS_F);
instance.addNumeric(feature, numFactoid);
}
use of info.ephyra.search.Result in project lucida by claritylab.
the class ScoreNormalizationFilter method preserveOrderResorting.
/**
* Reassigns the normalized scores for each extraction technique to ensure
* that the order suggested by the original scores is preserved.
*
* @param results array of <code>Result</code> objects
* @return array of <code>Result</code> objects with new normalized scores
*/
public Result[] preserveOrderResorting(Result[] results) {
List<Result> allResults = new ArrayList<Result>();
// get answers by extractors
Hashtable<String, ArrayList<Result>> allExtracted = new Hashtable<String, ArrayList<Result>>();
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) {
allResults.add(result);
continue;
}
String extractor = result.getExtractionTechniques()[0];
ArrayList<Result> extracted = allExtracted.get(extractor);
if (extracted == null) {
extracted = new ArrayList<Result>();
allExtracted.put(extractor, extracted);
}
extracted.add(result);
}
// normalize answer scores for each extractor
for (List<Result> extracted : allExtracted.values()) {
// sort results by their normalized scores in descending order
Result[] factoids = extracted.toArray(new Result[extracted.size()]);
factoids = (new NormalizedScoreSorterFilter()).apply(factoids);
// get sorted normalized scores
float[] normScores = new float[factoids.length];
for (int i = 0; i < factoids.length; i++) normScores[i] = factoids[i].getNormScore();
// sort results by their original scores in descending order
factoids = (new ScoreSorterFilter()).apply(factoids);
// reassign sorted normalized scores
for (int i = 0; i < factoids.length; i++) factoids[i].setNormScore(normScores[i]);
// merge answers
for (Result norm : factoids) allResults.add(norm);
}
return allResults.toArray(new Result[allResults.size()]);
}
use of info.ephyra.search.Result in project lucida by claritylab.
the class ScoreNormalizationFilter method addMinScoreFeature.
/**
* Adds the minimum score of all factoid answers from the same extractor as
* a feature to the instance.
*/
private static void addMinScoreFeature(MutableInstance instance, Result result, Result[] results) {
// calculate minimum score
double minScore = Double.POSITIVE_INFINITY;
// String extractor = result.getExtractionTechniques()[0];
for (Result r : results) if (r.getScore() > 0 && r.getScore() < Float.POSITIVE_INFINITY)
// if (r.extractedWith(extractor))
minScore = Math.min(r.getScore(), minScore);
Feature feature = new Feature(MIN_SCORE_F);
instance.addNumeric(feature, minScore);
}
use of info.ephyra.search.Result 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 info.ephyra.search.Result in project lucida by claritylab.
the class ScoreNormalizationFilter method createDataset.
/**
* Creates a training/evaluation set from serialized judged
* <code>Result</code> objects.
*
* @param features selected features
* @param serializedDir directory containing serialized results
* @return training/evaluation set
*/
private static Dataset createDataset(String[] features, String serializedDir) {
Dataset set = new BasicDataset();
File[] files = FileUtils.getFilesRec(serializedDir);
for (File file : files) {
// one file per question
String filename = file.getName();
if (!filename.endsWith(".serialized"))
continue;
// get question ID and results
String qid = filename.replace(".serialized", "");
Result[] results = readSerializedResults(file);
// create examples and add to data set
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;
Example example = createExample(features, result, results, qid);
set.add(example);
}
}
return set;
}
Aggregations