Search in sources :

Example 1 with Ranker

use of ciir.umass.edu.learning.Ranker in project Anserini by castorini.

the class RankLibScorer method main.

public static void main(String[] args) throws IOException {
    ParseArgs parsedArgs = new ParseArgs();
    CmdLineParser parser = new CmdLineParser(parsedArgs, ParserProperties.defaults().withUsageWidth(90));
    try {
        parser.parseArgument(args);
    } catch (CmdLineException e) {
        System.err.println(e.getMessage());
        parser.printUsage(System.err);
        System.err.println("Example: SearchTweets" + parser.printExample(OptionHandlerFilter.REQUIRED));
        return;
    }
    Qrels qrels = new Qrels(parsedArgs.qrels);
    BufferedReader reader = new BufferedReader(new FileReader(parsedArgs.featureFile));
    // Map of qid:docId -> datapoint
    Map<String, DataPoint> featureMap = new HashMap<>();
    Ranker ranker = new RankerFactory().loadRanker(parsedArgs.model);
    String line = reader.readLine();
    // qrel qid featureVector # docid
    while (line != null) {
        DataPoint dp = new DataPoint(line);
        String[] pieces = line.split(" ");
        String key = pieces[1] + " " + pieces[pieces.length - 1];
        featureMap.put(key, dp);
        line = reader.readLine();
    }
    BufferedWriter writer = new BufferedWriter(new FileWriter(parsedArgs.output));
    // qid, Q0, docid, 0(rank), score, LUCENE
    for (String key : featureMap.keySet()) {
        StringBuilder sb = new StringBuilder();
        String[] pieces = key.split(" ");
        sb.append(pieces[0]);
        sb.append(" Q0 ");
        sb.append(pieces[1]);
        sb.append(" 0 ");
        double score = ranker.eval(featureMap.get(key));
        sb.append(score);
        sb.append(" LUCENE");
        writer.write(sb.toString());
        writer.newLine();
    }
    writer.flush();
    writer.close();
}
Also used : Qrels(io.anserini.util.Qrels) HashMap(java.util.HashMap) Ranker(ciir.umass.edu.learning.Ranker) DataPoint(ciir.umass.edu.learning.DataPoint) RankerFactory(ciir.umass.edu.learning.RankerFactory)

Aggregations

DataPoint (ciir.umass.edu.learning.DataPoint)1 Ranker (ciir.umass.edu.learning.Ranker)1 RankerFactory (ciir.umass.edu.learning.RankerFactory)1 Qrels (io.anserini.util.Qrels)1 HashMap (java.util.HashMap)1