Spacy: Compare operator (==) behaves unexpectedly on spacy tokens

Created on 14 Aug 2017  路  3Comments  路  Source: explosion/spaCy

nlp = spacy.load("en")
doc1 = nlp(u"I am here")
doc2 = nlp(u"Hello")

doc1[0] == doc2[0]
True

In the above snippet, spacy is treating 1st token of both the docs as equal. So, in the below source code the __richcmp__ method it is using index to compare.

def __richcmp__(self, Token other, int op):
        # http://cython.readthedocs.io/en/latest/src/userguide/special_methods.html
        my = self.idx
        their = other.idx if other is not None else None

Environment

  • Python version: 2.7.10
  • Platform: Darwin-16.0.0-x86_64-i386-64bit
  • spaCy version: 1.9.0
  • Installed models: en
bug

Most helpful comment

Fixed :)

All 3 comments

Thanks, this must've been in there a long time. If you want to submit a patch for this, the best solution would be to check that other.doc is self

Fixed :)

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

peterroelants picture peterroelants  路  3Comments

armsp picture armsp  路  3Comments

besirkurtulmus picture besirkurtulmus  路  3Comments

ajayrfhp picture ajayrfhp  路  3Comments

norrishd picture norrishd  路  3Comments