diff --git a/.gitignore b/.gitignore index 64f24a487..8716a8ef0 100644 --- a/.gitignore +++ b/.gitignore @@ -105,3 +105,7 @@ website/package.json website/announcement.jade website/www/ website/.gitignore + +# Python virtualenv +venv +venv/* diff --git a/spacy/tests/spans/test_span.py b/spacy/tests/spans/test_span.py index 79505f1cb..14c176edc 100644 --- a/spacy/tests/spans/test_span.py +++ b/spacy/tests/spans/test_span.py @@ -31,6 +31,12 @@ def test_spans_root(doc): assert span.root.text == 'sentence' assert span.root.head.text == 'is' +def test_spans_string_fn(doc): + span = doc[0:4] + assert len(span) == 4 + assert span.text == 'This is a sentence' + assert span.upper_ == 'THIS IS A SENTENCE' + assert span.lower_ == 'this is a sentence' def test_spans_root2(en_tokenizer): text = "through North and South Carolina" diff --git a/spacy/tokens/span.pyx b/spacy/tokens/span.pyx index 903ef26d1..fc5d26174 100644 --- a/spacy/tokens/span.pyx +++ b/spacy/tokens/span.pyx @@ -365,6 +365,14 @@ cdef class Span: def __get__(self): return ' '.join([t.lemma_ for t in self]).strip() + property upper_: + def __get__(self): + return ''.join([t.string.upper() for t in self]).strip() + + property lower_: + def __get__(self): + return ''.join([t.string.lower() for t in self]).strip() + property string: def __get__(self): return ''.join([t.string for t in self])