mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-25 17:36:30 +03:00
* Add tests for new vectors functionality
This commit is contained in:
parent
c26b4b4650
commit
4ec89788ca
109
tests/vectors/test_vectors.py
Normal file
109
tests/vectors/test_vectors.py
Normal file
|
@ -0,0 +1,109 @@
|
|||
import pytest
|
||||
|
||||
@pytest.mark.models
|
||||
def test_token_vector(EN):
|
||||
token = EN(u'Apples and oranges')[0]
|
||||
token.vector
|
||||
token.vector_norm
|
||||
|
||||
@pytest.mark.models
|
||||
def test_lexeme_vector(EN):
|
||||
lexeme = EN.vocab[u'apples']
|
||||
lexeme.vector
|
||||
lexeme.vector_norm
|
||||
|
||||
|
||||
@pytest.mark.models
|
||||
def test_doc_vector(EN):
|
||||
doc = EN(u'Apples and oranges')
|
||||
doc.vector
|
||||
doc.vector_norm
|
||||
|
||||
@pytest.mark.models
|
||||
def test_span_vector(EN):
|
||||
span = EN(u'Apples and oranges')[0:2]
|
||||
span.vector
|
||||
span.vector_norm
|
||||
|
||||
@pytest.mark.models
|
||||
def test_token_token_similarity(EN):
|
||||
apples, oranges = EN(u'apples oranges')
|
||||
assert apples.similarity(oranges) == oranges.similarity(apples)
|
||||
assert 0.0 < apples.similarity(oranges) < 1.0
|
||||
|
||||
|
||||
@pytest.mark.models
|
||||
def test_token_lexeme_similarity(EN):
|
||||
apples = EN(u'apples')
|
||||
oranges = EN.vocab[u'oranges']
|
||||
assert apples.similarity(oranges) == oranges.similarity(apples)
|
||||
assert 0.0 < apples.similarity(oranges) < 1.0
|
||||
|
||||
|
||||
@pytest.mark.models
|
||||
def test_token_span_similarity(EN):
|
||||
doc = EN(u'apples orange juice')
|
||||
apples = doc[0]
|
||||
oranges = doc[1:3]
|
||||
assert apples.similarity(oranges) == oranges.similarity(apples)
|
||||
assert 0.0 < apples.similarity(oranges) < 1.0
|
||||
|
||||
|
||||
@pytest.mark.models
|
||||
def test_token_doc_similarity(EN):
|
||||
doc = EN(u'apples orange juice')
|
||||
apples = doc[0]
|
||||
assert apples.similarity(doc) == doc.similarity(apples)
|
||||
assert 0.0 < apples.similarity(doc) < 1.0
|
||||
|
||||
|
||||
@pytest.mark.models
|
||||
def test_lexeme_span_similarity(EN):
|
||||
doc = EN(u'apples orange juice')
|
||||
apples = EN.vocab[u'apples']
|
||||
span = doc[1:3]
|
||||
assert apples.similarity(span) == span.similarity(apples)
|
||||
assert 0.0 < apples.similarity(span) < 1.0
|
||||
|
||||
|
||||
@pytest.mark.models
|
||||
def test_lexeme_lexeme_similarity(EN):
|
||||
apples = EN.vocab[u'apples']
|
||||
oranges = EN.vocab[u'oranges']
|
||||
assert apples.similarity(oranges) == oranges.similarity(apples)
|
||||
assert 0.0 < apples.similarity(oranges) < 1.0
|
||||
|
||||
|
||||
@pytest.mark.models
|
||||
def test_lexeme_doc_similarity(EN):
|
||||
doc = EN(u'apples orange juice')
|
||||
apples = EN.vocab[u'apples']
|
||||
assert apples.similarity(doc) == doc.similarity(apples)
|
||||
assert 0.0 < apples.similarity(doc) < 1.0
|
||||
|
||||
|
||||
@pytest.mark.models
|
||||
def test_span_span_similarity(EN):
|
||||
doc = EN(u'apples orange juice')
|
||||
apples = doc[0:2]
|
||||
oj = doc[1:3]
|
||||
assert apples.similarity(oj) == oj.similarity(apples)
|
||||
assert 0.0 < apples.similarity(oj) < 1.0
|
||||
|
||||
|
||||
@pytest.mark.models
|
||||
def test_span_doc_similarity(EN):
|
||||
doc = EN(u'apples orange juice')
|
||||
apples = doc[0:2]
|
||||
oj = doc[1:3]
|
||||
assert apples.similarity(doc) == doc.similarity(apples)
|
||||
assert 0.0 < apples.similarity(doc) < 1.0
|
||||
|
||||
|
||||
@pytest.mark.models
|
||||
def test_doc_doc_similarity(EN):
|
||||
apples = EN(u'apples and apple pie')
|
||||
oranges = EN(u'orange juice')
|
||||
assert apples.similarity(oranges) == apples.similarity(oranges)
|
||||
assert 0.0 < apples.similarity(oranges) < 1.0
|
||||
|
Loading…
Reference in New Issue
Block a user