diff --git a/actes-princiers/conf/base/catalog.yml b/actes-princiers/conf/base/catalog.yml index 2692997..43a7649 100644 --- a/actes-princiers/conf/base/catalog.yml +++ b/actes-princiers/conf/base/catalog.yml @@ -16,7 +16,7 @@ bourbon_json: folderpath: data/01_raw/houses/bourbon bourbon_jsonoutput: - type: actesdataset.JSONDataSetCollection + type: actesdataset.FullJSONDataSetCollection housename: bourbon folderpath: data/02_intermediate/houses/bourbon/json diff --git a/actes-princiers/src/actes_princiers/pipelines/xml_processing/nodes.py b/actes-princiers/src/actes_princiers/pipelines/xml_processing/nodes.py index 7983274..ee01cab 100755 --- a/actes-princiers/src/actes_princiers/pipelines/xml_processing/nodes.py +++ b/actes-princiers/src/actes_princiers/pipelines/xml_processing/nodes.py @@ -61,3 +61,4 @@ def parse_json_collection(datasetcol: JSONDataSetCollection) -> Dict[str, BsXMLD output_datasets[dataset_filenamestem] = output_xmldataset return output_datasets +#def add_xmlcontent_tojson(jsondoc: JSONDataSetCollection, xmlcontent: XMLDataSetCollection) -> diff --git a/actes-princiers/src/actesdataset.py b/actes-princiers/src/actesdataset.py index 3b97c3f..b42163b 100644 --- a/actes-princiers/src/actesdataset.py +++ b/actes-princiers/src/actesdataset.py @@ -158,11 +158,36 @@ class JSONDataSetCollection(DataSetCollection): filepath=str(filepath)) return self + +class JSONDataSet(AbstractDataSet): + def __init__(self, filepath: str): + self._filepath = filepath + + def _load(self) -> Dict: + with open(self._filepath, 'r') as fp: + return json.load(fp) + + def _save(self, data: Dict) -> None: + with open(self._filepath, 'w') as fp: + json.dump(data, fp, sort_keys=True, indent=4) + + def _describe(self) -> Dict[str, Any]: + return dict(filepath=self._filepath) + + +class FullJSONDataSetCollection(DataSetCollection): + def _load(self) -> dict[str, JSONDataSet]: + "kedro's API loader method" + self.datasets = dict() + for filepath in sorted(self._folderpath.glob("*.xml")): + self.datasets[filepath.stem] = JSONDataSet( + filepath=str(filepath)) + return self + + #class TextDataSet: # """loads/saves data from/to a text file using an underlying filesystem - # example usage - # >>> string_to_write = "This will go in a file." # >>> # >>> data_set = TextDataSet(filepath="test.md") @@ -183,19 +208,3 @@ class JSONDataSetCollection(DataSetCollection): # def _describe(self) -> Dict[str, Any]: # return dict(filepath=self._filepath) - -#class JSONDataSet(AbstractDataSet): -# def __init__(self, filepath: str): -# self._filepath = filepath - -# def _load(self) -> Dict: -# with open(self._filepath, 'r') as fp: -# return json.load(fp) - -# def _save(self, data: Dict) -> None: -# with open(self._filepath, 'w') as fp: -# json.dump(data, fp, sort_keys=True, indent=4) - -# def _describe(self) -> Dict[str, Any]: -# return dict(filepath=self._filepath) -