Fix Issue #371: Lexeme objects were unhashable.

This commit is contained in:
Matthew Honnibal 2016-09-27 13:22:30 +02:00
parent e382e48d9f
commit e233328d38
2 changed files with 13 additions and 0 deletions

View File

@ -68,6 +68,9 @@ cdef class Lexeme:
else: else:
raise NotImplementedError(op) raise NotImplementedError(op)
def __hash__(self):
return self.c.orth
def set_flag(self, attr_id_t flag_id, bint value): def set_flag(self, attr_id_t flag_id, bint value):
Lexeme.c_set_flag(self.c, flag_id, value) Lexeme.c_set_flag(self.c, flag_id, value)

View File

@ -30,3 +30,13 @@ def test_lexeme_lt(en_vocab):
assert noun < opera assert noun < opera
assert opera > noun assert opera > noun
def test_lexeme_hash(en_vocab):
'''Test that lexemes are hashable.'''
phantom = en_vocab['phantom']
opera = en_vocab['opera']
lexes = {phantom: phantom, opera: opera}
assert lexes[phantom].orth_ == 'phantom'
assert lexes[opera].orth_ == 'opera'