spaCy/spacy/tests/regression/test_issue6815.py

36 lines
1.0 KiB
Python
Raw Normal View History

import pytest
from spacy.lang.en import English
2021-01-30 01:52:33 +00:00
import numpy as np
@pytest.mark.parametrize(
2021-01-30 01:52:33 +00:00
"sentence, start_idx,end_idx,label",
[("Welcome to Mumbai, my friend", 11, 17, "GPE")],
)
def test_char_span_label(sentence, start_idx, end_idx, label):
nlp = English()
doc = nlp(sentence)
span = doc[:].char_span(start_idx, end_idx, label=label)
assert span.label_ == label
2021-01-30 01:52:33 +00:00
@pytest.mark.parametrize(
2021-01-30 01:52:33 +00:00
"sentence, start_idx,end_idx,kb_id", [("Welcome to Mumbai, my friend", 11, 17, 5)]
)
def test_char_span_kb_id(sentence, start_idx, end_idx, kb_id):
nlp = English()
doc = nlp(sentence)
span = doc[:].char_span(start_idx, end_idx, kb_id=kb_id)
assert span.kb_id == kb_id
2021-01-30 01:52:33 +00:00
@pytest.mark.parametrize(
2021-01-30 01:52:33 +00:00
"sentence, start_idx,end_idx,vector",
[("Welcome to Mumbai, my friend", 11, 17, np.array([0.1, 0.2, 0.3]))],
)
def test_char_span_vector(sentence, start_idx, end_idx, vector):
nlp = English()
doc = nlp(sentence)
span = doc[:].char_span(start_idx, end_idx, vector=vector)
2021-01-30 01:52:33 +00:00
assert (span.vector == vector).all()