Commit af62470029698a1ee74f53fc63fae19f1191b874

Authored by Scott Klum
1 parent b7b7bf7b

Better rank output

Showing 1 changed file with 29 additions and 7 deletions
openbr/plugins/output/rank.cpp
@@ -22,6 +22,23 @@ @@ -22,6 +22,23 @@
22 namespace br 22 namespace br
23 { 23 {
24 24
  25 +struct RankResult
  26 +{
  27 + int rank;
  28 + float score;
  29 + File probe, target;
  30 +
  31 + bool operator<(const RankResult &other) const
  32 + {
  33 + return this->rank < other.rank;
  34 + }
  35 +
  36 + QString toLine(const QChar &separator) const
  37 + {
  38 + return probe.fileName() + separator + QString::number(rank) + separator + QString::number(score) + separator+ target.fileName();
  39 + }
  40 +};
  41 +
25 /*! 42 /*!
26 * \ingroup outputs 43 * \ingroup outputs
27 * \brief Outputs highest ranked matches with scores. 44 * \brief Outputs highest ranked matches with scores.
@@ -40,6 +57,8 @@ class rankOutput : public MatrixOutput @@ -40,6 +57,8 @@ class rankOutput : public MatrixOutput
40 QList<float> scores; 57 QList<float> scores;
41 QStringList lines; 58 QStringList lines;
42 59
  60 + QList<RankResult> results;
  61 +
43 for (int i=0; i<queryFiles.size(); i++) { 62 for (int i=0; i<queryFiles.size(); i++) {
44 typedef QPair<float,int> Pair; 63 typedef QPair<float,int> Pair;
45 int rank = 1; 64 int rank = 1;
@@ -48,9 +67,12 @@ class rankOutput : public MatrixOutput @@ -48,9 +67,12 @@ class rankOutput : public MatrixOutput
48 if (Globals->crossValidate > 0 ? (targetFiles[pair.second].get<int>("Partition",-1) == -1 || targetFiles[pair.second].get<int>("Partition",-1) == queryFiles[i].get<int>("Partition",-1)) : true) { 67 if (Globals->crossValidate > 0 ? (targetFiles[pair.second].get<int>("Partition",-1) == -1 || targetFiles[pair.second].get<int>("Partition",-1) == queryFiles[i].get<int>("Partition",-1)) : true) {
49 if (QString(targetFiles[pair.second]) != QString(queryFiles[i])) { 68 if (QString(targetFiles[pair.second]) != QString(queryFiles[i])) {
50 if (targetFiles[pair.second].get<QString>("Label") == queryFiles[i].get<QString>("Label")) { 69 if (targetFiles[pair.second].get<QString>("Label") == queryFiles[i].get<QString>("Label")) {
51 - ranks.append(rank);  
52 - positions.append(pair.second);  
53 - scores.append(pair.first); 70 + RankResult result;
  71 + result.rank = rank;
  72 + result.score = pair.first;
  73 + result.probe = queryFiles[i];
  74 + result.target = targetFiles[pair.second];
  75 + results.append(result);
54 break; 76 break;
55 } 77 }
56 rank++; 78 rank++;
@@ -59,10 +81,10 @@ class rankOutput : public MatrixOutput @@ -59,10 +81,10 @@ class rankOutput : public MatrixOutput
59 } 81 }
60 } 82 }
61 83
62 - typedef QPair<int,int> RankPair;  
63 - foreach (const RankPair &pair, Common::Sort(ranks, false))  
64 - // pair.first == rank retrieved, pair.second == original position  
65 - lines.append(queryFiles[pair.second].name + " " + QString::number(pair.first) + " " + QString::number(scores[pair.second]) + " " + targetFiles[positions[pair.second]].name); 84 + std::sort(results.begin(), results.end(), std::less<RankResult>());
  85 +
  86 + foreach (const RankResult &result, results)
  87 + lines.append(result.toLine('\t'));
66 88
67 89
68 QtUtils::writeFile(file, lines); 90 QtUtils::writeFile(file, lines);