Source code for node_dataset_to_dict
# This file is part of Sympathy for Data.
# Copyright (c) 2021 Combine Control Systems
#
# SYMPATHY FOR DATA COMMERCIAL LICENSE
# You should have received a link to the License with Sympathy for Data.
from sympathy.api import node, json, exceptions
from sympathy.api.nodeconfig import Port, Ports, Tag, Tags
from sylib_aml.dataset import DatasetPort
[docs]
class DatasetToDict(node.Node):
name = "Dataset to Dict (Experimental)"
nodeid = "com.sympathyfordata.advancedmachinelearning.datasettodict"
description = (
"Convert a dataset to a dictionary. Note that a dataset is a "
"structure that describes the data, containing meta information "
"including type, paths and calculations of the data etc. The output "
"dict will only holds these meta data, not the data.")
author = "Jannes Germishuys"
icon = "ds_to_dict.svg"
tags = Tags(Tag.MachineLearning.Processing)
inputs = Ports([DatasetPort("Dataset", "dataset")])
outputs = Ports([Port.Custom("{json}", "Json dict", name="json_dict")])
def execute(self, node_context):
input_ds = node_context.input["dataset"]
input_ds.load()
input_ds = input_ds.get_ds()
if input_ds is None:
raise exceptions.SyDataError("Empty dataset")
output = node_context.output[0]
for k, v in input_ds.items():
item = json.File()
item.set(v)
output[k] = item