2021-01-26 10:50:37 +03:00
|
|
|
import pytest
|
|
|
|
from spacy.lang.en import English
|
2021-01-30 04:52:33 +03:00
|
|
|
import numpy as np
|
2021-01-26 10:50:37 +03:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
2021-01-30 04:52:33 +03:00
|
|
|
"sentence, start_idx,end_idx,label",
|
|
|
|
[("Welcome to Mumbai, my friend", 11, 17, "GPE")],
|
2021-01-26 10:50:37 +03:00
|
|
|
)
|
|
|
|
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 04:52:33 +03:00
|
|
|
|
2021-01-26 10:50:37 +03:00
|
|
|
@pytest.mark.parametrize(
|
2021-01-30 04:52:33 +03:00
|
|
|
"sentence, start_idx,end_idx,kb_id", [("Welcome to Mumbai, my friend", 11, 17, 5)]
|
2021-01-26 10:50:37 +03:00
|
|
|
)
|
|
|
|
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 04:52:33 +03:00
|
|
|
|
2021-01-26 10:50:37 +03:00
|
|
|
@pytest.mark.parametrize(
|
2021-01-30 04:52:33 +03:00
|
|
|
"sentence, start_idx,end_idx,vector",
|
|
|
|
[("Welcome to Mumbai, my friend", 11, 17, np.array([0.1, 0.2, 0.3]))],
|
2021-01-26 10:50:37 +03:00
|
|
|
)
|
|
|
|
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 04:52:33 +03:00
|
|
|
assert (span.vector == vector).all()
|