From 361944e51216702bfd0468a86bf7b631fe90c051 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Wed, 6 Dec 2017 12:12:11 +0100 Subject: [PATCH] If no rules are set, lemmatize by lookup --- spacy/lemmatizer.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/spacy/lemmatizer.py b/spacy/lemmatizer.py index 40cd995e2..e51795684 100644 --- a/spacy/lemmatizer.py +++ b/spacy/lemmatizer.py @@ -8,15 +8,17 @@ from .symbols import VerbForm_inf, VerbForm_none, Number_sing, Degree_pos class Lemmatizer(object): @classmethod def load(cls, path, index=None, exc=None, rules=None, lookup=None): - return cls(index or {}, exc or {}, rules or {}, lookup or {}) + return cls(index, exc, rules, lookup) def __init__(self, index=None, exceptions=None, rules=None, lookup=None): - self.index = index if index is not None else {} - self.exc = exceptions if exceptions is not None else {} - self.rules = rules if rules is not None else {} + self.index = index + self.exc = exceptions + self.rules = rules self.lookup_table = lookup if lookup is not None else {} def __call__(self, string, univ_pos, morphology=None): + if not self.rules: + return [self.lookup_table.get(string, string)] if univ_pos in (NOUN, 'NOUN', 'noun'): univ_pos = 'noun' elif univ_pos in (VERB, 'VERB', 'verb'):