コード例 #1
0
 public void rank(String modelFile, String testFile, String indriRanking) {
   Ranker ranker = rFact.loadRanker(modelFile);
   int[] features = ranker.getFeatures();
   List<RankList> test = readInput(testFile);
   if (normalize) normalize(test, features);
   try {
     BufferedWriter out =
         new BufferedWriter(new OutputStreamWriter(new FileOutputStream(indriRanking), "ASCII"));
     for (int i = 0; i < test.size(); i++) {
       RankList l = test.get(i);
       double[] scores = new double[l.size()];
       for (int j = 0; j < l.size(); j++) scores[j] = ranker.eval(l.get(j));
       int[] idx = MergeSorter.sort(scores, false);
       for (int j = 0; j < idx.length; j++) {
         int k = idx[j];
         String str =
             l.getID()
                 + " Q0 "
                 + l.get(k).getDescription().replace("#", "").trim()
                 + " "
                 + (j + 1)
                 + " "
                 + SimpleMath.round(scores[k], 5)
                 + " indri";
         out.write(str);
         out.newLine();
       }
     }
     out.close();
   } catch (Exception ex) {
     System.out.println("Error in Evaluator::rank(): " + ex.toString());
   }
 }
コード例 #2
0
  public void rank(String modelFile, String testFile) {
    Ranker ranker = rFact.loadRanker(modelFile);
    int[] features = ranker.getFeatures();
    List<RankList> test = readInput(testFile);
    if (normalize) normalize(test, features);

    for (int i = 0; i < test.size(); i++) {
      RankList l = test.get(i);
      double[] scores = new double[l.size()];
      for (int j = 0; j < l.size(); j++) scores[j] = ranker.eval(l.get(j));
      int[] idx = Sorter.sort(scores, false);
      List<Integer> ll = new ArrayList<Integer>();
      for (int j = 0; j < idx.length; j++) ll.add(idx[j]);
      for (int j = 0; j < l.size(); j++) {
        int index = ll.indexOf(j) + 1;
        System.out.print(index + ((j == l.size() - 1) ? "" : " "));
      }
      System.out.println("");
    }
  }
コード例 #3
0
 public void score(String modelFile, String testFile, String outputFile) {
   Ranker ranker = rFact.loadRanker(modelFile);
   int[] features = ranker.getFeatures();
   List<RankList> test = readInput(testFile);
   if (normalize) normalize(test, features);
   try {
     BufferedWriter out =
         new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile), "ASCII"));
     for (int i = 0; i < test.size(); i++) {
       RankList l = test.get(i);
       for (int j = 0; j < l.size(); j++) {
         out.write(ranker.eval(l.get(j)) + "");
         out.newLine();
       }
     }
     out.close();
   } catch (Exception ex) {
     System.out.println("Error in Evaluator::rank(): " + ex.toString());
   }
 }