public DBpediaResource choose(ScoreDoc[] hits) throws SearchException {
Map<DBpediaResource,Double> sumForResource = new HashMap<DBpediaResource,Double>();
Map<DBpediaResource,Integer> countForResource = new HashMap<DBpediaResource,Integer>();
// Iterate through the results:
for (ScoreDoc hit : hits) {
DBpediaResource r = this.searcher.getDBpediaResource(hit.doc);
if (countForResource.containsKey(r)) {
countForResource.put(r, countForResource.get(r)+1);
sumForResource.put(r, sumForResource.get(r)+hit.score);
} else {
countForResource.put(r, 1);
sumForResource.put(r, new Double(hit.score));
}
}
for (Map.Entry<DBpediaResource,Double> entry: sumForResource.entrySet()) {
DBpediaResource key = entry.getKey();
Double sum = entry.getValue();
Integer count = countForResource.get(key);
sumForResource.put(key, sum/count);
}
return maxAvg(sumForResource);