2014-07-05 18:51:42 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
from spacy import lex_of
|
|
|
|
from spacy.en import lookup
|
2014-08-18 17:14:00 +00:00
|
|
|
from spacy.en import tokenize
|
2014-07-05 18:51:42 +00: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 17:14:00 +00:00
|
|
|
tokens = tokenize(string)
|
2014-07-05 18:51:42 +00:00
|
|
|
assert len(tokens) == 2
|
|
|
|
assert unhash(lex_of(tokens[1])) == p
|
2014-07-06 18:02:00 +00:00
|
|
|
assert unhash(lex_of(tokens[0])) == word_str
|
2014-07-05 18:51:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_two_different_close(close_puncts):
|
|
|
|
word_str = 'Hello'
|
|
|
|
for p in close_puncts:
|
|
|
|
string = word_str + p + "'"
|
2014-08-18 17:14:00 +00:00
|
|
|
tokens = tokenize(string)
|
2014-07-05 18:51:42 +00:00
|
|
|
assert len(tokens) == 3
|
|
|
|
assert unhash(lex_of(tokens[0])) == word_str
|
|
|
|
assert unhash(lex_of(tokens[1])) == p
|
|
|
|
assert unhash(lex_of(tokens[2])) == "'"
|
|
|
|
|
|
|
|
|
|
|
|
def test_three_same_close(close_puncts):
|
|
|
|
word_str = 'Hello'
|
|
|
|
for p in close_puncts:
|
|
|
|
string = word_str + p + p + p
|
2014-08-18 17:14:00 +00:00
|
|
|
tokens = tokenize(string)
|
2014-07-06 18:02:00 +00:00
|
|
|
assert len(tokens) == 4
|
2014-07-05 18:51:42 +00:00
|
|
|
assert unhash(lex_of(tokens[0])) == word_str
|
2014-07-06 18:02:00 +00:00
|
|
|
assert unhash(lex_of(tokens[1])) == p
|