nbbrd / sdmx-dl

Easily download official statistics
https://nbbrd.github.io/sdmx-dl
European Union Public License 1.2
3 stars 0 forks source link

Add support of attribute relationship #81

Closed charphi closed 2 years ago

charphi commented 3 years ago

Attributes can be attached at different level such as observation-level, time series-level and sibling-level. (see example at https://sdw.ecb.europa.eu/datastructure.do?datasetinstanceid=120) Currently, sdmx-dl cannot distringuish these levels.

charphi commented 2 years ago

In SDMX glossary v2.1, this feature is named Attribute Relationship (Attachment level in v2.0).

Definition: Specification of the type of artefact to which a data attribute can be attached in a Data Set. Context: A part of the specification of Attribute in a Data Structure Definition denotes to which part of the data the Attribute can relate in a Data Set. This can be the entire Data Set, specific grouping of the Dimensions, or an Observation. This is a version 2.1 construct. In version 2.0 this was known as the "attachment level".

DataStructure schema v2.0:

<xs:simpleType name="AttachmentLevelType">
    <xs:restriction base="xs:NMTOKEN">
        <xs:enumeration value="DataSet">
            <xs:annotation>
                <xs:documentation>Data set level</xs:documentation>
            </xs:annotation>
        </xs:enumeration>
        <xs:enumeration value="Group">
            <xs:annotation>
                <xs:documentation>Group level</xs:documentation>
            </xs:annotation>
        </xs:enumeration>
        <xs:enumeration value="Series">
            <xs:annotation>
                <xs:documentation>Series level</xs:documentation>
            </xs:annotation>
        </xs:enumeration>
        <xs:enumeration value="Observation">
            <xs:annotation>
                <xs:documentation>Observation level</xs:documentation>
            </xs:annotation>
        </xs:enumeration>
    </xs:restriction>
</xs:simpleType>

DataStructure schema v2.1:

<xs:complexType name="AttributeRelationshipType">
    <xs:annotation>
        <xs:documentation>AttributeRelationshipType defines the structure for stating the relationship between an attribute and other data structure definition components.</xs:documentation>
    </xs:annotation>
    <xs:choice>
        <xs:element name="None" type="common:EmptyType">
            <xs:annotation>
                <xs:documentation>This means that value of the attribute will not vary with any of the other key family components. This will always be treated as a data set level attribute.</xs:documentation>
            </xs:annotation>
        </xs:element>
        <xs:sequence>
            <xs:element name="Dimension" type="common:LocalDimensionReferenceType" maxOccurs="unbounded">
                <xs:annotation>
                    <xs:documentation>This is used to reference dimensions in the data structure definition on which the value of this attribute depends. An attribute using this relationship can be either a group, series (or section), or observation level attribute. The attachment level of the attribute will be determined by the data format and which dimensions are referenced.</xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="AttachmentGroup" type="common:LocalGroupKeyDescriptorReferenceType" minOccurs="0" maxOccurs="unbounded">
                <xs:annotation>
                    <xs:documentation>This is used to specify that the attribute should always be attached to the groups referenced here. Note that if one of the referenced dimensions is the time dimension, the groups referenced here will be ignored.</xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:sequence>
        <xs:element name="Group" type="common:LocalGroupKeyDescriptorReferenceType">
            <xs:annotation>
                <xs:documentation>This is used as a convenience to referencing all of the dimension defined by the referenced group. The attribute will also be attached to this group.</xs:documentation>
            </xs:annotation>
        </xs:element>
        <xs:element name="PrimaryMeasure" type="common:LocalPrimaryMeasureReferenceType">
            <xs:annotation>
                <xs:documentation>This is used to specify that the value of the attribute is dependent upon the observed value. An attribute with this relationship will always be treated as an observation level attribute.</xs:documentation>
            </xs:annotation>
        </xs:element>
    </xs:choice>
</xs:complexType>

DataStructure schema v3.0:

<xs:complexType name="AttributeRelationshipType">
    <xs:annotation>
        <xs:documentation>AttributeRelationshipType defines the structure for stating the relationship between an attribute and other data structure definition components.</xs:documentation>
    </xs:annotation>
    <xs:choice>
        <xs:element name="Dataflow" type="common:EmptyType">
            <xs:annotation>
                <xs:documentation>This means that the value of the attribute varies per dataflow. It is the data modeller's responsibility to design or use non-overlapping dataflows that do not have observations in common, otherwise the integrity of dataflow-specific attribute values is not assured by the model, e.g. when querying those data through its DSD.</xs:documentation>
            </xs:annotation>
        </xs:element>
        <xs:sequence>
            <xs:element name="Dimension" type="OptionalLocalDimensionReferenceType" maxOccurs="unbounded">
                <xs:annotation>
                    <xs:documentation>This is used to reference dimensions in the data structure definition on which the value of this attribute depends. An attribute using this relationship can be either a group, series (or section), or observation level attribute. The attachment level of the attribute will be determined by the data format and which dimensions are referenced.</xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:sequence>
        <xs:element name="Group" type="common:IDType">
            <xs:annotation>
                <xs:documentation>This is used as a convenience to referencing all of the dimension defined by the referenced group. The attribute will also be attached to this group.</xs:documentation>
            </xs:annotation>
        </xs:element>
        <xs:element name="Observation" type="common:EmptyType">
            <xs:annotation>
                <xs:documentation>This is used to specify that the value of the attribute is dependent upon the observed value. An attribute with this relationship will always be treated as an observation level attribute.</xs:documentation>
            </xs:annotation>
        </xs:element>
    </xs:choice>
</xs:complexType>
charphi commented 2 years ago

Done in cdff4602ba6acbc8835b4edaf2eb64bc468278c3