sdml_core/stdlib/
rdf.rs

1/*!
2This Rust module contains the SDML model of the SDML library module `rdf` for RDF syntax.
3*/
4
5use crate::model::{
6    annotations::{AnnotationOnlyBody, HasAnnotations},
7    modules::Module,
8    HasBody,
9};
10use std::str::FromStr;
11
12// ------------------------------------------------------------------------------------------------
13// Public Types
14// ------------------------------------------------------------------------------------------------
15
16pub const MODULE_PATH: &str = "::org::w3";
17pub const MODULE_NAME: &str = "rdf";
18pub const MODULE_URL: &str = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
19
20pub const HTML: &str = "HTML";
21pub const JSON: &str = "JSON";
22pub const LANG_STRING: &str = "langString";
23pub const PLAIN_LITERAL: &str = "PlainLiteral";
24pub const XML_LITERAL: &str = "XMLLiteral";
25
26pub const ALT: &str = "Alt";
27pub const BAG: &str = "Bag";
28pub const LIST: &str = "List";
29pub const PROPERTY: &str = "Property";
30pub const SEQ: &str = "Seq";
31pub const STATEMENT: &str = "Statement";
32
33pub const FIRST: &str = "first";
34pub const NIL: &str = "nil";
35pub const OBJECT: &str = "object";
36pub const PREDICATE: &str = "predicate";
37pub const REST: &str = "rest";
38pub const SUBJECT: &str = "subject";
39pub const TYPE: &str = "type";
40pub const VALUE: &str = "value";
41
42pub const COMPOUND: &str = "CompoundLiteral";
43pub const LANGUAGE: &str = "language";
44pub const DIRECTION: &str = "direction";
45
46// ------------------------------------------------------------------------------------------------
47// Public Functions
48// ------------------------------------------------------------------------------------------------
49
50module_function!(|| {
51    let module_uri: url::Url = url::Url::parse(MODULE_URL).unwrap();
52
53    module!(
54        id!(unchecked rdf), module_uri ; call |module: Module|
55        module.with_imports([import_statement!(
56            id!(unchecked rdfs),
57        )])
58            .with_definitions([
59                // ---------------------------------------------------------------------------------
60                // Literal Types
61                // ---------------------------------------------------------------------------------
62                rdf!(id!(unchecked HTML) ;
63                    class id!(unchecked rdfs:Literal) ;
64                    call |body: AnnotationOnlyBody|
65                    body.with_annotations([
66                        annotation!(id!(unchecked rdfs:isDefinedBy), id!(unchecked rdf)),
67                        annotation!(id!(unchecked skos:prefLabel), rdf_str!("HTML"@en)),
68                        annotation!(id!(unchecked rdfs:comment), rdf_str!("The datatype of RDF literals storing fragments of HTML content"@en)),
69                        annotation!(id!(unchecked rdfs:seeAlso), url!("http://www.w3.org/TR/rdf11-concepts/#section-html")),
70                    ])).into(),
71                rdf!(id!(unchecked JSON) ;
72                    class id!(unchecked rdfs:Literal) ;
73                    call |body: AnnotationOnlyBody|
74                    body.with_annotations([
75                        annotation!(id!(unchecked rdfs:isDefinedBy), id!(unchecked rdf)),
76                        annotation!(id!(unchecked skos:prefLabel), rdf_str!("JSON"@en)),
77                        annotation!(id!(unchecked rdfs:comment), rdf_str!("The datatype of RDF literals storing JSON content"@en)),
78                        annotation!(id!(unchecked rdfs:seeAlso), url!("https://www.w3.org/TR/json-ld11/#the-rdf-json-datatype")),
79                    ])).into(),
80                rdf!(id!(unchecked langString) ;
81                    class id!(unchecked rdfs:Literal) ;
82                    call |body: AnnotationOnlyBody|
83                    body.with_annotations([
84                        annotation!(id!(unchecked rdfs:isDefinedBy), id!(unchecked rdf)),
85                        annotation!(id!(unchecked skos:prefLabel), rdf_str!("Language-Tagged String"@en)),
86                        annotation!(id!(unchecked rdfs:comment), rdf_str!("The datatype of language-tagged string values"@en)),
87                        annotation!(id!(unchecked rdfs:seeAlso), url!("http://www.w3.org/TR/rdf11-concepts/#section-Graph-Literal")),
88                    ])).into(),
89                rdf!(id!(unchecked plainLiteral) ;
90                    class id!(unchecked rdfs:Literal) ;
91                    call |body: AnnotationOnlyBody|
92                    body.with_annotations([
93                        annotation!(id!(unchecked rdfs:isDefinedBy), id!(unchecked rdf)),
94                        annotation!(id!(unchecked skos:prefLabel), rdf_str!("Plain Literal"@en)),
95                        annotation!(id!(unchecked rdfs:comment), rdf_str!("The class of plain (i.e. untyped) literal values, as used in RIF and OWL 2"@en)),
96                        annotation!(id!(unchecked rdfs:seeAlso), url!("http://www.w3.org/TR/rdf-plain-literal/")),
97                    ])).into(),
98                rdf!(id!(unchecked XMLLiteral) ;
99                    class id!(unchecked rdfs:Literal) ;
100                    call |body: AnnotationOnlyBody|
101                    body.with_annotations([
102                        annotation!(id!(unchecked rdfs:isDefinedBy), id!(unchecked rdf)),
103                        annotation!(id!(unchecked skos:prefLabel), rdf_str!("XML Literal"@en)),
104                        annotation!(id!(unchecked rdfs:comment), rdf_str!("The datatype of XML literal values")),
105                    ])).into(),
106                // ---------------------------------------------------------------------------------
107                // Generic Properties
108                // ---------------------------------------------------------------------------------
109                rdf!(id!(unchecked Property) ;
110                    class ;
111                    call |body: AnnotationOnlyBody|
112                    body.with_annotations([
113                        annotation!(id!(unchecked rdfs:isDefinedBy), id!(unchecked rdf)),
114                        annotation!(id!(unchecked skos:prefLabel), rdf_str!(Property@en)),
115                        annotation!(id!(unchecked rdfs:comment), rdf_str!("The class of RDF properties")),
116                    ])).into(),
117                rdf!(id!(unchecked type) ;
118                    property id!(unchecked Property) ;
119                    call |body: AnnotationOnlyBody|
120                    body.with_annotations([
121                        annotation!(id!(unchecked rdfs:isDefinedBy), id!(unchecked rdf)),
122                        annotation!(id!(unchecked skos:prefLabel), rdf_str!(type@en)),
123                        annotation!(id!(unchecked skos:altLabel), rdf_str!(a@en)),
124                        annotation!(id!(unchecked rdfs:domain), id!(unchecked rdfs:Resource)),
125                        annotation!(id!(unchecked rdfs:range), id!(unchecked rdfs:Class)),
126                    ])).into(),
127                rdf!(id!(unchecked value) ;
128                    property id!(unchecked Property) ;
129                    call |body: AnnotationOnlyBody|
130                    body.with_annotations([
131                        annotation!(id!(unchecked rdfs:isDefinedBy), id!(unchecked rdf)),
132                        annotation!(id!(unchecked skos:prefLabel), rdf_str!(value@en)),
133                        annotation!(id!(unchecked rdfs:domain), id!(unchecked rdfs:Resource)),
134                        annotation!(id!(unchecked rdfs:range), id!(unchecked rdfs:Resource)),
135                        annotation!(id!(unchecked rdfs:comment), rdf_str!("Idiomatic property used for structured values"@en)),
136                    ])).into(),
137                // ---------------------------------------------------------------------------------
138                // Container Classes and Properties
139                // ---------------------------------------------------------------------------------
140                rdf!(id!(unchecked Alt) ;
141                    class id!(unchecked rdfs:Container) ;
142                    call |body: AnnotationOnlyBody|
143                    body.with_annotations([
144                        annotation!(id!(unchecked rdfs:isDefinedBy), id!(unchecked rdf)),
145                        annotation!(id!(unchecked skos:prefLabel), rdf_str!("Property"@en)),
146                        annotation!(id!(unchecked rdfs:comment), rdf_str!("The class of containers of alternatives")),
147                    ])).into(),
148                rdf!(id!(unchecked Bag) ;
149                    class id!(unchecked rdfs:Container) ;
150                    call |body: AnnotationOnlyBody|
151                    body.with_annotations([
152                        annotation!(id!(unchecked rdfs:isDefinedBy), id!(unchecked rdf)),
153                        annotation!(id!(unchecked skos:prefLabel), rdf_str!("Bag"@en)),
154                        annotation!(id!(unchecked rdfs:comment), rdf_str!("The class of unordered containers")),
155                    ])).into(),
156                rdf!(id!(unchecked Seq) ;
157                    class id!(unchecked rdfs:Container) ;
158                    call |body: AnnotationOnlyBody|
159                    body.with_annotations([
160                        annotation!(id!(unchecked rdfs:isDefinedBy), id!(unchecked rdf)),
161                        annotation!(id!(unchecked skos:prefLabel), rdf_str!("Seq"@en)),
162                        annotation!(id!(unchecked rdfs:comment), rdf_str!("The class of ordered containers")),
163                    ])).into(),
164                rdf!(id!(unchecked List) ;
165                    class ;
166                    call |body: AnnotationOnlyBody|
167                    body.with_annotations([
168                        annotation!(id!(unchecked rdfs:isDefinedBy), id!(unchecked rdf)),
169                        annotation!(id!(unchecked skos:prefLabel), rdf_str!(List@en)),
170                        annotation!(id!(unchecked rdfs:comment), rdf_str!("The class of RDF Lists")),
171                    ])).into(),
172                rdf!(id!(unchecked first) ;
173                    property id!(unchecked Property) ;
174                    call |body: AnnotationOnlyBody|
175                    body.with_annotations([
176                        annotation!(id!(unchecked rdfs:isDefinedBy), id!(unchecked rdf)),
177                        annotation!(id!(unchecked skos:prefLabel), rdf_str!(first@en)),
178                        annotation!(id!(unchecked rdfs:domain), id!(unchecked List)),
179                        annotation!(id!(unchecked rdfs:range), id!(unchecked rdfs:Resource)),
180                        annotation!(id!(unchecked rdfs:comment), rdf_str!("The first item in the subject RDF list"@en)),
181                    ])).into(),
182                rdf!(id!(unchecked rest) ;
183                    property id!(unchecked Property) ;
184                    call |body: AnnotationOnlyBody|
185                    body.with_annotations([
186                        annotation!(id!(unchecked rdfs:isDefinedBy), id!(unchecked rdf)),
187                        annotation!(id!(unchecked skos:prefLabel), rdf_str!(rest@en)),
188                        annotation!(id!(unchecked rdfs:domain), id!(unchecked List)),
189                        annotation!(id!(unchecked rdfs:range), id!(unchecked List)),
190                        annotation!(id!(unchecked rdfs:comment), rdf_str!("The rest of the subject RDF list after the first item"@en)),
191                    ])).into(),
192                rdf!(id!(unchecked nil) ;
193                    unnamed individual ;
194                    call |body: AnnotationOnlyBody|
195                    body.with_annotations([
196                        annotation!(id!(unchecked rdfs:isDefinedBy), id!(unchecked rdf)),
197                        annotation!(id!(unchecked skos:prefLabel), rdf_str!(language@en)),
198                        annotation!(id!(unchecked type), id!(unchecked List)),
199                        annotation!(id!(unchecked rdfs:comment), rdf_str!("The empty list, with no items in it. If the rest of a list is nil then the list has no more items in it")),
200                    ])).into(),
201                // ---------------------------------------------------------------------------------
202                // Reification Vocabulary
203                // ---------------------------------------------------------------------------------
204                rdf!(id!(unchecked Statement) ;
205                    class ;
206                    call |body: AnnotationOnlyBody|
207                    body.with_annotations([
208                        annotation!(id!(unchecked rdfs:isDefinedBy), id!(unchecked rdf)),
209                        annotation!(id!(unchecked skos:prefLabel), rdf_str!(Statement@en)),
210                        annotation!(id!(unchecked rdfs:comment), rdf_str!("The class of RDF statements")),
211                    ])).into(),
212                rdf!(id!(unchecked subject) ;
213                    property ;
214                    call |body: AnnotationOnlyBody|
215                    body.with_annotations([
216                        annotation!(id!(unchecked rdfs:isDefinedBy), id!(unchecked rdf)),
217                        annotation!(id!(unchecked skos:prefLabel), rdf_str!(subject@en)),
218                        annotation!(id!(unchecked rdfs:domain), id!(unchecked Statement)),
219                        annotation!(id!(unchecked rdfs:range), id!(unchecked rdfs:Resource)),
220                        annotation!(id!(unchecked rdfs:comment), rdf_str!("The subject of the subject RDF statement")),
221                    ])).into(),                rdf!(id!(unchecked predicate) ;
222                    property ;
223                    call |body: AnnotationOnlyBody|
224                    body.with_annotations([
225                        annotation!(id!(unchecked rdfs:isDefinedBy), id!(unchecked rdf)),
226                        annotation!(id!(unchecked skos:prefLabel), rdf_str!(predicate@en)),
227                        annotation!(id!(unchecked rdfs:domain), id!(unchecked Statement)),
228                        annotation!(id!(unchecked rdfs:range), id!(unchecked rdfs:Resource)),
229                        annotation!(id!(unchecked rdfs:comment), rdf_str!("The predicate of the subject RDF statement")),
230                    ])).into(),
231                rdf!(id!(unchecked object) ;
232                    property ;
233                    call |body: AnnotationOnlyBody|
234                    body.with_annotations([
235                        annotation!(id!(unchecked rdfs:isDefinedBy), id!(unchecked rdf)),
236                        annotation!(id!(unchecked skos:prefLabel), rdf_str!(object@en)),
237                        annotation!(id!(unchecked rdfs:domain), id!(unchecked Statement)),
238                        annotation!(id!(unchecked rdfs:range), id!(unchecked rdfs:Resource)),
239                        annotation!(id!(unchecked rdfs:comment), rdf_str!("The object of the subject RDF statement")),
240                    ])).into(),
241                // ---------------------------------------------------------------------------------
242                // Compound Literals
243                // ---------------------------------------------------------------------------------
244                rdf!(id!(unchecked CompoundLiteral) ;
245                    class ;
246                    call |body: AnnotationOnlyBody|
247                    body.with_annotations([
248                        annotation!(id!(unchecked rdfs:isDefinedBy), id!(unchecked rdf)),
249                        annotation!(id!(unchecked skos:prefLabel), rdf_str!(CompoundLiteral@en)),
250                        annotation!(id!(unchecked rdfs:comment), rdf_str!("A class representing a compound literal")),
251                        annotation!(id!(unchecked rdfs:seeAlso), url!("https://www.w3.org/TR/json-ld11/#the-rdf-compoundliteral-class-and-the-rdf-language-and-rdf-direction-properties")),
252                    ])).into(),
253                rdf!(id!(unchecked direction) ;
254                    property ;
255                    call |body: AnnotationOnlyBody|
256                    body.with_annotations([
257                        annotation!(id!(unchecked rdfs:isDefinedBy), id!(unchecked rdf)),
258                        annotation!(id!(unchecked skos:prefLabel), rdf_str!(direction@en)),
259                        annotation!(id!(unchecked rdfs:domain), id!(unchecked CompoundLiteral)),
260                        annotation!(id!(unchecked rdfs:range), id!(unchecked Literal)),
261                        annotation!(id!(unchecked rdfs:comment), rdf_str!("The base direction component of a CompoundLiteral")),
262                        annotation!(id!(unchecked rdfs:comment), rdf_str!("The range of the property is an rdfs:Literal, whose value MUST be either 'ltr' or 'rtl'")),
263                        annotation!(id!(unchecked rdfs:seeAlso), url!("https://www.w3.org/TR/json-ld11/#the-rdf-compoundliteral-class-and-the-rdf-language-and-rdf-direction-properties")),
264                    ])).into(),
265                rdf!(id!(unchecked language) ;
266                    property ;
267                    call |body: AnnotationOnlyBody|
268                    body.with_annotations([
269                        annotation!(id!(unchecked rdfs:isDefinedBy), id!(unchecked rdf)),
270                        annotation!(id!(unchecked skos:prefLabel), rdf_str!(language@en)),
271                        annotation!(id!(unchecked rdfs:domain), id!(unchecked CompoundLiteral)),
272                        annotation!(id!(unchecked rdfs:range), id!(unchecked Literal)),
273                        annotation!(id!(unchecked rdfs:comment), rdf_str!("The language component of a CompoundLiteral")),
274                        annotation!(id!(unchecked rdfs:comment), rdf_str!("The range of the property is an rdfs:Literal, whose value MUST be a well-formed [BCP47] language tag")),
275                        annotation!(id!(unchecked rdfs:seeAlso), url!("https://www.w3.org/TR/json-ld11/#the-rdf-compoundliteral-class-and-the-rdf-language-and-rdf-direction-properties")),
276                    ])).into(),
277            ])
278    )
279});