def __init__(self, data_model=None): if data_model is None: self.data_model = DataModel.new() else: self.data_model = data_model self.connection_set = ConnectionSet(self.data_model) self.node_types = {}
def from_json(file_name, data_model_type='dict'): ''' Import a network from a JSON file using the nio library. ''' data_model = DataModel.new(data_model_type) network = Network(data_model) data = nio.read(file_name) nodes = data.get('nodes', None) if nodes is not None: network.data_model.insert('nodes', nodes) types = data.get('types', None) if types is not None: network.types = types connections = data.get('connections', None) if connections is not None: network.connection_set.add_list(connections) return network