From 956dc36785bb827d1b24d94839cfb77148b78457 Mon Sep 17 00:00:00 2001 From: ines Date: Sat, 15 Apr 2017 12:12:31 +0200 Subject: [PATCH] Move functions to deprecated --- spacy/deprecated.py | 21 +++++++++++++++++++-- spacy/util.py | 33 --------------------------------- 2 files changed, 19 insertions(+), 35 deletions(-) diff --git a/spacy/deprecated.py b/spacy/deprecated.py index 3a00e7207..dc7d3e1e4 100644 --- a/spacy/deprecated.py +++ b/spacy/deprecated.py @@ -53,6 +53,23 @@ def detokenize(token_rules, words): # Deprecated? return positions +def match_best_version(target_name, target_version, path): + path = util.ensure_path(path) + if path is None or not path.exists(): + return None + matches = [] + for data_name in path.iterdir(): + name, version = split_data_name(data_name.parts[-1]) + if name == target_name: + matches.append((tuple(float(v) for v in version.split('.')), data_name)) + if matches: + return Path(max(matches)[1]) + else: + return None + + +def split_data_name(name): + return name.split('-', 1) if '-' in name else (name, '') def fix_glove_vectors_loading(overrides): @@ -72,11 +89,11 @@ def fix_glove_vectors_loading(overrides): vec_path = None if 'add_vectors' not in overrides: if 'vectors' in overrides: - vec_path = util.match_best_version(overrides['vectors'], None, data_path) + vec_path = match_best_version(overrides['vectors'], None, data_path) if vec_path is None: return overrides else: - vec_path = util.match_best_version('en_glove_cc_300_1m_vectors', None, data_path) + vec_path = match_best_version('en_glove_cc_300_1m_vectors', None, data_path) if vec_path is not None: vec_path = vec_path / 'vocab' / 'vec.bin' if vec_path is not None: diff --git a/spacy/util.py b/spacy/util.py index dd5937f7b..8229d05cd 100644 --- a/spacy/util.py +++ b/spacy/util.py @@ -55,39 +55,6 @@ def or_(val1, val2): return val2 -def match_best_version(target_name, target_version, path): - path = path if not isinstance(path, basestring) else pathlib.Path(path) - if path is None or not path.exists(): - return None - matches = [] - for data_name in path.iterdir(): - name, version = split_data_name(data_name.parts[-1]) - if name == target_name and constraint_match(target_version, version): - matches.append((tuple(float(v) for v in version.split('.')), data_name)) - if matches: - return pathlib.Path(max(matches)[1]) - else: - return None - - -def split_data_name(name): - return name.split('-', 1) if '-' in name else (name, '') - - -def constraint_match(constraint_string, version): - # From http://github.com/spacy-io/sputnik - if not constraint_string: - return True - - constraints = [c.strip() for c in constraint_string.split(',') if c.strip()] - - for c in constraints: - if not re.match(r'[><=][=]?\d+(\.\d+)*', c): - raise ValueError('invalid constraint: %s' % c) - - return all(semver.match(version, c) for c in constraints) - - def read_regex(path): path = ensure_path(path) with path.open() as file_: