DSD-DBS / raillabel

A devkit for working with recorded and annotated train ride data from Deutsche Bahn.
Apache License 2.0
20 stars 7 forks source link

feat: Add load_from_string #34

Closed nalquas closed 1 year ago

nalquas commented 1 year ago

Summary

This PR adds a function load_from_string. For this, I have split up the existing load function.

Use case

Currently, if you want to modify a raillabel json file before loading it using raillabel's load, you have to save the modified json to disk first. Using load_from_string, you can skip creating a temporary file on disk.

Notes for reviewer

As a side effect of moving most of the code from load into load_from_string, the path variable isn't accessible anymore when printing warnings, so the filename isn't printed anymore. I could have added an optional path variable to load_from_string as a workaround, but I didn't want to expose that workaround to the API. Please suggest an alternative solution if this is a problem.

tklockau commented 1 year ago

There already is the option of loading a dictionary, that is only in memory by calling the specific loader class. If you want to load a RailLABEL dict, just call the following: LoaderRailLabelV2().load(your_dict)