Skip to content

Commit

Permalink
Fix bug in meteor (nltk#2619)
Browse files Browse the repository at this point in the history
* passing preprocess arg to single_meteor_score function call

* adding test case

* updating authors
  • Loading branch information
AkshitaB authored Nov 23, 2020
1 parent 860c494 commit df8cab1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@
- Jacob Moorman <https://github.com/jdmoorman>
- Cory Nezin <https://github.com/corynezin>
- Matt Chaput
- Akshita Bhagia <https://github.com/AkshitaB>

## Others whose work we've taken and included in NLTK, but who didn't directly contribute it:
### Contributors to the Porter Stemmer
Expand Down
16 changes: 16 additions & 0 deletions nltk/test/unit/translate/test_meteor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import unittest

from nltk.translate.meteor_score import meteor_score

class TestMETEOR(unittest.TestCase):
def test_preprocess(self):
# Using lists instead of strings specifically to demonstrate use of `preprocess`.
reference = [['this', 'is', 'a', 'test'], ['this', 'is' 'test']]
candidate = ['this', 'is', 'a', 'test']

# no `preprocess` argument
self.assertRaises(TypeError, meteor_score, reference, candidate)

# with `preprocess` argument
score = meteor_score(reference, candidate, preprocess=lambda x: ' '.join(x))
assert score == 0.9921875
1 change: 1 addition & 0 deletions nltk/translate/meteor_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ def meteor_score(
single_meteor_score(
reference,
hypothesis,
preprocess=preprocess,
stemmer=stemmer,
wordnet=wordnet,
alpha=alpha,
Expand Down

0 comments on commit df8cab1

Please sign in to comment.