spaCy/tests/test_contractions.py

58 lines
1.3 KiB
Python
Raw Normal View History

from __future__ import unicode_literals
2014-12-21 09:41:13 +00:00
import pytest
2014-12-21 09:41:13 +00:00
from spacy.en import English
2014-12-21 09:41:13 +00:00
@pytest.fixture
def EN():
2014-12-30 10:34:09 +00:00
return English()
2014-12-21 09:41:13 +00:00
def test_possess(EN):
tokens = EN("Mike's", parse=False)
2015-01-22 15:08:25 +00:00
assert EN.vocab.strings[tokens[0].orth] == "Mike"
assert EN.vocab.strings[tokens[1].orth] == "'s"
assert len(tokens) == 2
2014-12-21 09:41:13 +00:00
def test_apostrophe(EN):
tokens = EN("schools'")
assert len(tokens) == 2
assert tokens[1].orth_ == "'"
assert tokens[0].orth_ == "schools"
2014-12-21 09:41:13 +00:00
def test_LL(EN):
tokens = EN("we'll", parse=False)
assert len(tokens) == 2
assert tokens[1].orth_ == "'ll"
assert tokens[1].lemma_ == "will"
assert tokens[0].orth_ == "we"
2014-12-21 09:41:13 +00:00
def test_aint(EN):
tokens = EN("ain't", parse=False)
assert len(tokens) == 2
assert tokens[0].orth_ == "ai"
assert tokens[0].lemma_ == "be"
assert tokens[1].orth_ == "n't"
assert tokens[1].lemma_ == "not"
2014-12-21 09:41:13 +00:00
def test_capitalized(EN):
tokens = EN("can't", parse=False)
assert len(tokens) == 2
tokens = EN("Can't", parse=False)
assert len(tokens) == 2
tokens = EN("Ain't", parse=False)
assert len(tokens) == 2
assert tokens[0].orth_ == "Ai"
assert tokens[0].lemma_ == "be"
2014-12-07 11:08:04 +00:00
2014-12-21 09:41:13 +00:00
def test_punct(EN):
tokens = EN("We've", parse=False)
2014-12-07 11:08:04 +00:00
assert len(tokens) == 2
tokens = EN("``We've", parse=False)
2014-12-07 11:08:04 +00:00
assert len(tokens) == 3