From ed2fff61287e2cdf53b7f2eb731a1e6f6b6d975c Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Sat, 20 Dec 2014 03:51:25 +1100 Subject: [PATCH] * Add tests --- tests/test_add_lemmas.py | 24 ++++++++++++++++++++++++ tests/test_morph_exceptions.py | 19 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 tests/test_add_lemmas.py create mode 100644 tests/test_morph_exceptions.py diff --git a/tests/test_add_lemmas.py b/tests/test_add_lemmas.py new file mode 100644 index 000000000..8effbbb48 --- /dev/null +++ b/tests/test_add_lemmas.py @@ -0,0 +1,24 @@ +from spacy.en import EN +import pytest + + +@pytest.fixture +def tagged(): + EN.load() + string = u'Bananas in pyjamas are geese.' + tokens = EN.tokenize(string) + EN.set_pos(tokens) + return tokens + + +@pytest.fixture +def lemmas(tagged): + return [t.lemma for t in tagged] + + +def test_lemmas(lemmas): + assert lemmas[0] == 'banana' + assert lemmas[1] == 'in' + assert lemmas[2] == 'pyjama' + assert lemmas[3] == 'be' + assert lemmas[4] == 'goose' diff --git a/tests/test_morph_exceptions.py b/tests/test_morph_exceptions.py new file mode 100644 index 000000000..0d5d3d178 --- /dev/null +++ b/tests/test_morph_exceptions.py @@ -0,0 +1,19 @@ +from __future__ import unicode_literals +from spacy.en import EN + +import pytest + +@pytest.fixture +def morph_exc(): + return { + 'PRP$': {'his': {'L': '-PRP-', 'person': 3, 'case': 2}}, + } + +def test_load_exc(morph_exc): + EN.load() + EN.morphologizer.load_exceptions(morph_exc) + tokens = EN.tokenize('I like his style.') + EN.set_pos(tokens) + his = tokens[2] + assert his.pos == 'PRP$' + assert his.lemma == '-PRP-'