2014-09-25 16:29:42 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
2015-10-09 02:37:25 +00:00
|
|
|
from spacy.attrs import *
|
2014-09-25 16:29:42 +00:00
|
|
|
|
|
|
|
|
2015-06-07 16:02:24 +00:00
|
|
|
def test_is_alpha(en_vocab):
|
|
|
|
the = en_vocab['the']
|
2015-01-14 13:33:16 +00:00
|
|
|
assert the.flags & (1 << IS_ALPHA)
|
2015-06-07 16:02:24 +00:00
|
|
|
year = en_vocab['1999']
|
2015-01-14 13:33:16 +00:00
|
|
|
assert not year.flags & (1 << IS_ALPHA)
|
2015-06-07 16:02:24 +00:00
|
|
|
mixed = en_vocab['hello1']
|
2015-01-14 13:33:16 +00:00
|
|
|
assert not mixed.flags & (1 << IS_ALPHA)
|
2014-09-25 16:29:42 +00:00
|
|
|
|
|
|
|
|
2015-06-07 16:02:24 +00:00
|
|
|
def test_is_digit(en_vocab):
|
|
|
|
the = en_vocab['the']
|
2015-01-14 13:33:16 +00:00
|
|
|
assert not the.flags & (1 << IS_DIGIT)
|
2015-06-07 16:02:24 +00:00
|
|
|
year = en_vocab['1999']
|
2015-01-14 13:33:16 +00:00
|
|
|
assert year.flags & (1 << IS_DIGIT)
|
2015-06-07 16:02:24 +00:00
|
|
|
mixed = en_vocab['hello1']
|
2015-01-14 13:33:16 +00:00
|
|
|
assert not mixed.flags & (1 << IS_DIGIT)
|
2016-10-14 10:15:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_add_flag_auto_id(en_vocab):
|
|
|
|
is_len4 = en_vocab.add_flag(lambda string: len(string) == 4)
|
|
|
|
assert en_vocab['1999'].check_flag(is_len4) == True
|
|
|
|
assert en_vocab['1999'].check_flag(IS_DIGIT) == True
|
|
|
|
assert en_vocab['199'].check_flag(is_len4) == False
|
|
|
|
assert en_vocab['199'].check_flag(IS_DIGIT) == True
|
|
|
|
assert en_vocab['the'].check_flag(is_len4) == False
|
|
|
|
assert en_vocab['dogs'].check_flag(is_len4) == True
|
|
|
|
|
|
|
|
|
|
|
|
def test_add_flag_provided_id(en_vocab):
|
|
|
|
is_len4 = en_vocab.add_flag(lambda string: len(string) == 4, flag_id=IS_DIGIT)
|
|
|
|
assert en_vocab['1999'].check_flag(is_len4) == True
|
|
|
|
assert en_vocab['199'].check_flag(is_len4) == False
|
|
|
|
assert en_vocab['199'].check_flag(IS_DIGIT) == False
|
|
|
|
assert en_vocab['the'].check_flag(is_len4) == False
|
|
|
|
assert en_vocab['dogs'].check_flag(is_len4) == True
|