mirror of
https://github.com/explosion/spaCy.git
synced 2025-08-07 13:44:55 +03:00
Minor refactoring for fuzz/fuzzy
This commit is contained in:
parent
6a9fec7ea8
commit
183b13dc9c
|
@ -841,8 +841,8 @@ class _FuzzyPredicate:
|
||||||
self.key = (attr, self.predicate, srsly.json_dumps(value, sort_keys=True))
|
self.key = (attr, self.predicate, srsly.json_dumps(value, sort_keys=True))
|
||||||
if self.predicate not in self.operators:
|
if self.predicate not in self.operators:
|
||||||
raise ValueError(Errors.E126.format(good=self.operators, bad=self.predicate))
|
raise ValueError(Errors.E126.format(good=self.operators, bad=self.predicate))
|
||||||
self.fuzzy = self.predicate[len('FUZZY'):] # number after prefix
|
fuzz = self.predicate[len("FUZZY"):] # number after prefix
|
||||||
self.fuzzy = int(self.fuzzy) if self.fuzzy else -1
|
self.fuzzy = int(fuzz) if fuzz else -1
|
||||||
|
|
||||||
def __call__(self, Token token):
|
def __call__(self, Token token):
|
||||||
if self.is_extension:
|
if self.is_extension:
|
||||||
|
@ -1055,12 +1055,12 @@ def _get_extra_predicates_dict(attr, value_dict, vocab, predicate_types,
|
||||||
continue
|
continue
|
||||||
elif cls == _FuzzyPredicate:
|
elif cls == _FuzzyPredicate:
|
||||||
fuzz = type_[len("FUZZY"):] # number after prefix
|
fuzz = type_[len("FUZZY"):] # number after prefix
|
||||||
fuzz = int(fuzz) if fuzz else -1
|
fuzzy = int(fuzz) if fuzz else -1
|
||||||
if isinstance(value, dict):
|
if isinstance(value, dict):
|
||||||
# add predicates inside fuzzy operator
|
# add predicates inside fuzzy operator
|
||||||
output.extend(_get_extra_predicates_dict(attr, value, vocab, predicate_types,
|
output.extend(_get_extra_predicates_dict(attr, value, vocab, predicate_types,
|
||||||
extra_predicates, seen_predicates,
|
extra_predicates, seen_predicates,
|
||||||
fuzzy=fuzz))
|
fuzzy=fuzzy))
|
||||||
continue
|
continue
|
||||||
predicate = cls(len(extra_predicates), attr, value, type_, vocab=vocab,
|
predicate = cls(len(extra_predicates), attr, value, type_, vocab=vocab,
|
||||||
regex=regex, fuzzy=fuzzy)
|
regex=regex, fuzzy=fuzzy)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user