From 8ae8b443f15b287534b22613553e47a3c3096aac Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Mon, 9 Jan 2017 19:30:31 +0100 Subject: [PATCH] Add richcmp method to Token. Closes #631 --- spacy/tokens/token.pyx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/spacy/tokens/token.pyx b/spacy/tokens/token.pyx index b2b7dc83f..ff1c6149d 100644 --- a/spacy/tokens/token.pyx +++ b/spacy/tokens/token.pyx @@ -60,6 +60,25 @@ cdef class Token: def __repr__(self): return self.__str__() + def __richcmp__(self, other, int op): + # http://cython.readthedocs.io/en/latest/src/userguide/special_methods.html + my = self.idx + their = other.idx + if op == 0: + return my < their + elif op == 2: + return my == their + elif op == 4: + return my > their + elif op == 1: + return my <= their + elif op == 3: + return my != their + elif op == 5: + return my >= their + else: + raise ValueError(op) + cpdef bint check_flag(self, attr_id_t flag_id) except -1: '''Check the value of a boolean flag.