-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e5129bf
commit 5585426
Showing
3 changed files
with
42 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import unittest | ||
import numpy as np | ||
import pandas as pd | ||
from pyterrier_dr import MmrScorer | ||
|
||
|
||
class TestMmr(unittest.TestCase): | ||
def test_mmr(self): | ||
mmr = MmrScorer() | ||
results = mmr(pd.DataFrame([ | ||
['q0', 'd0', 1.0, np.array([0, 1, 0])], | ||
['q0', 'd1', 0.5, np.array([0, 1, 1])], | ||
['q0', 'd2', 0.5, np.array([1, 1, 1])], | ||
['q0', 'd3', 0.1, np.array([1, 1, 0])], | ||
['q1', 'd0', 0.6, np.array([0, 1, 0])], | ||
['q2', 'd0', 0.4, np.array([0, 1, 0])], | ||
['q2', 'd1', 0.3, np.array([0, 1, 1])], | ||
], columns=['qid', 'docno', 'score', 'doc_vec'])) | ||
pd.testing.assert_frame_equal(results, pd.DataFrame([ | ||
['q0', 'd0', 0.0, 0], | ||
['q0', 'd2', -1.0, 1], | ||
['q0', 'd1', -2.0, 2], | ||
['q0', 'd3', -3.0, 3], | ||
['q1', 'd0', 0.0, 0], | ||
['q2', 'd0', 0.0, 0], | ||
['q2', 'd1', -1.0, 1], | ||
], columns=['qid', 'docno', 'score', 'rank'])) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |