2015-01-05 03:53:30 +03:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2014-12-21 13:02:44 +03:00
|
|
|
from spacy.en.lemmatizer import Lemmatizer, read_index, read_exc
|
2015-01-14 16:33:16 +03:00
|
|
|
from spacy.en import LOCAL_DATA_DIR
|
2014-12-07 17:39:13 +03:00
|
|
|
from os import path
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
|
|
def test_read_index():
|
2015-01-14 16:33:16 +03:00
|
|
|
wn = path.join(LOCAL_DATA_DIR, 'wordnet')
|
2014-12-07 17:39:13 +03:00
|
|
|
index = read_index(path.join(wn, 'index.noun'))
|
|
|
|
assert 'man' in index
|
|
|
|
assert 'plantes' not in index
|
|
|
|
assert 'plant' in index
|
|
|
|
|
|
|
|
|
|
|
|
def test_read_exc():
|
2015-01-14 16:33:16 +03:00
|
|
|
wn = path.join(LOCAL_DATA_DIR, 'wordnet')
|
2014-12-07 17:39:13 +03:00
|
|
|
exc = read_exc(path.join(wn, 'verb.exc'))
|
|
|
|
assert exc['was'] == ('be',)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def lemmatizer():
|
2015-01-14 16:33:16 +03:00
|
|
|
return Lemmatizer(path.join(LOCAL_DATA_DIR, 'wordnet'), 0, 0, 0)
|
2014-12-07 17:39:13 +03:00
|
|
|
|
|
|
|
|
|
|
|
def test_noun_lemmas(lemmatizer):
|
|
|
|
do = lemmatizer.noun
|
|
|
|
|
|
|
|
assert do('aardwolves') == set(['aardwolf'])
|
|
|
|
assert do('aardwolf') == set(['aardwolf'])
|
|
|
|
assert do('planets') == set(['planet'])
|
|
|
|
assert do('ring') == set(['ring'])
|
|
|
|
assert do('axes') == set(['axis', 'axe', 'ax'])
|