mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-25 17:36:30 +03:00
Move functions to deprecated
This commit is contained in:
parent
c05ec4b89a
commit
956dc36785
|
@ -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:
|
||||
|
|
|
@ -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_:
|
||||
|
|
Loading…
Reference in New Issue
Block a user