def from_json(fpath): """ A static constructor of this class given a jsonified file """ if isinstance(fpath, str): if path.exists(fpath): #Get dataset path from json path with open(fpath, 'r') as f: ds_json = json.load(f) else: # logger.error("Found no dataset json at path: %s" % str(fpath)) raise Exception("Found no dataset json at path: %s" % str(fpath)) elif isinstance(fpath, IOBase): logger.debug("Loading dataset json from open file") ds_json = json.load(fpath) else: # logger.error("Found no dataset json at path: %s" % str(fpath)) raise Exception("Found no dataset json at path: %s" % str(fpath)) logger.debug("got dataset json: %s" % str(ds_json)) json_doc = { 'about': ds_json['about'], 'dataResources': ds_json['dataResources'] } dpath = ds_json['dataset_info']['root_path'] dname = ds_json['dataset_info']['dataset_dir'].rsplit("_", 1)[0] if isinstance(fpath, str): logger.debug("Creating D3mDataset with fpath: %s\nMetadata: %s" % (dpath, str(ds_json))) # ds = D3MDataset(fpath, ds_json['about']) ds = D3MDataset(dpath, ds_json) elif isinstance(fpath, IOBase): logger.debug("Creating D3mDataset with fpath: %s\nMetadata: %s" % (dpath, str(ds_json))) # ds = D3MDataset(fpath.name, ds_json['about']) ds = D3MDataset(dpath, ds_json) logger.debug("Creating problem description") logger.debug("Got default problem: %s" % str(ProblemDesc.get_default_problem(ds))) prob_desc = ProblemDesc.from_json(ProblemDesc.get_default_problem(ds)) # prob_desc = ProblemDesc.from_json( # LSPrediction.get_default_problem(ds_json['dataset_info']['root_path'])) return D3MPrediction(dpath, json_doc, path.join(dpath, ds_json['dataset_info']['dataset_dir'], 'output'), prob_desc=prob_desc, pfiles=ds_json['pred_info']['pred_files'])
def from_json(fpath): """ A static constructor of this class given a dataset json """ if isinstance(fpath, str): if path.exists: with open(fpath, 'r') as f: ds_json = json.load(f) else: logger.error("Found no dataset json at path: %s" % str(fpath)) raise Exception("Found no dataset json at path: %s" % str(fpath)) elif isinstance(fpath, IOBase): logger.debug("Loading dataset json from open file") ds_json = json.load(fpath) else: logger.error("Found no dataset json at path: %s" % str(fpath)) raise Exception("Found no dataset json at path: %s" % str(fpath)) dpath = ds_json['dataset_info']['root_path'] dname = ds_json['dataset_info']['dataset_dir'].rsplit("_", 1)[0] if isinstance(fpath, str): logger.debug("Creating D3mDataset with fpath: %s\nMetadata: %s" % (str(fpath), str(ds_json['about']))) # ds = D3MDataset(fpath, ds_json['about']) ds = D3MDataset(dpath, ds_json) elif isinstance(fpath, IOBase): logger.debug("Creating D3mDataset with fpath: %s\nMetadata: %s" % (fpath.name, str(ds_json['about']))) # ds = D3MDataset(fpath.name, ds_json['about']) ds = D3MDataset(dpath, ds_json) logger.debug("Creating problem description") logger.debug("Got default problem: %s" % str(ProblemDesc.get_default_problem(ds))) prob_desc = ProblemDesc.from_json(ProblemDesc.get_default_problem(ds)) # prob_desc = ProblemDesc.from_json( # prob_desc = ProblemDesc.from_json( # ProblemDesc.get_default_problem(D3MDataset(fpath, ds_json['about'])) # ) # LSPrediction.get_default_problem(ds_json['dataset_info']['root_path'])) return LSPrediction(ds_json['dataset_info']['root_path'], ds_json['pred_info']['pred_root'], prob_desc=prob_desc, pfiles=ds_json['pred_info']['pred_files'])