06dc59afe4657c009430a4673f1504feb69d2736,torchtext/data/example.py,Example,fromJSON,#Any#Any#Any#,12
Before Change
ex = cls()
obj = json.loads(data)
for key, vals in fields.items():
if vals is not None:
if not isinstance(vals, list):
vals = [vals]
for val in vals:
// for processing the key likes "foo.bar"
name, field = val
ks = key.split(".")
def reducer(obj, key):
if isinstance(obj, list):
results = []
for data in obj:
if key not in data:
// key error
raise ValueError("Specified key {} was not found in "
"the input data".format(key))
else:
results.append(data[key])
return results
else:
// key error
if key not in obj:
raise ValueError("Specified key {} was not found in "
"the input data".format(key))
else:
return obj[key]
v = reduce(reducer, ks, obj)
setattr(ex, name, field.preprocess(v))
return ex
@classmethod
def fromdict(cls, data, fields):
After Change
class Example(object):
@classmethod
def fromJSON(cls, data, fields):
warnings.warn("{} class has ".format(self.__class__.__name__) +
"been retired and moved to torchtext.legacy. Please " +
"import from torchtext.legacy.data if you still want it.", UserWarning)
raise ImportWarning
In pattern: SUPERPATTERN
Frequency: 3
Non-data size: 7
Instances Project Name: pytorch/text
Commit Name: 06dc59afe4657c009430a4673f1504feb69d2736
Time: 2021-02-17
Author: 6156351+zhangguanheng66@users.noreply.github.com
File Name: torchtext/data/example.py
Class Name: Example
Method Name: fromJSON
Project Name: sony/nnabla
Commit Name: ffdd950970c5953e351fa88795fe916b3465d813
Time: 2018-06-13
Author: Yukio.Oobuchi@sony.com
File Name: python/src/nnabla/utils/data_source_implements.py
Class Name: CacheDataSource
Method Name: _get_data
Project Name: pytorch/text
Commit Name: 06dc59afe4657c009430a4673f1504feb69d2736
Time: 2021-02-17
Author: 6156351+zhangguanheng66@users.noreply.github.com
File Name: torchtext/data/example.py
Class Name: Example
Method Name: fromdict