2014-07-05 22:51:42 +04:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
from spacy.en import lookup
|
2014-08-18 21:14:00 +04:00
|
|
|
from spacy.en import tokenize
|
2014-07-05 22:51:42 +04:00
|
|
|
from spacy.en import unhash
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def close_puncts():
|
|
|
|
return [')', ']', '}', '*']
|
|
|
|
|
|
|
|
|
|
|
|
def test_close(close_puncts):
|
|
|
|
word_str = 'Hello'
|
|
|
|
for p in close_puncts:
|
|
|
|
string = word_str + p
|
2014-08-18 21:14:00 +04:00
|
|
|
tokens = tokenize(string)
|
2014-07-05 22:51:42 +04:00
|
|
|
assert len(tokens) == 2
|
2014-08-23 21:55:06 +04:00
|
|
|
assert unhash(tokens[1].lex) == p
|
|
|
|
assert unhash(tokens[0].lex) == word_str
|
2014-07-05 22:51:42 +04:00
|
|
|
|
|
|
|
|
|
|
|
def test_two_different_close(close_puncts):
|
|
|
|
word_str = 'Hello'
|
|
|
|
for p in close_puncts:
|
|
|
|
string = word_str + p + "'"
|
2014-08-18 21:14:00 +04:00
|
|
|
tokens = tokenize(string)
|
2014-07-05 22:51:42 +04:00
|
|
|
assert len(tokens) == 3
|
2014-08-23 21:55:06 +04:00
|
|
|
assert unhash(tokens[0].lex) == word_str
|
|
|
|
assert unhash(tokens[1].lex) == p
|
|
|
|
assert unhash(tokens[2].lex) == "'"
|
2014-07-05 22:51:42 +04:00
|
|
|
|
|
|
|
|
|
|
|
def test_three_same_close(close_puncts):
|
|
|
|
word_str = 'Hello'
|
|
|
|
for p in close_puncts:
|
|
|
|
string = word_str + p + p + p
|
2014-08-18 21:14:00 +04:00
|
|
|
tokens = tokenize(string)
|
2014-07-06 22:02:00 +04:00
|
|
|
assert len(tokens) == 4
|
2014-08-23 21:55:06 +04:00
|
|
|
assert unhash(tokens[0].lex) == word_str
|
|
|
|
assert unhash(tokens[1].lex) == p
|