mirror of
https://github.com/explosion/spaCy.git
synced 2024-09-22 03:49:17 +03:00
6fe276f85d
* Test on #2396: bug in Doc.get_lca_matrix() * reimplementation of Doc.get_lca_matrix(), (closes #2396) * reimplement Span.get_lca_matrix(), and call it from Doc.get_lca_matrix() * tests Span.get_lca_matrix() as well as Doc.get_lca_matrix() * implement _get_lca_matrix as a helper function in doc.pyx; call it from Doc.get_lca_matrix and Span.get_lca_matrix * use memory view instead of np.ndarray in _get_lca_matrix (faster) * fix bug when calling Span.get_lca_matrix; return lca matrix as np.array instead of memoryview * cleaner conditional, add comment
28 lines
638 B
Python
28 lines
638 B
Python
# coding: utf-8
|
|
from __future__ import unicode_literals
|
|
|
|
from ..util import get_doc
|
|
|
|
import pytest
|
|
import numpy
|
|
|
|
@pytest.mark.parametrize('sentence,matrix', [
|
|
(
|
|
'She created a test for spacy',
|
|
numpy.array([
|
|
[0, 1, 1, 1, 1, 1],
|
|
[1, 1, 1, 1, 1, 1],
|
|
[1, 1, 2, 3, 3, 3],
|
|
[1, 1, 3, 3, 3, 3],
|
|
[1, 1, 3, 3, 4, 4],
|
|
[1, 1, 3, 3, 4, 5]], dtype=numpy.int32)
|
|
)
|
|
])
|
|
def test_issue2396(EN, sentence, matrix):
|
|
doc = EN(sentence)
|
|
span = doc[:]
|
|
assert (doc.get_lca_matrix() == matrix).all()
|
|
assert (span.get_lca_matrix() == matrix).all()
|
|
|
|
|