Skip to content

Commit

Permalink
Mirror update in analyze method in underlying Java code (#30)
Browse files Browse the repository at this point in the history
i.e., analyze returns list of tokens, not just the first.
  • Loading branch information
zeynepakkalyoncu authored and lintool committed Jan 16, 2020
1 parent b1c4393 commit b336a8c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
10 changes: 7 additions & 3 deletions pyserini/index/pyutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,21 @@ def __init__(self, term, doc_freq, total_term_freq):
self.doc_freq = doc_freq
self.total_term_freq = total_term_freq

def analyze_term(self, term):
def analyze(self, text):
'''
Parameters
----------
term : str
Returns
-------
result : str
Stemmed term
List of stemmed tokens
'''
return self.object.analyzeTerm(JString(term))
stemmed = self.object.analyze(JString(text))
token_list = []
for token in stemmed.toArray():
token_list.append(token)
return token_list

def terms(self):
'''
Expand Down
9 changes: 5 additions & 4 deletions tests/test_indexutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ def setUp(self):
def test_terms(self):
self.assertEqual(sum(1 for x in self.index_utils.terms()), 14363)

def test_term_stats(self):
term = 'retrieval'
self.assertEqual(self.index_utils.analyze_term(term), 'retriev')
def test_analyze(self):
self.assertEqual(' '.join(self.index_utils.analyze('retrieval')), 'retriev')
self.assertEqual(' '.join(self.index_utils.analyze('rapid retrieval, space economy')), 'rapid retriev space economi')

collection_freq, doc_freq = self.index_utils.get_term_counts(term)
def test_term_stats(self):
collection_freq, doc_freq = self.index_utils.get_term_counts('retrieval')
self.assertEqual(collection_freq, 275)
self.assertEqual(doc_freq, 138)

Expand Down

0 comments on commit b336a8c

Please sign in to comment.