Merge pull request #147 from andreasgrv/master

add __repr__  print text default for doc, token, and span
This commit is contained in:
Matthew Honnibal 2015-10-22 21:45:41 +11:00
commit 57a68b0d03
3 changed files with 12 additions and 0 deletions

View File

@ -120,6 +120,9 @@ cdef class Doc:
def __str__(self): def __str__(self):
return u''.join([t.string for t in 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): def similarity(self, other):
if self.vector_norm == 0 or other.vector_norm == 0: if self.vector_norm == 0 or other.vector_norm == 0:
return 0.0 return 0.0

View File

@ -46,6 +46,12 @@ cdef class Span:
return 0 return 0
return self.end - self.start 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): def __getitem__(self, object i):
if isinstance(i, slice): if isinstance(i, slice):
start, end = normalize_slice(len(self), i.start, i.stop, i.step) start, end = normalize_slice(len(self), i.start, i.stop, i.step)

View File

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