sdml_core/stdlib/
sdml.rs

1/*!
2This Rust module contains the SDML model of the SDML library module `sdml`.
3*/
4
5use crate::model::annotations::AnnotationBuilder;
6use crate::model::modules::Module;
7use crate::model::HasBody;
8use crate::stdlib::{owl, rdf, rdfs, skos, xsd};
9use url::Url;
10
11// ------------------------------------------------------------------------------------------------
12// Public Macros
13// ------------------------------------------------------------------------------------------------
14
15// ------------------------------------------------------------------------------------------------
16// Public Types
17// ------------------------------------------------------------------------------------------------
18
19pub const MODULE_NAME: &str = "sdml";
20pub const MODULE_URL: &str = "http://sdml.io/sdml-owl.ttl#";
21
22pub const ANNOTATION: &str = "Annotation";
23pub const ANNOTATION_PROPERTY: &str = "AnnotationProperty";
24pub const CARDINALITY: &str = "Cardinality";
25pub const CONSTRAINT: &str = "Constraint";
26pub const DEFINITION: &str = "Definition";
27pub const ENTITY: &str = "Entity";
28pub const ENUMERATION: &str = "Enumeration";
29pub const EVENT: &str = "Event";
30pub const FEATURE_SET: &str = "FeatureSet";
31pub const FORMAL_CONSTRAINT: &str = "FormalConstraint";
32pub const IDENTIFIER_REFERENCE: &str = "IdentifierReference";
33pub const IMPORT: &str = "Import";
34pub const IMPORT_STATEMENT: &str = "ImportStatement";
35pub const INFORMAL_CONSTRAINT: &str = "InformalConstraint";
36pub const CLASS_MAP_TYPE_NAME: &str = "MapType";
37pub const MEMBER: &str = "Member";
38pub const MEMBER_IMPORT: &str = "MemberImport";
39pub const MODULE: &str = "Module";
40pub const MODULE_IMPORT: &str = "ModuleImport";
41pub const ORDERING_CONSTRAINT: &str = "OrderingConstraint";
42pub const PROPERTY: &str = "Property";
43pub const ROLE: &str = "Role";
44pub const ROLE_REFERENCE: &str = "RoleReference";
45pub const QUALIFIED_IDENTIFIER: &str = "QualifiedIdentifier";
46pub const STRUCTURE: &str = "Structure";
47pub const TYPE_CLASS: &str = "TypeClass";
48pub const TYPE_VARIANT: &str = "TypeVariant";
49pub const UNION: &str = "Union";
50pub const UNKNOWN: &str = "Unknown";
51pub const UNIQUENESS_CONSTRAINT: &str = "UniquenessConstraint";
52pub const VALUE_VARIANT: &str = "ValueVariant";
53
54pub const IDENTIFIER: &str = "Identifier";
55
56pub const BINARY: &str = "binary";
57pub const BOOLEAN: &str = "boolean";
58pub const DECIMAL: &str = "decimal";
59pub const DOUBLE: &str = "double";
60pub const INTEGER: &str = "integer";
61pub const IRI: &str = "iri";
62pub const LANGUAGE: &str = "language";
63pub const STRING: &str = "string";
64pub const UNSIGNED: &str = "unsigned";
65
66pub const HAS_NAME: &str = "hasName";
67pub const HAS_ANNOTATION: &str = "hasAnnotation";
68pub const HAS_CARDINALITY: &str = "hasCardinality";
69pub const HAS_DEFINITION: &str = "hasDefinition";
70pub const HAS_DOMAIN_VALUE: &str = "hasDomainValue";
71pub const HAS_IMPORT_STATEMENT: &str = "hasImportStatement";
72pub const HAS_MEMBER: &str = "hasMember";
73pub const HAS_RANGE_VALUE: &str = "hasRangeValue";
74pub const HAS_SOURCE_ENTITY: &str = "hasSourceEntity";
75pub const HAS_SOURCE_LOCATION: &str = "hasSourceLocation";
76pub const HAS_TYPE_VARIANT: &str = "hasTypeVariant";
77pub const HAS_VALUE_VARIANT: &str = "hasValueVariant";
78pub const LOCATION_END_BYTE: &str = "endByte";
79pub const LOCATION_START_BYTE: &str = "startByte";
80pub const LOCATION_START_LINE: &str = "startLine";
81pub const LOCATION_END_LINE: &str = "endLine";
82pub const LOCATION_START_COL: &str = "startColumn";
83pub const LOCATION_END_COL: &str = "endColumn";
84pub const MAX_OCCURS: &str = "maxOccurs";
85pub const MIN_OCCURS: &str = "minOccurs";
86pub const ORDERING: &str = "ordering";
87pub const SRC_LABEL: &str = "srcLabel";
88pub const UNIQUENESS: &str = "uniqueness";
89
90pub const ORDERED: &str = "Ordered";
91pub const UNIQUE: &str = "Unique";
92pub const NONUNIQUE: &str = "NonUnique";
93pub const UNORDERED: &str = "Unordered";
94
95// ------------------------------------------------------------------------------------------------
96// Public Functions
97// ------------------------------------------------------------------------------------------------
98
99pub fn module() -> Module {
100    #[allow(non_snake_case)]
101    let MODULE_IRI: url::Url = url::Url::parse(MODULE_URL).unwrap();
102    let mut module = Module::empty(id!(MODULE_NAME)).with_base_uri(Url::parse(MODULE_URL).unwrap());
103
104    module.body_mut().add_to_imports(import!(
105        id!(owl::MODULE_NAME),
106        id!(rdf::MODULE_NAME),
107        id!(rdfs::MODULE_NAME),
108        id!(skos::MODULE_NAME),
109        id!(xsd::MODULE_NAME)
110    ));
111
112    module
113        .body_mut()
114        .extend_definitions(vec![
115            // Classes
116            rdf!(class ANNOTATION, MODULE_IRI).into(),
117            rdf!(class ANNOTATION_PROPERTY, MODULE_IRI).into(),
118            rdf!(class CARDINALITY, MODULE_IRI).into(),
119            rdf!(class CONSTRAINT, MODULE_IRI).into(),
120            rdf!(class DEFINITION, MODULE_IRI).into(),
121            rdf!(class ENTITY, MODULE_IRI).into(),
122            rdf!(class ENUMERATION, MODULE_IRI).into(),
123            rdf!(class EVENT, MODULE_IRI).into(),
124            rdf!(class FEATURE_SET, MODULE_IRI).into(), // subClassOf :Union
125            rdf!(class FORMAL_CONSTRAINT, MODULE_IRI).into(),
126            rdf!(class IDENTIFIER_REFERENCE, MODULE_IRI).into(),
127            rdf!(class IMPORT, MODULE_IRI).into(),
128            rdf!(class IMPORT_STATEMENT, MODULE_IRI).into(),
129            rdf!(class INFORMAL_CONSTRAINT, MODULE_IRI).into(),
130            rdf!(class ORDERING_CONSTRAINT, MODULE_IRI).into(),
131            rdf!(class PROPERTY, MODULE_IRI).into(),
132            rdf!(class ROLE, MODULE_IRI).into(),
133            rdf!(class ROLE_REFERENCE, MODULE_IRI).into(),
134            rdf!(class QUALIFIED_IDENTIFIER, MODULE_IRI).into(),
135            rdf!(class STRUCTURE, MODULE_IRI).into(),
136            rdf!(class TYPE_CLASS, MODULE_IRI).into(),
137            rdf!(class TYPE_VARIANT, MODULE_IRI).into(),
138            rdf!(class UNION, MODULE_IRI).into(),
139            rdf!(class UNKNOWN, MODULE_IRI).into(), // subClassOf owl:Nothing
140            rdf!(class UNIQUENESS_CONSTRAINT, MODULE_IRI).into(),
141            rdf!(class VALUE_VARIANT, MODULE_IRI).into(),
142            // Data types
143            rdf!(datatype IDENTIFIER, MODULE_IRI).into(),
144            rdf!(datatype BINARY, MODULE_IRI)
145                .with_equivalent_class(qualid!(xsd::MODULE_NAME, xsd::HEX_BINARY))
146                .into(),
147            rdf!(datatype BOOLEAN, MODULE_IRI)
148                .with_equivalent_class(qualid!(xsd::MODULE_NAME, xsd::BOOLEAN))
149                .into(),
150            rdf!(datatype DECIMAL, MODULE_IRI)
151                .with_equivalent_class(qualid!(xsd::MODULE_NAME, xsd::DECIMAL))
152                .into(),
153            rdf!(datatype DOUBLE, MODULE_IRI)
154                .with_equivalent_class(qualid!(xsd::MODULE_NAME, xsd::DOUBLE))
155                .into(),
156            rdf!(datatype INTEGER, MODULE_IRI)
157                .with_equivalent_class(qualid!(xsd::MODULE_NAME, xsd::INTEGER))
158                .into(),
159            rdf!(datatype UNSIGNED, MODULE_IRI)
160                .with_equivalent_class(qualid!(xsd::MODULE_NAME, xsd::NONNEGATIVE_INTEGER))
161                .into(),
162            rdf!(datatype IRI, MODULE_IRI)
163                .with_equivalent_class(qualid!(xsd::MODULE_NAME, xsd::ANY_URI))
164                .into(),
165            rdf!(datatype STRING, MODULE_IRI)
166                .with_equivalent_class(qualid!(xsd::MODULE_NAME, xsd::STRING))
167                .into(),
168            rdf!(datatype LANGUAGE, MODULE_IRI)
169                .with_equivalent_class(qualid!(xsd::MODULE_NAME, xsd::LANGUAGE))
170                .into(),
171            // Properties
172            rdf!(property HAS_ANNOTATION, MODULE_IRI).into(),
173            rdf!(property HAS_CARDINALITY, MODULE_IRI).into(),
174            rdf!(property HAS_DEFINITION, MODULE_IRI).into(),
175            rdf!(property HAS_DOMAIN_VALUE, MODULE_IRI).into(),
176            rdf!(property HAS_IMPORT_STATEMENT, MODULE_IRI).into(),
177            rdf!(property HAS_MEMBER, MODULE_IRI).into(),
178            rdf!(property HAS_NAME, MODULE_IRI).into(),
179            rdf!(property HAS_RANGE_VALUE, MODULE_IRI).into(),
180            rdf!(property HAS_TYPE_VARIANT, MODULE_IRI).into(),
181            rdf!(property HAS_VALUE_VARIANT, MODULE_IRI).into(),
182            rdf!(property MAX_OCCURS, MODULE_IRI).into(),
183            rdf!(property MIN_OCCURS, MODULE_IRI).into(),
184            rdf!(property ORDERING, MODULE_IRI).into(),
185            rdf!(property SRC_LABEL, MODULE_IRI).into(),
186            rdf!(property UNIQUENESS, MODULE_IRI).into(),
187            // Individuals
188            rdf!(thing ORDERED, MODULE_IRI, ORDERING_CONSTRAINT).into(),
189            rdf!(thing NONUNIQUE, MODULE_IRI, UNIQUENESS_CONSTRAINT).into(),
190            rdf!(thing UNIQUE, MODULE_IRI, UNIQUENESS_CONSTRAINT).into(),
191            rdf!(thing UNORDERED, MODULE_IRI, ORDERING_CONSTRAINT).into(),
192        ])
193        .unwrap();
194
195    module
196}