mirror of
https://github.com/explosion/spaCy.git
synced 2024-11-10 19:57:17 +03:00
Fix Issue #371: Lexeme objects were unhashable.
This commit is contained in:
parent
e382e48d9f
commit
e233328d38
|
@ -68,6 +68,9 @@ cdef class Lexeme:
|
|||
else:
|
||||
raise NotImplementedError(op)
|
||||
|
||||
def __hash__(self):
|
||||
return self.c.orth
|
||||
|
||||
def set_flag(self, attr_id_t flag_id, bint value):
|
||||
Lexeme.c_set_flag(self.c, flag_id, value)
|
||||
|
||||
|
|
|
@ -30,3 +30,13 @@ def test_lexeme_lt(en_vocab):
|
|||
assert noun < opera
|
||||
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'
|
||||
|
|
Loading…
Reference in New Issue
Block a user