mirror of
https://github.com/explosion/spaCy.git
synced 2025-06-02 20:23:12 +03:00
Use the same tuple in Span cmp and hash (#12251)
This commit is contained in:
parent
eec5ccd72f
commit
5089efa2d0
|
@ -134,10 +134,8 @@ cdef class Span:
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
cdef SpanC* span_c = self.span_c()
|
self_tuple = self._cmp_tuple()
|
||||||
cdef SpanC* other_span_c = other.span_c()
|
other_tuple = other._cmp_tuple()
|
||||||
self_tuple = (span_c.start_char, span_c.end_char, span_c.label, span_c.kb_id, self.id, self.doc)
|
|
||||||
other_tuple = (other_span_c.start_char, other_span_c.end_char, other_span_c.label, other_span_c.kb_id, other.id, other.doc)
|
|
||||||
# <
|
# <
|
||||||
if op == 0:
|
if op == 0:
|
||||||
return self_tuple < other_tuple
|
return self_tuple < other_tuple
|
||||||
|
@ -158,8 +156,20 @@ cdef class Span:
|
||||||
return self_tuple >= other_tuple
|
return self_tuple >= other_tuple
|
||||||
|
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
|
return hash(self._cmp_tuple())
|
||||||
|
|
||||||
|
def _cmp_tuple(self):
|
||||||
cdef SpanC* span_c = self.span_c()
|
cdef SpanC* span_c = self.span_c()
|
||||||
return hash((self.doc, span_c.start_char, span_c.end_char, span_c.label, span_c.kb_id, span_c.id))
|
return (
|
||||||
|
span_c.start_char,
|
||||||
|
span_c.end_char,
|
||||||
|
span_c.start,
|
||||||
|
span_c.end,
|
||||||
|
span_c.label,
|
||||||
|
span_c.kb_id,
|
||||||
|
span_c.id,
|
||||||
|
self.doc,
|
||||||
|
)
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
"""Get the number of tokens in the span.
|
"""Get the number of tokens in the span.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user