mirror of
https://github.com/explosion/spaCy.git
synced 2025-06-03 20:53:12 +03:00
Fix comparison of Token from different docs. Closes #1257
This commit is contained in:
parent
9b6a5df15e
commit
d55d6e1cfa
12
spacy/tests/regression/test_issue1257.py
Normal file
12
spacy/tests/regression/test_issue1257.py
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
'''Test tokens compare correctly'''
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from ..util import get_doc
|
||||||
|
from ...vocab import Vocab
|
||||||
|
|
||||||
|
|
||||||
|
def test_issue1257():
|
||||||
|
doc1 = get_doc(Vocab(), ['a', 'b', 'c'])
|
||||||
|
doc2 = get_doc(Vocab(), ['a', 'c', 'e'])
|
||||||
|
assert doc1[0] != doc2[0]
|
||||||
|
assert not doc1[0] == doc2[0]
|
|
@ -62,18 +62,26 @@ cdef class Token:
|
||||||
|
|
||||||
def __richcmp__(self, Token other, int op):
|
def __richcmp__(self, Token other, int op):
|
||||||
# http://cython.readthedocs.io/en/latest/src/userguide/special_methods.html
|
# http://cython.readthedocs.io/en/latest/src/userguide/special_methods.html
|
||||||
|
cdef Doc my_doc = self.doc
|
||||||
|
cdef Doc other_doc = other.doc
|
||||||
my = self.idx
|
my = self.idx
|
||||||
their = other.idx if other is not None else None
|
their = other.idx if other is not None else None
|
||||||
if op == 0:
|
if op == 0:
|
||||||
return my < their
|
return my < their
|
||||||
elif op == 2:
|
elif op == 2:
|
||||||
return my == their
|
if my_doc is other_doc:
|
||||||
|
return my == their
|
||||||
|
else:
|
||||||
|
return False
|
||||||
elif op == 4:
|
elif op == 4:
|
||||||
return my > their
|
return my > their
|
||||||
elif op == 1:
|
elif op == 1:
|
||||||
return my <= their
|
return my <= their
|
||||||
elif op == 3:
|
elif op == 3:
|
||||||
return my != their
|
if my_doc is other_doc:
|
||||||
|
return my != their
|
||||||
|
else:
|
||||||
|
return True
|
||||||
elif op == 5:
|
elif op == 5:
|
||||||
return my >= their
|
return my >= their
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user