mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-26 01:46:28 +03:00
Add compat function to normalize dict keys
This commit is contained in:
parent
92f9e5cc9a
commit
480ef8bfc8
|
@ -6,6 +6,8 @@ import ftfy
|
||||||
import sys
|
import sys
|
||||||
import ujson
|
import ujson
|
||||||
|
|
||||||
|
import thinc.neural.util
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import cPickle as pickle
|
import cPickle as pickle
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -32,6 +34,7 @@ copy_reg = copy_reg
|
||||||
CudaStream = CudaStream
|
CudaStream = CudaStream
|
||||||
cupy = cupy
|
cupy = cupy
|
||||||
fix_text = ftfy.fix_text
|
fix_text = ftfy.fix_text
|
||||||
|
copy_array = thinc.neural.util.copy_array
|
||||||
|
|
||||||
is_python2 = six.PY2
|
is_python2 = six.PY2
|
||||||
is_python3 = six.PY3
|
is_python3 = six.PY3
|
||||||
|
@ -71,3 +74,16 @@ def is_config(python2=None, python3=None, windows=None, linux=None, osx=None):
|
||||||
(windows == None or windows == is_windows) and
|
(windows == None or windows == is_windows) and
|
||||||
(linux == None or linux == is_linux) and
|
(linux == None or linux == is_linux) and
|
||||||
(osx == None or osx == is_osx))
|
(osx == None or osx == is_osx))
|
||||||
|
|
||||||
|
|
||||||
|
def normalize_string_keys(old):
|
||||||
|
'''Given a dictionary, make sure keys are unicode strings, not bytes.'''
|
||||||
|
new = {}
|
||||||
|
for key, value in old:
|
||||||
|
if isinstance(key, bytes_):
|
||||||
|
new[key.decode('utf8')] = value
|
||||||
|
else:
|
||||||
|
new[key] = value
|
||||||
|
return new
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user