Skip to content

Commit

Permalink
fix RRE export format (#929)
Browse files Browse the repository at this point in the history
* add test for the ratings format that confirms int values not floats...

* change the output format to be what RRE does and RankQuest expects.

* lint

* messaging
  • Loading branch information
epugh authored Jan 20, 2025
1 parent 3c152c8 commit ebbe2ba
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
5 changes: 2 additions & 3 deletions app/assets/javascripts/components/export_case/_modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,9 @@ <h3 class="modal-title">Export Case: <span class="modal-case">{{ ctrl.theCase.ca
<hr/>
<div class="form-group">
<input type="radio" id="rre" name="exportSelection" value="rre" ng-model="ctrl.options.which">
<label for="rre">Rated Ranking Evaluator</label>
<label for="rre">Rated Ranking Evaluator / RankQuest</label>
<span class="help-block">
Need to gather relevance metrics for 1000's of queries? <a href="https://github.com/SeaseLtd/rated-ranking-evaluator" target="_blank">Rated Ranking Evaluator</a> is a great option! This exports
the judgement list in the RRE format.
Using <a href="https://github.com/SeaseLtd/rated-ranking-evaluator" target="_blank">Rated Ranking Evaluator</a> or <a href="https://rankquest.jillesvangurp.com/" target="_blank">RankQuest</a>? Use the RRE format to export the ratings from Quepid to import into those tools.
</span>
</div>
<div class="form-group">
Expand Down
15 changes: 2 additions & 13 deletions app/views/api/v1/export/ratings/_rre_query.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,8 @@ json.placeholders do
json.set!('$query', query.query_text)
end

grouped_ratings = {}

query.ratings.fully_rated.each do |r|
# rubocop:disable Style/IfUnlessModifier
unless grouped_ratings.key?(r.rating)
grouped_ratings[r.rating] = []
end
# rubocop:enable Style/IfUnlessModifier
grouped_ratings[r.rating] << r.doc_id
end

json.relevant_documents do
grouped_ratings.sort.to_h.each do |key, value|
json.set!(key, value)
query.ratings.fully_rated.each do |r|
json.set!(r.doc_id, { gain: r.rating.to_i } )
end
end
16 changes: 14 additions & 2 deletions test/controllers/api/v1/export/ratings_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class RatingsControllerTest < ActionController::TestCase
end

describe 'Exporting a case in RRE json format' do
let(:the_case) { cases(:one) }
let(:the_case) { cases(:queries_case) }

test 'returns case info' do
get :show, params: { case_id: the_case.id, file_format: 'rre' }
Expand All @@ -57,7 +57,19 @@ class RatingsControllerTest < ActionController::TestCase
assert_equal body['queries'].size, the_case.queries.size
assert_equal body['queries'][1]['placeholders']['$query'], the_case.queries[1].query_text
assert_equal body['queries'][2]['placeholders']['$query'], the_case.queries[2].query_text
assert_nil body['queries'][2]['relevant_documents']
assert_not_nil body['queries'][2]['relevant_documents']

# somewhat verbose RRE format for describing ratings.
expected_relevant_docs = {
docb: {
gain: 1,
},
doca: {
gain: 3,
},
}

assert_equal expected_relevant_docs, body['queries'][2]['relevant_documents'].deep_symbolize_keys
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/teams.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
valid:
name: valid team
owner: :doug
cases: shared_through_owned_team
cases: shared_through_owned_team, queries_case
members: doug

shared:
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/tries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ for_case_queries_case:
case: :queries_case
query_params: 'q=#$query##'
try_number: 1
field_spec: id:id title:title
search_endpoint: :for_case_queries_case
number_of_rows: 10
field_spec: id:id title:title
Expand Down

0 comments on commit ebbe2ba

Please sign in to comment.