Example #1
0
def test_window_size(spacy_doc):
    result_10 = kt.sgrank(spacy_doc, window_size=10)
    result_100 = kt.sgrank(spacy_doc, window_size=100)
    assert len(result_10) > 0 and len(result_100) > 0
    assert result_10 != result_100
    with pytest.raises(ValueError):
        _ = kt.sgrank(spacy_doc, window_size=1)
Example #2
0
def test_empty_doc(empty_spacy_doc):
    result = kt.sgrank(empty_spacy_doc)
    assert isinstance(result, list)
    assert len(result) == 0
Example #3
0
def test_normalize_callable(spacy_doc):
    result = kt.sgrank(spacy_doc, normalize=lambda tok: tok.text.upper())
    assert len(result) > 0
    assert all(term == term.upper() for term, _ in result)
Example #4
0
def test_normalize_lower(spacy_doc):
    result = kt.sgrank(spacy_doc, normalize="lower")
    assert len(result) > 0
    assert all(term == term.lower() for term, _ in result)
Example #5
0
def test_normalize_none(spacy_doc):
    result = kt.sgrank(spacy_doc, normalize=None)
    assert len(result) > 0
    assert any(term != term.lower() for term, _ in result)
Example #6
0
def test_topn_float(spacy_doc):
    result = kt.sgrank(spacy_doc, topn=0.2)
    assert len(result) > 0
    with pytest.raises(ValueError):
        _ = kt.sgrank(spacy_doc, topn=2.0)
Example #7
0
def test_topn(spacy_doc):
    for n in (5, 25):
        result = kt.sgrank(spacy_doc, topn=n)
        assert 0 < len(result) <= n
Example #8
0
def test_ngrams_2_3(spacy_doc):
    result = kt.sgrank(spacy_doc, ngrams=(2, 3))
    assert len(result) > 0
    assert all(2 <= len(term.split()) <= 3 for term, _ in result)
Example #9
0
def test_ngrams_1(spacy_doc):
    result = kt.sgrank(spacy_doc, ngrams=1)
    assert len(result) > 0
    assert all(len(term.split()) == 1 for term, _ in result)
Example #10
0
def test_default(spacy_doc):
    result = kt.sgrank(spacy_doc)
    assert isinstance(result, list) and len(result) > 0
    assert all(isinstance(ts, tuple) and len(ts) == 2 for ts in result)
    assert all(
        isinstance(ts[0], str) and isinstance(ts[1], float) for ts in result)