2014-07-05 22:51:42 +04:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2014-12-23 03:40:32 +03:00
|
|
|
from spacy.en import English
|
2014-07-05 22:51:42 +04:00
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def open_puncts():
|
|
|
|
return ['(', '[', '{', '*']
|
|
|
|
|
|
|
|
|
2014-12-23 03:40:32 +03:00
|
|
|
@pytest.fixture
|
|
|
|
def EN():
|
2014-12-23 05:18:59 +03:00
|
|
|
return English(tag=False, parse=False)
|
2014-12-23 03:40:32 +03:00
|
|
|
|
|
|
|
|
|
|
|
def test_open(open_puncts, EN):
|
2014-07-05 22:51:42 +04:00
|
|
|
word_str = 'Hello'
|
|
|
|
for p in open_puncts:
|
|
|
|
string = p + word_str
|
2014-12-23 03:40:32 +03:00
|
|
|
tokens = EN(string)
|
2014-07-05 22:51:42 +04:00
|
|
|
assert len(tokens) == 2
|
2014-08-27 21:38:57 +04:00
|
|
|
assert tokens[0].string == p
|
|
|
|
assert tokens[1].string == word_str
|
2014-07-05 22:51:42 +04:00
|
|
|
|
|
|
|
|
2014-12-23 03:40:32 +03:00
|
|
|
def test_two_different_open(open_puncts, EN):
|
2014-07-05 22:51:42 +04:00
|
|
|
word_str = 'Hello'
|
|
|
|
for p in open_puncts:
|
|
|
|
string = p + "`" + word_str
|
2014-12-23 03:40:32 +03:00
|
|
|
tokens = EN(string)
|
2014-07-05 22:51:42 +04:00
|
|
|
assert len(tokens) == 3
|
2014-08-27 21:38:57 +04:00
|
|
|
assert tokens[0].string == p
|
|
|
|
assert tokens[1].string == "`"
|
|
|
|
assert tokens[2].string == word_str
|
2014-07-05 22:51:42 +04:00
|
|
|
|
|
|
|
|
2014-12-23 03:40:32 +03:00
|
|
|
def test_three_same_open(open_puncts, EN):
|
2014-07-05 22:51:42 +04:00
|
|
|
word_str = 'Hello'
|
|
|
|
for p in open_puncts:
|
|
|
|
string = p + p + p + word_str
|
2014-12-23 03:40:32 +03:00
|
|
|
tokens = EN(string)
|
2014-07-06 22:02:00 +04:00
|
|
|
assert len(tokens) == 4
|
2014-08-27 21:38:57 +04:00
|
|
|
assert tokens[0].string == p
|
|
|
|
assert tokens[3].string == word_str
|
2014-07-08 01:24:20 +04:00
|
|
|
|
|
|
|
|
2014-12-23 03:40:32 +03:00
|
|
|
def test_open_appostrophe(EN):
|
2014-07-08 01:24:20 +04:00
|
|
|
string = "'The"
|
2014-12-23 03:40:32 +03:00
|
|
|
tokens = EN(string)
|
2014-07-08 01:24:20 +04:00
|
|
|
assert len(tokens) == 2
|
2014-08-27 21:38:57 +04:00
|
|
|
assert tokens[0].string == "'"
|