Background: In my computer vision program, users are modifying YAML files to supply annotation functions (lists items are functions, sequences of scalars are arguments). The workflow is open/modify YAML file > save yaml > parse and execute functions > show results, and start over or save. There can be multiple instances of the same tool in one file, differentiated through an "id" scalar. Since the annotations are saved after every iteration, they also needs to be control for overwrite behavior, which is also controlled with a scalar.
- create_annotation:
id: my_id1
overwrite: false
tool: mask
- create_annotation:
id: my_id2
overwrite: true
tool: mask
Problem I would like to start using some custom YAML tags to separate instance/overwrite statements from the function arguments (seems more intuitive). I use ruamel.yaml and I have looked at similar questions where the tags are "registered" through a class and then added to the constructor. However, I am not sure hoe to retrieve the tag information after loading (it's not in the ordereddict/CommentedMap).
Questions
- How do I construct and load a custom tag from a node and where do I find it?
- Can I have multiple tags per node?
Expected outcome
I was hoping for something like this:
- create_annotation: !id my_id1 !ow false
tool: mask
- create_annotation: !id my_id2 !ow true
tool: mask
Which would be parsed as:
{tool: mask,
id: my_id1,
overwrite: false}