1.2.1. Bag definitionsΒΆ
definition - Bag: A Bag is a collection of BagNodes. You can use a Bag as a flat Bag or as a hierarchical Bag.
definition - BagNode: a
BagNode
(or “node”) is a Genro class composed by three metadata:
- a single label.
- a single value (or item).
- one or more attributes.
Where:
The “value” contains the value of the Bagnode.
The “attributes” allow to insert other metadata (for more information, check the attributes page).
Note
The couple
label:value
carries many analogies with thekey:value
couple Dictionary, so you can think to the Bag label as a transposition of the Dictionary key (for example, with thekeys()
method you will get all the Bag labels) but for its nature a key is unique, while Bag label can be unique or notLet’s see a scheme of a BagNode:
A BagNode value can be a Bag, so a Bag is a recursive and hierarchical container.
We now introduce the two definitions of a Bag:
- definition - flat Bag: it is a Bag in which all of its BagNodes don’t have a Bag as their value.
definition - hierarchical Bag: it is a nested Bag with complex path, including Bags as a value of some BagNodes (check Bag’s path section for more explanation).
Note
there is no syntax difference in the two definitions, as you can see in the How to instantiate a Bag section.
Each Bag may access directly to its inner elements using a path.
definition - path: it is a concatenation of traversed Bag labels separated by a dot (
.
) (For more information, check Bag’s path section).