added __repr__ that prints text in ipython for doc, token, and span objects

This commit is contained in:
Andreas Grivas 2015-10-21 14:11:46 +03:00
parent f02a428fc7
commit 93ada458e2
3 changed files with 12 additions and 0 deletions

View File

@ -120,6 +120,9 @@ cdef class Doc:
def __str__(self):
return u''.join([t.string for t in self])
def __repr__(self):
return u''.join([t.string for t in self])
def similarity(self, other):
if self.vector_norm == 0 or other.vector_norm == 0:
return 0.0

View File

@ -46,6 +46,12 @@ cdef class Span:
return 0
return self.end - self.start
def __repr__(self):
text = self.text_with_ws
if self[-1].whitespace_:
text = text[:-1]
return text
def __getitem__(self, object i):
if isinstance(i, slice):
start, end = normalize_slice(len(self), i.start, i.stop, i.step)

View File

@ -43,6 +43,9 @@ cdef class Token:
def __str__(self):
return self.string
def __repr__(self):
return self.string
cpdef bint check_flag(self, attr_id_t flag_id) except -1:
return Lexeme.c_check_flag(self.c.lex, flag_id)