You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// rdfcanon implements the dataset canonicalization algorithm
24
+
import"github.com/dpb587/rdfkit-go/rdfcanon"
25
+
```
24
26
25
-
</details>
27
+
The [`examples` submodules](examples) demonstrates some common use cases and starter snippets.
26
28
27
-
<details><summary><code>examples$ go run <strong>./html-extract https://microsoft.com</strong></code></summary>
29
+
<details><summary><code>html-extract$ <strong>go run . https://microsoft.com</strong></code></summary>
28
30
29
31
```turtle
30
32
@base <https://www.microsoft.com/en-us/> .
@@ -56,6 +58,155 @@ _:b0
56
58
57
59
</details>
58
60
61
+
The [`cmd/rdfkit` submodule](cmd/rdfkit) offers command line access to some common tasks. Refer to its subpackages to learn more about their implementations.
62
+
63
+
<details><summary><code>rdfkit$ <strong>go run . --help</strong></code></summary>
64
+
65
+
```
66
+
Usage:
67
+
rdfkit [command]
68
+
69
+
Available Commands:
70
+
canonicalize Convert a dataset into canonical blank nodes and ordering
71
+
completion Generate the autocompletion script for the specified shell
72
+
export-dot Generate a Graphviz DOT visualization from an ontology
73
+
export-go-iri Generate a Go file of IRI constants from an ontology
74
+
help Help about any command
75
+
pipe Decode and re-encode using supported encoding formats
76
+
77
+
Flags:
78
+
-h, --help help for rdfkit
79
+
80
+
Use "rdfkit [command] --help" for more information about a command.
81
+
```
82
+
83
+
</details>
84
+
85
+
<details><summary><code>rdfkit$ <strong>go run . pipe --help</strong></code></summary>
86
+
87
+
```
88
+
Decode and re-encode using supported encoding formats
89
+
90
+
Usage:
91
+
rdfkit pipe [flags]
92
+
93
+
Flags:
94
+
-h, --help help for pipe
95
+
-i, --in string path or IRI for reading (default stdin)
96
+
--in-base string override the base IRI of the resource
97
+
--in-param stringArray extra decode configuration parameters (syntax "KEY[=VALUE]")
98
+
--in-param-io stringArray extra read configuration parameters (syntax "KEY[=VALUE]")
99
+
--in-type string name or alias for the decoder (default detect)
100
+
-o, --out string path or IRI for writing (default stdout)
101
+
--out-base string override the base IRI of the resource
102
+
--out-param stringArray extra encode configuration parameters (syntax "KEY[=VALUE]")
103
+
--out-param-io stringArray extra write configuration parameters (syntax "KEY[=VALUE]")
104
+
--out-type string name or alias for the encoder (default detect or nquads)
105
+
106
+
Encodings:
107
+
108
+
org.json-ld.document (decode)
109
+
110
+
Aliases: jsonld
111
+
File Extensions: .jsonld
112
+
Media Types: application/ld+json
113
+
114
+
--in-param captureTextOffsets[=bool]
115
+
Capture the line+column offsets for statement properties
116
+
117
+
--in-param tokenizer.lax[=bool]
118
+
Accept and recover common syntax errors
119
+
120
+
org.w3.n-quads (decode, encode)
121
+
122
+
Aliases: n-quads, nq, nquads
123
+
File Extensions: .nq
124
+
Media Types: application/n-quads
125
+
126
+
--in-param captureTextOffsets[=bool]
127
+
Capture the line+column offsets for statement properties
128
+
129
+
--out-param ascii[=bool]
130
+
Use escape sequences for non-ASCII characters
131
+
132
+
org.w3.n-triples (decode, encode)
133
+
134
+
Aliases: n-triples, nt, ntriples
135
+
File Extensions: .nt
136
+
Media Types: application/n-triples
137
+
138
+
--in-param captureTextOffsets[=bool]
139
+
Capture the line+column offsets for statement properties
140
+
141
+
--out-param ascii[=bool]
142
+
Use escape sequences for non-ASCII characters
143
+
144
+
org.w3.rdf-json (decode, encode)
145
+
146
+
Aliases: rdf-json, rdfjson, rj
147
+
File Extensions: .rj
148
+
Media Types: application/rdf+json
149
+
150
+
--in-param captureTextOffsets[=bool]
151
+
Capture the line+column offsets for statement properties
152
+
153
+
org.w3.rdf-xml (decode)
154
+
155
+
Aliases: rdf-xml, rdfxml, xml
156
+
File Extensions: .rdf
157
+
Media Types: application/rdf+xml
158
+
159
+
--in-param captureTextOffsets[=bool]
160
+
Capture the line+column offsets for statement properties
161
+
162
+
org.w3.trig (decode)
163
+
164
+
Aliases: trig
165
+
File Extensions: .trig
166
+
Media Types: application/trig
167
+
168
+
--in-param captureTextOffsets[=bool]
169
+
Capture the line+column offsets for statement properties
170
+
171
+
org.w3.turtle (decode, encode)
172
+
173
+
Aliases: ttl, turtle
174
+
File Extensions: .ttl
175
+
Media Types: text/turtle
176
+
177
+
--in-param captureTextOffsets[=bool]
178
+
Capture the line+column offsets for statement properties
179
+
180
+
--out-param buffered[=bool]
181
+
Load all statements into memory before writing any output
182
+
183
+
--out-param iris.useBase[=bool]
184
+
Prefer IRIs relative to the resource IRI
185
+
186
+
--out-param iris.usePrefix=string...
187
+
Prefer IRIs using a prefix. Use the syntax of "{prefix}:{iri}", "rdfa-context", or "none"
188
+
189
+
--out-param resources[=bool]
190
+
Write nested statements and resource descriptions (implies buffered=true)
191
+
192
+
public.html (decode)
193
+
194
+
Aliases: htm, html, xhtml
195
+
File Extensions: .htm, .html, .xhtml
196
+
Media Types: application/xhtml+xml, text/html, text/xhtml+xml
197
+
198
+
--in-param captureTextOffsets[=bool]
199
+
Capture the line+column offsets for statement properties
200
+
```
201
+
202
+
</details>
203
+
204
+
<details><summary><code>rdfkit$ <strong>go run . export-dot -i https://www.w3.org/2000/01/rdf-schema.ttl</strong> | dot -Tsvg</code></summary>
Based on the [Resource Description Framework](https://www.w3.org/TR/rdf11-concepts/) (RDF), there are three primitive value types, aka *terms*, that are used to represent data: *IRIs*, *literals*, and *blank nodes*. The primitive value types are the basis of *triples* and other assertions about information.
@@ -105,9 +256,10 @@ A *blank node* represents an anonymous resource and are always created with a un
105
256
106
257
```go
107
258
bnode:= rdf.NewBlankNode()
259
+
bnode.Identifier != rdf.NewBlankNode().Identifier
108
260
```
109
261
110
-
The [`blanknodeutil` package](rdf/blanknodeutil) provides additional support for using string-based identifiers (e.g. `b0`), mapping blank nodes from implementations, and scoped factories.
262
+
The [`blanknodes` package](rdf/blanknodes) provides additional support for using string-based identifiers (e.g. `b0`)and other utilities.
111
263
112
264
### Triple
113
265
@@ -121,19 +273,11 @@ nameTriple := rdf.Triple{
121
273
}
122
274
```
123
275
124
-
The fields of a triple are restricted to the normative value types they support, described by the table below.
125
-
126
-
| Field | IRI | Literal | Blank Node |
127
-
| ----- |:---:|:-------:|:----------:|
128
-
| Subject | Valid | Invalid | Valid |
129
-
| Predicate | Valid | Invalid | Invalid |
130
-
| Object | Valid | Valid | Valid |
131
-
132
-
The `rdf` package includes other supporting types (e.g. `TripleList`, `TripleIterator`, and `TripleMatcher`), and the [`triples` package](rdf/triples) offers additional interfaces and utilities for working with triple types.
276
+
The `rdf` package includes other supporting types (e.g. `TripleList`, `TripleIterator`, and `TripleMatcher`), and the [`triples` package](rdf/triples) offers additional interfaces and utilities for working with triples.
133
277
134
278
### Quad
135
279
136
-
A *quad* is used to describe a triple with an optional graph name. A graph name may be an IRI, Blank Node, or `nil` which indicates the default graph.
280
+
A *quad* is used to describe a triple with an optional graph name.
137
281
138
282
```go
139
283
nameQuad:= rdf.Quad{
@@ -142,7 +286,18 @@ nameQuad := rdf.Quad{
142
286
}
143
287
```
144
288
145
-
Similar to triples, the `rdf` and [`quads` package](rdf/quads) offers additional interfaces and utilities.
289
+
The `rdf` and [`quads` packages](rdf/quads) offer additional interfaces and utilities for working with quads.
290
+
291
+
### Property Values
292
+
293
+
The fields of triples and quads are restricted (with interfaces) to the normative value types they support, described by the table below. [Generalized RDF](https://www.w3.org/TR/rdf11-concepts/#section-generalized-rdf) values are not currently supported.
@@ -172,29 +327,25 @@ The [`inmemory` experimental package](x/storage/inmemory) offers a dataset imple
172
327
storage:= inmemory.NewDataset()
173
328
```
174
329
175
-
Better-supported storage or alternative, remote service clients will likely be a focus on the future.
330
+
Better-supported storage or alternative, remote service clients will likely be a focus in the future.
176
331
177
332
## Encodings
178
333
179
334
An *encoding* (or *file format*) is used to decode and encode RDF data. The following encodings are available under the [`encoding` package](encoding).
Some encodings do not yet support all syntactic features defined by their official specification, though they should cover common practices. Most are tested against some sort of test suite (such as the ones published by W3C), and the latest results can be found in their `testsuites/*/testresults` directory.
195
-
196
-
Broader support for encoders will likely be added in the future.
197
-
198
349
### Decoder
199
350
200
351
Encodings provide a `NewDecoder` function which require an `io.Reader` and optional `DecoderConfig` options. It can be used as an iterator for all statements found in the encoding. Depending on the capabilities of the encoding format, the decoder fulfills either the `encoding.TripleDecoder` or `encoding.QuadDecoder` interface.
@@ -238,7 +389,7 @@ for decoder.Next() {
238
389
239
390
When working with offsets, consider the following caveats.
240
391
241
-
* Capturing and processing text offsets comes with a slight impact to performance and memory.
392
+
* Capturing and processing text offsets impacts the performance and memory.
242
393
* Offsets for some properties may not always be available due to decoding limitations.
243
394
* Offsets for some properties may be "incomplete" due to stream processing. For example, `turtle` may only refer to the opening `[` token of an anonymous resource when the closing `]` token has not yet been read.
244
395
@@ -330,7 +481,7 @@ Once canonicalized, the encoded N-Quads form can be directly written to an `io.W
330
481
_, err:= canonicalized.WriteTo(os.Stdout)
331
482
```
332
483
333
-
Alternatively, use `NewIterator` to manually iterate over the results containing its encoded form. If the `BuildCanonicalQuad` option was enabled, use `NewQuadIterator` for a standard `rdf.QuadIterator` of quads including the canonicalized blank nodes.
484
+
Alternatively, use `NewIterator` to manually iterate over the results containing its encoded form. If the `BuildCanonicalQuad` option was enabled, use `NewQuadIterator` for a standard `rdf.QuadIterator` of quads with the canonical blank nodes.
@@ -423,17 +574,9 @@ ok && rIRI == "http://example.com/resource"
423
574
424
575
The [`rdfacontext` package](rdf/iriutil/rdfacontext/) provides a list of prefix mappings defined by the W3C at [RDFa Core Initial Context](https://www.w3.org/2011/rdfa-context/rdfa-1.1). This includes prefixes such as `owl:`, `rdfa:`, and `xsd:`. The list of widely-used prefixes is included as well, which includes prefixes such as `dc:` and `schema:`.
425
576
426
-
## Command Line
427
-
428
-
The `cmd/rdfkit` package offers a command line interface with a few utilities. Most notably:
429
-
430
-
*`irigen` - generate Go constants from an RDF vocabulary. Used internally for most of the `*iri` packages.
431
-
*`pipe` - decode local files or remote URLs, and then re-encode using any of the supported RDF formats.
432
-
433
577
## Notes
434
578
435
-
***RDF 1.2** (i.e. RDF-star) - not currently supported; waiting for more stability in the draft specification and definitions.
436
-
***Generalized RDF** - not currently supported; may be introduced in the future as a breaking change or via build tag.
579
+
***RDF 1.2** (i.e. RDF-star) - not currently supported; likely to add primitive type support soon, encodings later.
437
580
* This is a periodically updated fork based on private usage. There may still be some breaking changes before starting to version this module.
0 commit comments