2014-07-07 02:23:46 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
from spacy.en import tokenize
|
|
|
|
from spacy.en import lookup
|
|
|
|
|
|
|
|
|
|
|
|
def test_single_word():
|
|
|
|
lex_ids = tokenize(u'hello')
|
|
|
|
assert lex_ids[0] == lookup(u'hello')
|
|
|
|
|
|
|
|
|
|
|
|
def test_two_words():
|
2014-08-23 17:55:06 +00:00
|
|
|
words = tokenize('hello possums')
|
|
|
|
assert len(words) == 2
|
|
|
|
assert words[0] == lookup('hello')
|
|
|
|
assert words[0] != words[1]
|
2014-07-07 02:23:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_punct():
|
2014-08-18 17:14:00 +00:00
|
|
|
tokens = tokenize('hello, possums.')
|
|
|
|
assert len(tokens) == 4
|
2014-08-23 17:55:06 +00:00
|
|
|
assert tokens[0].lex == lookup('hello').lex
|
|
|
|
assert tokens[1].lex == lookup(',').lex
|
|
|
|
assert tokens[2].lex == lookup('possums').lex
|
|
|
|
assert tokens[1].lex != lookup('hello').lex
|
2014-07-07 02:23:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_digits():
|
|
|
|
lex_ids = tokenize('The year: 1984.')
|
|
|
|
assert len(lex_ids) == 5
|
2014-08-23 17:55:06 +00:00
|
|
|
assert lex_ids[0].lex == lookup('The').lex
|
|
|
|
assert lex_ids[3].lex == lookup('1984').lex
|
|
|
|
assert lex_ids[4].lex == lookup('.').lex
|
2014-07-07 02:23:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_contraction():
|
|
|
|
lex_ids = tokenize("don't giggle")
|
|
|
|
assert len(lex_ids) == 3
|
2014-08-23 17:55:06 +00:00
|
|
|
assert lex_ids[1].lex == lookup("not").lex
|
2014-07-07 02:23:46 +00:00
|
|
|
lex_ids = tokenize("i said don't!")
|
|
|
|
assert len(lex_ids) == 4
|
2014-08-23 17:55:06 +00:00
|
|
|
assert lex_ids[3].lex == lookup('!').lex
|