2014-07-05 22:51:42 +04:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2014-08-18 21:14:00 +04:00
|
|
|
from spacy import lex_of
|
|
|
|
from spacy.en import tokenize
|
2014-07-05 22:51:42 +04:00
|
|
|
from spacy.en import lookup
|
|
|
|
from spacy.en import unhash
|
|
|
|
|
|
|
|
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-18 21:14:00 +04:00
|
|
|
tokens = tokenize(string)
|
2014-07-05 22:51:42 +04:00
|
|
|
assert len(tokens) == 3
|
|
|
|
assert unhash(lex_of(tokens[0])) == open_
|
|
|
|
assert unhash(lex_of(tokens[1])) == word_str
|
|
|
|
assert unhash(lex_of(tokens[2])) == close_
|
|
|
|
|
|
|
|
|
|
|
|
def test_two_different(paired_puncts):
|
|
|
|
word_str = 'Hello'
|
|
|
|
for open_, close_ in paired_puncts:
|
|
|
|
string = "`" + open_ + word_str + close_ + "'"
|
2014-08-18 21:14:00 +04:00
|
|
|
tokens = tokenize(string)
|
2014-07-05 22:51:42 +04:00
|
|
|
assert len(tokens) == 5
|
|
|
|
assert unhash(lex_of(tokens[0])) == "`"
|
|
|
|
assert unhash(lex_of(tokens[1])) == open_
|
|
|
|
assert unhash(lex_of(tokens[2])) == word_str
|
|
|
|
assert unhash(lex_of(tokens[2])) == word_str
|
|
|
|
assert unhash(lex_of(tokens[3])) == close_
|
|
|
|
assert unhash(lex_of(tokens[4])) == "'"
|