2014-07-05 18:51:42 +00:00
|
|
|
from __future__ import unicode_literals
|
2014-12-23 00:40:32 +00:00
|
|
|
import pytest
|
2015-10-13 09:20:10 +00:00
|
|
|
import io
|
2015-10-12 08:33:11 +00:00
|
|
|
import cloudpickle
|
2015-10-12 06:00:01 +00:00
|
|
|
import pickle
|
2014-07-05 18:51:42 +00:00
|
|
|
|
2015-10-10 07:27:03 +00:00
|
|
|
from spacy.attrs import LEMMA, ORTH, PROB, IS_ALPHA
|
|
|
|
from spacy.parts_of_speech import NOUN, VERB
|
2014-07-05 18:51:42 +00:00
|
|
|
|
2015-10-10 07:27:03 +00:00
|
|
|
from spacy.attrs import LEMMA, ORTH, PROB, IS_ALPHA
|
|
|
|
from spacy.parts_of_speech import NOUN, VERB
|
|
|
|
|
2014-07-05 18:51:42 +00:00
|
|
|
|
2015-06-07 16:02:24 +00:00
|
|
|
def test_neq(en_vocab):
|
|
|
|
addr = en_vocab['Hello']
|
|
|
|
assert en_vocab['bye'].orth != addr.orth
|
2014-07-05 18:51:42 +00:00
|
|
|
|
|
|
|
|
2015-06-07 16:02:24 +00:00
|
|
|
def test_eq(en_vocab):
|
|
|
|
addr = en_vocab['Hello']
|
|
|
|
assert en_vocab['Hello'].orth == addr.orth
|
2014-07-05 18:51:42 +00:00
|
|
|
|
|
|
|
|
2015-06-07 16:02:24 +00:00
|
|
|
def test_case_neq(en_vocab):
|
|
|
|
addr = en_vocab['Hello']
|
|
|
|
assert en_vocab['hello'].orth != addr.orth
|
2014-07-05 18:51:42 +00:00
|
|
|
|
|
|
|
|
2015-06-07 16:02:24 +00:00
|
|
|
def test_punct_neq(en_vocab):
|
|
|
|
addr = en_vocab['Hello']
|
|
|
|
assert en_vocab['Hello,'].orth != addr.orth
|
2014-07-05 18:51:42 +00:00
|
|
|
|
2014-12-23 00:40:32 +00:00
|
|
|
|
2015-06-07 16:02:24 +00:00
|
|
|
def test_shape_attr(en_vocab):
|
|
|
|
example = en_vocab['example']
|
2015-01-22 15:08:25 +00:00
|
|
|
assert example.orth != example.shape
|
2015-10-10 07:27:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_symbols(en_vocab):
|
|
|
|
assert en_vocab.strings['IS_ALPHA'] == IS_ALPHA
|
|
|
|
assert en_vocab.strings['NOUN'] == NOUN
|
|
|
|
assert en_vocab.strings['VERB'] == VERB
|
|
|
|
assert en_vocab.strings['LEMMA'] == LEMMA
|
|
|
|
assert en_vocab.strings['ORTH'] == ORTH
|
|
|
|
assert en_vocab.strings['PROB'] == PROB
|
2016-03-08 15:49:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_contains(en_vocab):
|
|
|
|
assert 'Hello' in en_vocab
|
|
|
|
assert 'LKsdjvlsakdvlaksdvlkasjdvljasdlkfvm' not in en_vocab
|
2015-10-10 07:27:03 +00:00
|
|
|
|
2015-10-12 06:00:01 +00:00
|
|
|
|
2016-02-05 11:46:58 +00:00
|
|
|
@pytest.mark.xfail
|
2015-10-12 06:00:01 +00:00
|
|
|
def test_pickle_vocab(en_vocab):
|
2015-10-13 09:20:10 +00:00
|
|
|
file_ = io.BytesIO()
|
2015-10-12 08:33:11 +00:00
|
|
|
cloudpickle.dump(en_vocab, file_)
|
2015-10-12 06:00:01 +00:00
|
|
|
|
|
|
|
file_.seek(0)
|
|
|
|
|
|
|
|
loaded = pickle.load(file_)
|
2015-10-26 01:31:05 +00:00
|
|
|
|
|
|
|
|
2016-02-05 11:46:58 +00:00
|
|
|
@pytest.mark.xfail
|
2015-10-26 01:31:05 +00:00
|
|
|
def test_pickle_vocab_vectors(en_vocab):
|
|
|
|
vectors_length = en_vocab.vectors_length
|
|
|
|
assert vectors_length != 0
|
|
|
|
|
|
|
|
apples = en_vocab['apples']
|
|
|
|
oranges = en_vocab['oranges']
|
|
|
|
hippos = en_vocab['hippos']
|
|
|
|
|
|
|
|
assert apples.similarity(oranges) > apples.similarity(hippos)
|
|
|
|
|
|
|
|
apples.vector = hippos.vector
|
|
|
|
|
|
|
|
assert apples.similarity(oranges) < apples.similarity(hippos)
|
|
|
|
|
|
|
|
file_ = io.BytesIO()
|
|
|
|
cloudpickle.dump(en_vocab, file_)
|
|
|
|
|
|
|
|
file_.seek(0)
|
|
|
|
|
|
|
|
loaded = pickle.load(file_)
|
|
|
|
|
|
|
|
apples = loaded['apples']
|
|
|
|
oranges = loaded['oranges']
|
|
|
|
hippos = loaded['hippos']
|
|
|
|
|
|
|
|
assert apples.similarity(oranges) < apples.similarity(hippos)
|
|
|
|
|