mirror of https://github.com/explosion/spaCy.git
Fix Issue #371: Lexeme objects were unhashable.
This commit is contained in:
parent
e382e48d9f
commit
e233328d38
|
@ -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)
|
||||||
|
|
||||||
|
|
|
@ -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'
|
||||||
|
|
Loading…
Reference in New Issue