sdml_core/stdlib/
iso_3166.rs1use crate::model::{
6 annotations::{AnnotationOnlyBody, HasAnnotations},
7 definitions::UnionBody,
8 modules::Module,
9};
10use std::str::FromStr;
11
12pub const MODULE_NAME: &str = "iso_3166";
17library_module_url! { "iso", "3166:2020" }
18
19pub const MODULE_SRC: &str = include_str!("org/iso/iso_3166.sdml");
20
21pub const COUNTRY_CODE_ALPHA_2: &str = "CountryCodeAlpha2";
22pub const COUNTRY_CODE_ALPHA_3: &str = "CountryCodeAlpha3";
23pub const COUNTRY_CODE_NUMERIC_3: &str = "CountryCodeNumeric3";
24pub const COUNTRY_CODE: &str = "CountryCode";
25
26module_function!(|| {
31 let module_uri: url::Url = url::Url::parse(MODULE_URL).unwrap();
32
33 module!(
34 id!(unchecked iso_3166), module_uri ; call |module: Module|
35 module.with_imports([import_statement!(
36 id!(unchecked dc_terms),
37 id!(unchecked owl),
38 id!(unchecked rdf),
39 id!(unchecked rdfs),
40 id!(unchecked skos)
41 )])
42 .with_annotations([
43 annotation!(id!(unchecked skos:prefLabel), rdf_str!("ISO 3166-1:2020"@en)),
44 annotation!(id!(unchecked dc_terms:version), rdf_str!("4"@en)),
45 annotation!(id!(unchecked dc_terms:replaces), rdf_str!("ISO 3166-1:2013"@en)),
46 annotation!(id!(unchecked dc_terms:description), rdf_str!("Codes for the representation of names of countries and their subdivisions — Part 1: Country code"@en)),
47 annotation!(id!(unchecked dc_terms:description), rdf_str!("Codes pour la représentation des noms de pays et de leurs subdivisions — Partie 1: Codes de pays"@fr)),
48 annotation!(id!(unchecked rdfs:seeAlso), url!("https://www.iso.org/standard/72482.html")),
49 ])
50 .with_definitions([
51 datatype!(
52 id!(unchecked AlphaTwoCode), idref!(unchecked xsd:string) ;
53 call |body: AnnotationOnlyBody|
54 body.with_annotations([
55 annotation!(id!(unchecked rdfs:isDefinedBy), id!(unchecked iso_3166)),
56 annotation!(id!(unchecked xsd:pattern), rdf_str!("[A-Z]{2}")),
57 annotation!(id!(unchecked skos:prefLabel), rdf_str!("alpha-2 code"@en)),
58 annotation!(id!(unchecked skos:prefLabel), rdf_str!("code alpha-2"@fr)),
59 ])).into(),
60 datatype!(
61 id!(unchecked AlphaThreeCode), idref!(unchecked xsd:string) ;
62 call |body: AnnotationOnlyBody|
63 body.with_annotations([
64 annotation!(id!(unchecked rdfs:isDefinedBy), id!(unchecked iso_3166)),
65 annotation!(id!(unchecked xsd:pattern), rdf_str!("[A-Z]{3}")),
66 annotation!(id!(unchecked skos:prefLabel), rdf_str!("alpha-3 code"@en)),
67 annotation!(id!(unchecked skos:prefLabel), rdf_str!("code alpha-3"@fr)),
68 ])).into(),
69 datatype!(
70 id!(unchecked NumericCode), idref!(unchecked xsd:nonNegativeInteger) ;
71 call |body: AnnotationOnlyBody|
72 body.with_annotations([
73 annotation!(id!(unchecked rdfs:isDefinedBy), id!(unchecked iso_3166)),
74 annotation!(id!(unchecked xsd:minInclusive), v!(id!(unchecked xsd:nonNegativeInteger), 0)),
75 annotation!(id!(unchecked xsd:maxInclusive), v!(id!(unchecked xsd:nonNegativeInteger), 999)),
76 annotation!(id!(unchecked skos:prefLabel), rdf_str!("numeric-3 code"@en)),
77 annotation!(id!(unchecked skos:prefLabel), rdf_str!("code numérique-3"@fr)),
78 ])).into(),
79 union!(
80 id!(unchecked CountryCode) ;
81 call |body: UnionBody|
82 body.with_annotations([
83 annotation!(id!(unchecked rdfs:isDefinedBy), id!(unchecked iso_3166)),
84 annotation!(id!(unchecked skos:prefLabel), rdf_str!("country code"@en)),
85 ])
86 .with_variants([
87 unvar!(id!(unchecked AlphaTwoCode)),
88 unvar!(id!(unchecked AlphaThreeCode)),
89 unvar!(id!(unchecked NumericCode)),
90 ])).into(),
91 ])
92 )
93});