2014-07-05 18:51:42 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2014-08-27 17:38:57 +00:00
|
|
|
from spacy.en import EN
|
2014-07-05 18:51:42 +00:00
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def paired_puncts():
|
|
|
|
return [('(', ')'), ('[', ']'), ('{', '}'), ('*', '*')]
|
|
|
|
|
|
|
|
|
|
|
|
def test_token(paired_puncts):
|
|
|
|
word_str = 'Hello'
|
|
|
|
for open_, close_ in paired_puncts:
|
|
|
|
string = open_ + word_str + close_
|
2014-08-27 17:38:57 +00:00
|
|
|
tokens = EN.tokenize(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 == open_
|
|
|
|
assert tokens[1].string == word_str
|
|
|
|
assert tokens[2].string == close_
|
2014-07-05 18:51:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_two_different(paired_puncts):
|
|
|
|
word_str = 'Hello'
|
|
|
|
for open_, close_ in paired_puncts:
|
|
|
|
string = "`" + open_ + word_str + close_ + "'"
|
2014-08-27 17:38:57 +00:00
|
|
|
tokens = EN.tokenize(string)
|
2014-07-05 18:51:42 +00:00
|
|
|
assert len(tokens) == 5
|
2014-08-27 17:38:57 +00:00
|
|
|
assert tokens[0].string == "`"
|
|
|
|
assert tokens[1].string == open_
|
|
|
|
assert tokens[2].string == word_str
|
|
|
|
assert tokens[2].string == word_str
|
|
|
|
assert tokens[3].string == close_
|
|
|
|
assert tokens[4].string == "'"
|