2014-07-05 18:51:42 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2014-12-23 00:40:32 +00:00
|
|
|
from spacy.en import English
|
2014-07-05 18:51:42 +00:00
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def close_puncts():
|
|
|
|
return [')', ']', '}', '*']
|
|
|
|
|
|
|
|
|
2014-12-23 00:40:32 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def EN():
|
|
|
|
return English()
|
|
|
|
|
|
|
|
|
|
|
|
def test_close(close_puncts, EN):
|
2014-07-05 18:51:42 +00:00
|
|
|
word_str = 'Hello'
|
|
|
|
for p in close_puncts:
|
|
|
|
string = word_str + p
|
2014-12-23 00:40:32 +00:00
|
|
|
tokens = EN(string)
|
2014-07-05 18:51:42 +00:00
|
|
|
assert len(tokens) == 2
|
2014-08-27 17:38:57 +00:00
|
|
|
assert tokens[1].string == p
|
|
|
|
assert tokens[0].string == word_str
|
2014-07-05 18:51:42 +00:00
|
|
|
|
|
|
|
|
2014-12-23 00:40:32 +00:00
|
|
|
def test_two_different_close(close_puncts, EN):
|
2014-07-05 18:51:42 +00:00
|
|
|
word_str = 'Hello'
|
|
|
|
for p in close_puncts:
|
|
|
|
string = word_str + p + "'"
|
2014-12-23 00:40:32 +00:00
|
|
|
tokens = EN(string)
|
2014-07-05 18:51:42 +00:00
|
|
|
assert len(tokens) == 3
|
2014-08-27 17:38:57 +00:00
|
|
|
assert tokens[0].string == word_str
|
|
|
|
assert tokens[1].string == p
|
|
|
|
assert tokens[2].string == "'"
|
2014-07-05 18:51:42 +00:00
|
|
|
|
|
|
|
|
2014-12-23 00:40:32 +00:00
|
|
|
def test_three_same_close(close_puncts, EN):
|
2014-07-05 18:51:42 +00:00
|
|
|
word_str = 'Hello'
|
|
|
|
for p in close_puncts:
|
|
|
|
string = word_str + p + p + p
|
2014-12-23 00:40:32 +00:00
|
|
|
tokens = EN(string)
|
2014-07-06 18:02:00 +00:00
|
|
|
assert len(tokens) == 4
|
2014-08-27 17:38:57 +00:00
|
|
|
assert tokens[0].string == word_str
|
|
|
|
assert tokens[1].string == p
|
2014-11-02 10:24:09 +00:00
|
|
|
|
|
|
|
|
2014-12-23 00:40:32 +00:00
|
|
|
def test_double_end_quote(EN):
|
|
|
|
assert len(EN("Hello''")) == 2
|
|
|
|
assert len(EN("''")) == 1
|
2014-11-02 10:24:09 +00:00
|
|
|
|