Document (rdf rdf) and (rdf xsd)
README.md
| 69 | 69 | ``` | |
| 70 | 70 | ||
| 71 | 71 | Please [report](https://framagit.org/tyreunom/guile-jsonld/issues) any failure! | |
| 72 | + | ||
| 73 | + | Documentation | |
| 74 | + | ------------- | |
| 75 | + | ||
| 76 | + | This section documents the RDF library. It is mostly based on the different | |
| 77 | + | recommendations from the W3C. | |
| 78 | + | ||
| 79 | + | ### RDF Structures | |
| 80 | + | ||
| 81 | + | The RDF Structure is defined in module `(rdf rdf)`. | |
| 82 | + | ||
| 83 | + | #### **Scheme Datatype**: `rdf-dataset` | |
| 84 | + | ||
| 85 | + | An RDF dataset is a set of graphs, with one default graph and a set of named | |
| 86 | + | graphs. This type has the following fields: | |
| 87 | + | ||
| 88 | + | * **default-graph**: the default graph, an RDF graph | |
| 89 | + | * **named-graphs**: the list of named graphs, an alist where keys are names and | |
| 90 | + | values are graphs. | |
| 91 | + | ||
| 92 | + | #### **Scheme Datatype**: `rdf-triple` | |
| 93 | + | ||
| 94 | + | An RDF triple is a truth assertion that a subject is linked to an object by | |
| 95 | + | a certain predicate. This type has the following fields: | |
| 96 | + | ||
| 97 | + | * **subject**: The subject, which can be a blank node, an IRI, a datatype or | |
| 98 | + | a literal | |
| 99 | + | * **predicate**: The predicate, which can have the same type of values | |
| 100 | + | * **object**: The object, which can have the same type of values | |
| 101 | + | ||
| 102 | + | Note that the recommendation restricts the possible values for predicate | |
| 103 | + | further (it should not be a blank node for instance), but also introduces the | |
| 104 | + | notion of *generalized RDF*, which corresponds to our definition of a triple. | |
| 105 | + | This is useful for entailment. A valid RDF triple can still be represented with | |
| 106 | + | this datatype. | |
| 107 | + | ||
| 108 | + | #### **Scheme Datatype**: `rdf-literal` | |
| 109 | + | ||
| 110 | + | An RDF literal is the value of a node. This type has the following fields: | |
| 111 | + | ||
| 112 | + | * **lexical-form**: The lexical form of the literal, a unicode string. | |
| 113 | + | * **type**: The type of the literal. This can be either an IRI or an RDF | |
| 114 | + | datatype (described later). | |
| 115 | + | * **langtag**: An optional language tag. Note that when `langtag` is defined, | |
| 116 | + | the type is necessarily rdf:langString. | |
| 117 | + | ||
| 118 | + | Note that the `langtag` restriction only applies semantically. Operations on | |
| 119 | + | RDF graphs and datasets as implemented in this library do not check that it is | |
| 120 | + | well-formed. Parsers and producers will fail to execute when the type is not | |
| 121 | + | as expected though. | |
| 122 | + | ||
| 123 | + | #### **Scheme Procedure**: blank-node? node | |
| 124 | + | ||
| 125 | + | Returns wether a node is a blank node or not. Blank node representation is | |
| 126 | + | internal and should not be relied upon as it might change without prior | |
| 127 | + | notice. Two blank nodes can be compared for equality (or unequality) with | |
| 128 | + | `equal?`. Other procedures are not guaranteed to work on blank nodes. | |
| 129 | + | ||
| 130 | + | #### **Scheme Procedure**: rdf-graph? graph | |
| 131 | + | ||
| 132 | + | Returns whether a scheme value is an RDF graph. This does not check the | |
| 133 | + | consistency or validity of the graph, but merely that it is syntactically | |
| 134 | + | correct. | |
| 135 | + | ||
| 136 | + | ### RDF Datatypes | |
| 137 | + | ||
| 138 | + | Datatypes are used to add semantics to literals. The `(rdf rdf)` further defines | |
| 139 | + | them, as well as some base datatypes. | |
| 140 | + | ||
| 141 | + | #### **Scheme Datatype**: `rdf-datatype` | |
| 142 | + | ||
| 143 | + | This type has the following fields: | |
| 144 | + | ||
| 145 | + | * **iris**: A list of IRIs that represent this type | |
| 146 | + | * **description**: A string describing that datatype, usually taken from | |
| 147 | + | documentations or recommendations | |
| 148 | + | * **literal?**: A procedure to check whether a string is a literal of that type | |
| 149 | + | * **value?**: A procedure to check whether a value is of that type | |
| 150 | + | * **lexical->value**: A procedure to transform a valid literal into a value value | |
| 151 | + | * **value->lexical**: A procedure to transform a valid value into a valid literal | |
| 152 | + | ||
| 153 | + | Note that there might be more that one valid value or literal to transform into. | |
| 154 | + | The last two procedures will choose one canonical representation. | |
| 155 | + | ||
| 156 | + | The documentation does not refer to `value->lexical`. It is an addition of this | |
| 157 | + | implementation. | |
| 158 | + | ||
| 159 | + | #### **Scheme Datatype**: `rdf-vocabulary` | |
| 160 | + | ||
| 161 | + | A vocabulary is a collection of datatypes. This implementation also equips a | |
| 162 | + | vocabulary with utility functions. This type has the following fields: | |
| 163 | + | ||
| 164 | + | * **datatypes**: A list of RDF datatypes | |
| 165 | + | * **order**: A procedure that returns whether the first datatype's value space is | |
| 166 | + | included in the value space of the second (i.e. whether it is smaller). | |
| 167 | + | * **compatible?**: A procedure that returns whether the two datatypes passed as | |
| 168 | + | parameters are compatible, i. e. their value space is not disjoint. | |
| 169 | + | ||
| 170 | + | Compatibility is assumed to be total (it always answers for any pair of recognized | |
| 171 | + | datatype in the vocabulary). One of the consistency conditions of a graph is | |
| 172 | + | that when a node has multiple types, they must have at least one value in | |
| 173 | + | common (for instance, a node can be both an integer and a decimal, because | |
| 174 | + | integer values are both integers and decimals, but it cannot be a boolean and an | |
| 175 | + | integer). | |
| 176 | + | ||
| 177 | + | The type consistency of a node is mathematically expressed as the non-emptyness | |
| 178 | + | of the intersection of value spaces of all the types of the node. It is assumed | |
| 179 | + | in this implementation that, when all the types or two-by-two compatible, that | |
| 180 | + | intersection is not empty. This is not true in general, but works at least of | |
| 181 | + | the base vocabulary included in guile-rdf. | |
| 182 | + | ||
| 183 | + | **Help wanted**: if you can come up with a better algorithm, please share! | |
| 184 | + | ||
| 185 | + | #### Available Datatypes in `(rdf rdf) | |
| 186 | + | ||
| 187 | + | * rdf:langString | |
| 188 | + | * rdf:XMLLiteral | |
| 189 | + | ||
| 190 | + | #### Available Datatypes in `(rdf xsd)` | |
| 191 | + | ||
| 192 | + | When you import this module with `#:prefix xsd:`, you can easily use these | |
| 193 | + | literals with that prefix, in the same way you would write it in a concrete | |
| 194 | + | RDF document. For instance, the following is a valid triple: | |
| 195 | + | ||
| 196 | + | ```scheme | |
| 197 | + | (make-rdf-triple | |
| 198 | + | "http://example.org/a" | |
| 199 | + | "http://example.org/prop" | |
| 200 | + | (make-rdf-literal "10" xsd:integer #f)) | |
| 201 | + | ``` | |
| 202 | + | ||
| 203 | + | Representing (in turtle syntax): | |
| 204 | + | ||
| 205 | + | ``` | |
| 206 | + | @prefix xsd: http://www.w3.org/2001/XMLSchema# | |
| 207 | + | <http://example.org/a> <http://example.org/prop> "10"^^xsd:integer . | |
| 208 | + | ``` | |
| 209 | + | ||
| 210 | + | Available datatypes are: | |
| 211 | + | ||
| 212 | + | * xsd:boolean | |
| 213 | + | * xsd:string | |
| 214 | + | * xsd:decimal | |
| 215 | + | * xsd:integer | |
| 216 | + | * xsd:int | |
| 217 | + | ||
| 218 | + | ### Graph Operations | |
| 219 | + | ||
| 220 | + | The `(rdf rdf)` module also defines some graph operations. They are presented | |
| 221 | + | below. | |
| 222 | + | ||
| 223 | + | #### **Scheme Procedure**: `merge-graphs g1 g2` | |
| 224 | + | ||
| 225 | + | Merges two graphs. As graphs are collections of RDF triples, this is very | |
| 226 | + | similar to appending the two sets. However, we must ensure that we don't | |
| 227 | + | accidentaly merge blank node identifiers that should not be merged, as two | |
| 228 | + | distinct blank nodes can have the same internal representation in both graphs. | |
| 229 | + | ||
| 230 | + | #### **Scheme Procedure**: `rdf-isomorphic? g1 g2` | |
| 231 | + | ||
| 232 | + | Returns whether two graphs are the same. Two graphs can have a different | |
| 233 | + | representation because of order and because of differing blank node | |
| 234 | + | representations. For instance the following graphs (in turtle format) are | |
| 235 | + | isomorphic, even though their representation is different: | |
| 236 | + | ||
| 237 | + | ``` | |
| 238 | + | _:a1 <http://example.org> "10"^^<xsd:integer> | |
| 239 | + | ``` | |
| 240 | + | ||
| 241 | + | and | |
| 242 | + | ||
| 243 | + | ``` | |
| 244 | + | _:bn <http://example.org> "10"^^<xsd:integer> | |
| 245 | + | ``` | |
| 246 | + | ||
| 247 | + | However, the following is *not* isomorphic with any of the previous graphs: | |
| 248 | + | ||
| 249 | + | ``` | |
| 250 | + | _:a1 <http://example.org> "010"^^<xsd:integer> | |
| 251 | + | ``` | |
| 252 | + | ||
| 253 | + | Because the literal representation of `10` differs. | |
| 254 | + | ||
| 255 | + | #### **Scheme Procedure**: `recognize graph vocabulary` | |
| 256 | + | ||
| 257 | + | Transforms a graph to replace every instance of recognized IRIs in the | |
| 258 | + | vocabulary by an RDF datatype. | |
| 258 | < | ||
| 0 | 259 | < | \ No newline at end of file |