2014-07-05 22:51:42 +04:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
from spacy import lex_of
|
|
|
|
from spacy.spacy import expand_chunk
|
|
|
|
from spacy.en import lookup
|
|
|
|
from spacy.en import unhash
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def open_puncts():
|
|
|
|
return ['(', '[', '{', '*']
|
|
|
|
|
|
|
|
|
|
|
|
def test_open(open_puncts):
|
|
|
|
word_str = 'Hello'
|
|
|
|
for p in open_puncts:
|
|
|
|
string = p + word_str
|
|
|
|
token = lookup(string)
|
|
|
|
assert unhash(lex_of(token)) == p
|
|
|
|
tokens = expand_chunk(token)
|
|
|
|
assert len(tokens) == 2
|
|
|
|
assert unhash(lex_of(tokens[0])) == p
|
|
|
|
assert unhash(lex_of(tokens[1])) == word_str
|
|
|
|
|
|
|
|
|
|
|
|
def test_two_different_open(open_puncts):
|
|
|
|
word_str = 'Hello'
|
|
|
|
for p in open_puncts:
|
|
|
|
string = p + "`" + word_str
|
|
|
|
token = lookup(string)
|
|
|
|
assert unhash(lex_of(token)) == p
|
|
|
|
tokens = expand_chunk(token)
|
|
|
|
assert len(tokens) == 3
|
|
|
|
assert unhash(lex_of(tokens[0])) == p
|
|
|
|
assert unhash(lex_of(tokens[1])) == "`"
|
|
|
|
assert unhash(lex_of(tokens[2])) == word_str
|
|
|
|
|
|
|
|
|
|
|
|
def test_three_same_open(open_puncts):
|
|
|
|
word_str = 'Hello'
|
|
|
|
for p in open_puncts:
|
|
|
|
string = p + p + p + word_str
|
|
|
|
token = lookup(string)
|
2014-07-06 22:02:00 +04:00
|
|
|
assert unhash(lex_of(token)) == p
|
2014-07-05 22:51:42 +04:00
|
|
|
tokens = expand_chunk(token)
|
2014-07-06 22:02:00 +04:00
|
|
|
assert len(tokens) == 4
|
|
|
|
assert unhash(lex_of(tokens[0])) == p
|
|
|
|
assert unhash(lex_of(tokens[3])) == word_str
|
2014-07-08 01:24:20 +04:00
|
|
|
|
|
|
|
|
|
|
|
def test_open_appostrophe():
|
|
|
|
string = "'The"
|
|
|
|
tokens = expand_chunk(lookup(string))
|
|
|
|
assert len(tokens) == 2
|
|
|
|
assert unhash(lex_of(tokens[0])) == "'"
|