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