This commit is contained in:
Andreas Grivas 2015-11-02 11:54:22 +00:00
commit b11fff8317
4 changed files with 103 additions and 5 deletions

View File

@ -0,0 +1,98 @@
# -*- coding: utf-8 -*-
import pytest
def test_print_doc(EN):
try:
doc = EN(u'I sat down for coffee at the coffee store')
print(doc)
except Exception:
pytest.fail("Printing failed")
def test_repr_doc(EN):
try:
doc = EN(u'I sat down for coffee at the coffee store')
print(repr(doc))
except Exception:
pytest.fail("Printing failed")
def test_print_doc_unicode(EN):
try:
doc = EN(u'I sat down for coffee at the café')
print(doc)
except Exception:
pytest.fail("Printing failed")
def test_repr_doc_unicode(EN):
try:
doc = EN(u'I sat down for coffee at the café')
print(repr(doc))
except Exception:
pytest.fail("Printing failed")
def test_print_span(EN):
try:
doc = EN(u'I sat down for coffee at the coffee store')[-3:]
print(doc)
except Exception:
pytest.fail("Printing failed")
def test_repr_span(EN):
try:
doc = EN(u'I sat down for coffee at the coffee store')[-3:]
print(repr(doc))
except Exception:
pytest.fail("Printing failed")
def test_print_span_unicode(EN):
try:
doc = EN(u'I sat down for coffee at the café')[-3:]
print(doc)
except Exception:
pytest.fail("Printing failed")
def test_repr_span_unicode(EN):
try:
doc = EN(u'I sat down for coffee at the café')[-3:]
print(repr(doc))
except Exception:
pytest.fail("Printing failed")
def test_print_token(EN):
try:
doc = EN(u'I sat down for coffee at the coffee store')[-1]
print(doc)
except Exception:
pytest.fail("Printing failed")
def test_repr_token(EN):
try:
doc = EN(u'I sat down for coffee at the coffee store')[-1]
print(repr(doc))
except Exception:
pytest.fail("Printing failed")
def test_print_token_unicode(EN):
try:
doc = EN(u'I sat down for coffee at the café')[-1]
print(doc)
except Exception:
pytest.fail("Printing failed")
def test_repr_token_unicode(EN):
try:
doc = EN(u'I sat down for coffee at the café')[-1]
print(repr(doc))
except Exception:
pytest.fail("Printing failed")

View File

@ -118,10 +118,10 @@ cdef class Doc:
return u''.join([t.string for t in self]) return u''.join([t.string for t in self])
def __str__(self): def __str__(self):
return u''.join([t.string for t in self]) return u''.join([t.string for t in self]).encode('utf-8')
def __repr__(self): def __repr__(self):
return u''.join([t.string for t in self]) return u''.join([t.string for t in self]).encode('utf-8')
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:

View File

@ -50,7 +50,7 @@ cdef class Span:
text = self.text_with_ws text = self.text_with_ws
if self[-1].whitespace_: if self[-1].whitespace_:
text = text[:-1] text = text[:-1]
return text return text.encode('utf-8')
def __getitem__(self, object i): def __getitem__(self, object i):
if isinstance(i, slice): if isinstance(i, slice):

View File

@ -41,10 +41,10 @@ cdef class Token:
return self.string return self.string
def __str__(self): def __str__(self):
return self.string return self.string.encode('utf-8')
def __repr__(self): def __repr__(self):
return self.string return self.string.encode('utf-8')
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)