diff --git a/website/content/tutorials/5-constraints-has-cardinality/_index.md b/website/content/tutorials/5-constraints-has-cardinality/_index.md new file mode 100644 index 00000000..397ff856 --- /dev/null +++ b/website/content/tutorials/5-constraints-has-cardinality/_index.md @@ -0,0 +1,917 @@ +--- +title: "Complex Constraints: has-cardinality" +description: "" +--- + +# Complex Constraints + +## Introduction + +In the previous tutorial, we enhanced the computer model and learned how to use constraints to customize specific fields' and flags' values by subsetting their data types or matching certain patterns with regular expressions. In previous tutorials about constraints, we have learned multiple techniques to precisely control the values of fields and flags. But how do we control the minimum and maximum number of occurrences for assemblies, fields, and flags in document instance(s) with logical conditions using their own identifiers and values? How do we do this with related assemblies, fields, and flags co-occurring these document instance(s)? + +To control the minimum and maximum occurrence of different assemblies, fields, flags and/or their respective values, we can use `has-cardinality` constraints to meet this use case. + +We will begin where we left off in the previous tutorial, with the model and conforming document instances below. + +```xml + + + + Computer Model + 0.0.11 + computer + http://example.com/ns/computer + http://example.com/ns/computer + + Computer Property + A property is a key-value pair of metadata about the computer, not its parts. + + + + + + + + + + + + + + + + Vendor Information + Information about a vendor of a computer part. + + Vendor Identifier + An identifier for classifying a unique computer parts vendor. + + + + Vendor Name + The registered company name of the vendor. + + + Vendor Address + The physical address of an office location for the vendor. + + + Vendor Website + A public website made by the vendor documenting their parts as used in the computer. + + + + + Product Name + The product name from the vendor of the computer part. + + + CPU Firmware + Information about the firmware for a computer CPU. + + + Firmware Version + An identifier that singles + + + Firmware Hash + A cryptographic hash with an approved algorithm of the firmware as flashed onto the chip. + value + + Hash Algorithm + + + The SHA-256 algorithm. + The SHA-512 algorithm. + + + + + + + + + + + + Computer Assembly + A container object for a computer, its parts, and its sub-parts. + computer + + Computer Identifier + An identifier for classifying a unique make and model of computer. + + + + + + + + Motherboard Assembly + A container object for a motherboard in a computer and its sub-parts. + + + + Motherboard Type + The type motherboard layout, at, atx, mini-itx or an alternative. + + + Motherboard Central Processing Unit (CPU) + The model number of the CPU on the motherboard of a computer. + + + + + + CPU Architecture + The Instruction Set Architecture (ISA) approved by module stakeholders. + + + Intel 64-bit systems, also known as x86-64 or em64t + Arm v7 32-bit systems + Arm v8 64-bit systems + Intel 32-bit x86 systems, for 686 class or newer + + + + + CPU Speed + The clock speed of the CPU in megahertz or gigahertz. + + + + + Motherboard Advanced Technology Attachment (ATA) Socket + The model number of ATA socket on the motherboard of a computer. There will only be one socket on any motherboard. + + + Vendor Information + Information about a vendor of a computer part. + + Vendor Identifier + An identifier for classifying a unique computer parts vendor. + + + + Vendor Name + The registered company name of the vendor. + + + Vendor Address + The physical address of an office location for the vendor. + + + Vendor Website + A public website made by the vendor documenting their parts as used in the computer. + + + + + Product Name + The product name from the vendor of the computer part. + + + ATA Socket Type + The type of ATA socket on the motherboard with approved (but optional) values recommended by model stakeholders. + + + Parallel ATA buses also known as AT-Attachment and IDE + Serial ATA buses supporting Advanced Host Controller Interface or legacy IDE modes + External Serial ATA buses for pluggable external devices using SATA + External Serial ATA buses supporting SATA traffic and device power + + + + + + + Motherboard Random Access Memory (RAM) Module(s) + Random access memory hardware installed on the motherboard of a computer. + + + + Vendor Information + Information about a vendor of a computer part. + + Vendor Identifier + An identifier for classifying a unique computer parts vendor. + + + + Vendor Name + The registered company name of the vendor. + + + Vendor Address + The physical address of an office location for the vendor. + + + Vendor Website + A public website made by the vendor documenting their parts as used in the computer. + + + + + Product Name + The product name from the vendor of the computer part. + + + + Memory Module Size + Size of the memory module in binary, not SI base-10 units, meaning a kilobyte is 1024 bytes, not 1000 bytes. + + + Memory Module Size + Size of memory module in binary or SI base-10 units, optionally with a size unit. This does not require to be in bits or bytes. If no optional flags are used, it is required to process its value as a size as counted in bits (not bytes) in decimal base-ten form, with no unit prefix. + count + + Memory Module Size Unit + The unit size for a memory module can either be bytes (B) or bits (b). + + + bytes + bits + + + + + Memory Module Size Unit Prefix Base + The prefix type of module size, binary or decimal. This is useful if you will not specify an optional unit or unit base. + + + + + + + + + Memory Module Size Unit Prefix + The optional prefix the of unit from a given system. + + + + + + + + + + + + + Memory Module Size Unit System + An identifier for the organization associated with the specific usage of the unit with its prefix. If absent, the use of no unit is assumed with and the value is counted in bits. + + + The International Electrotechnical Commission 60027-2 Amendment 2 Units + JEDEC Solid State Technology Association Units + International System of Units + + + + + + + + + All memory modules MUST have a byte divisible by two. + + + All memory modules SHOULD have a bite size divisible by one megabyte (1,024 bytes) . + + + All memory modules SHOULD use size because byte-size is now deprecated and byte-size will be removed. + + + + + Motherboard Expansion Card + The model number of an expansion card connected to the motherboard of a computer. + + + + Vendor Information + Information about a vendor of a computer part. + + Vendor Identifier + An identifier for classifying a unique computer parts vendor. + + + + Vendor Name + The registered company name of the vendor. + + + Vendor Address + The physical address of an office location for the vendor. + + + Vendor Website + A public website made by the vendor documenting their parts as used in the computer. + + + + + Product Name + The product name from the vendor of the computer part. + + + Expansion Card Type + The type of expansion card on a motherboard of a computer, such as pci (PCI, e.g. Peripheral Component Interconnect), pcie (PCI Express), or an alternative. + + + + + + + All memory modules SHOULD be the same size or byte-size for a computer. + + + + + + + + + + + + +``` + +{{< tabs JSON XML YAML >}} +{{% tab %}} +{{< highlight json >}} +{ + "computer": { + "id": "awesomepc1", + "properties": [ + { + "ns": "http://example-consortium.org", + "key": "release-status", + "value": "public" + }, + { + "ns": "http://specific-vendor.com", + "key": "release-status", + "value": "custom" + }, + { + "ns": "http://example-consortium.org", + "key": "release-date", + "value": "2024-01-0Z" + } + ], + "motherboard": { + "vendor": { + "id": "vendor2", + "name": "ISA Corp", + "address": "2000 K Street NW Washington, DC 20002", + "website": "https://example.com/isacorp/" + }, + "type": "atx", + "cpu": { + "vendor": { + "id": "vendor2", + "name": "ISA Corp", + "address": "2000 K Street NW Washington, DC 20002", + "website": "https://example.com/isacorp/" + }, + "product-name": "Superchip Model 1 4-core Processor", + "firmware": { + "version": "1.2.1", + "hash": { + "algorithm": "sha512", + "value": "7e9c54ef590b3e053495c253e135695eb55f4e966d49671e8739f5574d27f7809fefb8f75b998b1333a934bb59f4246928c11621e411286d77191a53ae362e3a" + } + }, + "architecture": "arm64", + "speed": "4.7 gigahertz" + }, + "ata-socket": { + "vendor": { + "id": "vendor2", + "name": "ISA Corp", + "address": "2000 K Street NW Washington, DC 20002", + "website": "https://example.com/isacorp/" + }, + "product-name": "AwesomeSAS Model 1 Storage Socket", + "type": "sas" + }, + "memory-modules": [ + { + "vendor": { + "id": "vendor3", + "name": "Massive Memory Corp", + "address": "3000 K Street NW Washington, DC 20003", + "website": "https://example.com/massive-memory-corp/" + }, + "product-name": "Erroneous Model 3 DDR4-3200 8GB (Module 1)", + "size": { + "count": 7, + "prefix": "G", + "unit": "B", + "unit-system": "si", + "base": "decimal" + } + }, + { + "vendor": { + "id": "vendor3", + "name": "Massive Memory Corp", + "address": "3000 K Street NW Washington, DC 20003", + "website": "https://example.com/massive-memory-corp/" + }, + "product-name": "Model 3 DDR4-3200 8GB (Module 2)", + "size": { + "count": 7, + "prefix": "G", + "unit": "B", + "unit-system": "si", + "base": "decimal" + } + } + ] + } + } +} +{{< /highlight >}} +{{% /tab %}} +{{% tab %}} +{{< highlight xml >}} + + + + + + + AwesomeComp Incorportated +
1000 K Street NW Washington, DC 20001
+ https://example.com/awesomecomp/ +
+ + + ISA Corp +
2000 K Street NW Washington, DC 20002
+ https://example.com/isacorp/ +
+ atx + + + ISA Corp +
2000 K Street NW Washington, DC 20002
+ https://example.com/isacorp/ +
+ Superchip Model 1 4-core Processor + + 1.2.1 + 7e9c54ef590b3e053495c253e135695eb55f4e966d49671e8739f5574d27f7809fefb8f75b998b1333a934bb59f4246928c11621e411286d77191a53ae362e3a + + arm64 + 4.7 gigahertz +
+ + + ISA Corp +
2000 K Street NW Washington, DC 20002
+ https://example.com/isacorp/ +
+ AwesomeSAS Model 1 Storage Socket + sas +
+ + + Massive Memory Corp +
3000 K Street NW Washington, DC 20003
+ https://example.com/massive-memory-corp/ +
+ Erroneous Model 3 DDR4-3200 8GB (Module 1) + 8 +
+ + + Massive Memory Corp +
3000 K Street NW Washington, DC 20003
+ https://example.com/massive-memory-corp/ +
+ Model 3 DDR4-3200 8GB (Module 2) + 8 +
+
+
+{{< /highlight >}} +{{% /tab %}} +{{% tab %}} +{{< highlight yaml >}} +--- +computer: + id: awesomepc1 + properties: + - ns: http://example-consortium.org + key: release-status + value: public + - ns: http://specific-vendor.com + key: release-status + value: custom + - ns: http://example-consortium.org + key: release-date + value: 2024-01-01Z + vendor: + id: vendor1 + name: AwesomeComp Incorportated + address: 1000 K Street NW Washington, DC 20001 + website: https://example.com/awesomecomp/ + motherboard: + vendor: + id: vendor2 + name: ISA Corp + address: 2000 K Street NW Washington, DC 20002 + website: https://example.com/isacorp/ + product-name: Magestic Model M-Ultra Motherboard + type: atx + cpu: + vendor: + id: vendor2 + name: ISA Corp + address: 2000 K Street NW Washington, DC 20002 + website: https://example.com/isacorp/ + firmware: + version: 1.2.1 + hash: + algorithm: sha512 + value: 7e9c54ef590b3e053495c253e135695eb55f4e966d49671e8739f5574d27f7809fefb8f75b998b1333a934bb59f4246928c11621e411286d77191a53ae362e3a + architecture: arm64 + product-name: Superchip Model 1 4-core Processor + speed: 4.7 gigahertz + ata-socket: + vendor: + id: vendor2 + name: ISA Corp + address: 2000 K Street NW Washington, DC 20002 + website: https://example.com/isacorp/ + product-name: AwesomeSAS Model 1 Storage Socket + type: sas + memory-modules: + - vendor: + id: vendor3 + name: Massive Memory Corp + address: 3000 K Street NW Washington, DC 20003 + website: https://example.com/massive-memory-corp/ + product-name: Erroneous Model 3 DDR4-3200 8GB (Module 1) + size: + count: 7 + prefix: G + unit: B + unit-system: si + base: decimal + - size: + count: 8 + prefix: G + unit: B + unit-system: si + base: decimal + product-name: Model 3 DDR4-3200 8GB (Module 2) + vendor: + address: 3000 K Street NW Washington, DC 20003 + id: vendor3 + name: Massive Memory Corp + website: https://example.com/massive-memory-corp/ +{{< /highlight >}} +{{% /tab %}} +{{< /tabs >}} + +## Using has-cardinality constraints with identifiers + +Given previous successes with our Metaschema model, our stakeholders are eager to consult us and add a new requirement to the model. They want to propose a new requirement to partners in the consortium: the consortium requires that computers of the standard ATX form factor must have between one and four ATA sockets and between one and four memory slots. The consortium also requires that Mini ATX computers have one or two memory modules and no ATA sockets. + +Fortunately for us, this business requirement is easy to add to our Metaschema model using the `has-cardinality` constraint. We define Metapath expressions to count these fields and flags based upon their name. We then define the `min-occurs` and `max-occurs` specific to this use case. + +```xml {linenos=table,hl_lines=["313-316"]} + + + + Computer Model + 0.0.11 + computer + http://example.com/ns/computer + http://example.com/ns/computer + + Computer Property + A property is a key-value pair of metadata about the computer, not its parts. + + + + + + + + + + + + + + + + Vendor Information + Information about a vendor of a computer part. + + Vendor Identifier + An identifier for classifying a unique computer parts vendor. + + + + Vendor Name + The registered company name of the vendor. + + + Vendor Address + The physical address of an office location for the vendor. + + + Vendor Website + A public website made by the vendor documenting their parts as used in the computer. + + + + + Product Name + The product name from the vendor of the computer part. + + + CPU Firmware + Information about the firmware for a computer CPU. + + + Firmware Version + An identifier that singles + + + Firmware Hash + A cryptographic hash with an approved algorithm of the firmware as flashed onto the chip. + value + + Hash Algorithm + + + The SHA-256 algorithm. + The SHA-512 algorithm. + + + + + + + + + + + + Computer Assembly + A container object for a computer, its parts, and its sub-parts. + computer + + Computer Identifier + An identifier for classifying a unique make and model of computer. + + + + + + + + Motherboard Assembly + A container object for a motherboard in a computer and its sub-parts. + + + + Motherboard Type + The type motherboard layout, at, atx, mini-itx or an alternative. + + + Motherboard Central Processing Unit (CPU) + The model number of the CPU on the motherboard of a computer. + + + + + + CPU Architecture + The Instruction Set Architecture (ISA) approved by module stakeholders. + + + Intel 64-bit systems, also known as x86-64 or em64t + Arm v7 32-bit systems + Arm v8 64-bit systems + Intel 32-bit x86 systems, for 686 class or newer + + + + + CPU Speed + The clock speed of the CPU in megahertz or gigahertz. + + + + + Motherboard Advanced Technology Attachment (ATA) Socket + The model number of ATA socket on the motherboard of a computer. There will only be one socket on any motherboard. + + + Vendor Information + Information about a vendor of a computer part. + + Vendor Identifier + An identifier for classifying a unique computer parts vendor. + + + + Vendor Name + The registered company name of the vendor. + + + Vendor Address + The physical address of an office location for the vendor. + + + Vendor Website + A public website made by the vendor documenting their parts as used in the computer. + + + + + Product Name + The product name from the vendor of the computer part. + + + ATA Socket Type + The type of ATA socket on the motherboard with approved (but optional) values recommended by model stakeholders. + + + Parallel ATA buses also known as AT-Attachment and IDE + Serial ATA buses supporting Advanced Host Controller Interface or legacy IDE modes + External Serial ATA buses for pluggable external devices using SATA + External Serial ATA buses supporting SATA traffic and device power + + + + + + + Motherboard Random Access Memory (RAM) Module(s) + Random access memory hardware installed on the motherboard of a computer. + + + + Vendor Information + Information about a vendor of a computer part. + + Vendor Identifier + An identifier for classifying a unique computer parts vendor. + + + + Vendor Name + The registered company name of the vendor. + + + Vendor Address + The physical address of an office location for the vendor. + + + Vendor Website + A public website made by the vendor documenting their parts as used in the computer. + + + + + Product Name + The product name from the vendor of the computer part. + + + + Memory Module Size + Size of the memory module in binary, not SI base-10 units, meaning a kilobyte is 1024 bytes, not 1000 bytes. + + + Memory Module Size + Size of memory module in binary or SI base-10 units, optionally with a size unit. This does not require to be in bits or bytes. If no optional flags are used, it is required to process its value as a size as counted in bits (not bytes) in decimal base-ten form, with no unit prefix. + count + + Memory Module Size Unit + The unit size for a memory module can either be bytes (B) or bits (b). + + + bytes + bits + + + + + Memory Module Size Unit Prefix Base + The prefix type of module size, binary or decimal. This is useful if you will not specify an optional unit or unit base. + + + + + + + + + Memory Module Size Unit Prefix + The optional prefix the of unit from a given system. + + + + + + + + + + + + + Memory Module Size Unit System + An identifier for the organization associated with the specific usage of the unit with its prefix. If absent, the use of no unit is assumed with and the value is counted in bits. + + + The International Electrotechnical Commission 60027-2 Amendment 2 Units + JEDEC Solid State Technology Association Units + International System of Units + + + + + + + + + All memory modules MUST have a byte divisible by two. + + + All memory modules SHOULD have a bite size divisible by one megabyte (1,024 bytes) . + + + All memory modules SHOULD use size because byte-size is now deprecated and byte-size will be removed. + + + + + Motherboard Expansion Card + The model number of an expansion card connected to the motherboard of a computer. + + + + Vendor Information + Information about a vendor of a computer part. + + Vendor Identifier + An identifier for classifying a unique computer parts vendor. + + + + Vendor Name + The registered company name of the vendor. + + + Vendor Address + The physical address of an office location for the vendor. + + + Vendor Website + A public website made by the vendor documenting their parts as used in the computer. + + + + + Product Name + The product name from the vendor of the computer part. + + + Expansion Card Type + The type of expansion card on a motherboard of a computer, such as pci (PCI, e.g. Peripheral Component Interconnect), pcie (PCI Express), or an alternative. + + + + + + + All memory modules SHOULD be the same size or byte-size for a computer. + + + + + + + + + + +``` + +## Using has-cardinality constraints with values + +## Using complex has-cardinality constraints with both + +## Conclusion