gnarly 0.0.0.dev13__tar.gz → 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gnarly-0.1.1/.gitignore +6 -0
- gnarly-0.1.1/LICENSE +12 -0
- gnarly-0.1.1/PKG-INFO +249 -0
- gnarly-0.1.1/README.md +237 -0
- gnarly-0.1.1/gnarly/__init__.py +317 -0
- gnarly-0.1.1/gnarly/__main__.py +4 -0
- gnarly-0.1.1/gnarly/cli.py +126 -0
- gnarly-0.1.1/gnarly/jsonld.py +155 -0
- gnarly-0.1.1/gnarly/rdfxml.py +245 -0
- gnarly-0.1.1/gnarly/rq.py +38 -0
- gnarly-0.1.1/gnarly/trig.py +540 -0
- gnarly-0.1.1/pyproject.toml +31 -0
- gnarly-0.0.0.dev13/.gitignore +0 -10
- gnarly-0.0.0.dev13/.python-version +0 -1
- gnarly-0.0.0.dev13/PKG-INFO +0 -8
- gnarly-0.0.0.dev13/docs/Makefile +0 -20
- gnarly-0.0.0.dev13/docs/api/gnarly.rst +0 -45
- gnarly-0.0.0.dev13/docs/api/gnarly.utils.code.rst +0 -21
- gnarly-0.0.0.dev13/docs/api/gnarly.utils.llm.rst +0 -45
- gnarly-0.0.0.dev13/docs/api/gnarly.utils.rst +0 -30
- gnarly-0.0.0.dev13/docs/api/modules.rst +0 -7
- gnarly-0.0.0.dev13/docs/make.bat +0 -35
- gnarly-0.0.0.dev13/docs/source/api/gnarly.rst +0 -45
- gnarly-0.0.0.dev13/docs/source/api/gnarly.utils.code.rst +0 -21
- gnarly-0.0.0.dev13/docs/source/api/gnarly.utils.llm.rst +0 -45
- gnarly-0.0.0.dev13/docs/source/api/gnarly.utils.rst +0 -30
- gnarly-0.0.0.dev13/docs/source/api/modules.rst +0 -7
- gnarly-0.0.0.dev13/docs/source/api.md +0 -29
- gnarly-0.0.0.dev13/docs/source/conf.py +0 -84
- gnarly-0.0.0.dev13/docs/source/index.md +0 -15
- gnarly-0.0.0.dev13/docs/source/usage.md +0 -11
- gnarly-0.0.0.dev13/pyproject.toml +0 -23
- gnarly-0.0.0.dev13/src/gnarly/__init__.py +0 -53
- gnarly-0.0.0.dev13/src/gnarly/constants.py +0 -82
- gnarly-0.0.0.dev13/src/gnarly/errors.py +0 -29
- gnarly-0.0.0.dev13/src/gnarly/types.py +0 -100
- gnarly-0.0.0.dev13/src/gnarly/utils/__init__.py +0 -44
- gnarly-0.0.0.dev13/src/gnarly/utils/code/__init__.py +0 -33
- gnarly-0.0.0.dev13/src/gnarly/utils/code/projects.py +0 -218
- gnarly-0.0.0.dev13/src/gnarly/utils/io.py +0 -202
- gnarly-0.0.0.dev13/src/gnarly/utils/llm/__init__.py +0 -22
- gnarly-0.0.0.dev13/src/gnarly/utils/llm/chatgpt.py +0 -93
- gnarly-0.0.0.dev13/src/gnarly/utils/llm/claude.py +0 -98
- gnarly-0.0.0.dev13/src/gnarly/utils/llm/interfaces.py +0 -485
- gnarly-0.0.0.dev13/src/gnarly/utils/llm/models.py +0 -285
- gnarly-0.0.0.dev13/tests/__init__.py +0 -0
- gnarly-0.0.0.dev13/tests/test_constants.py +0 -27
- gnarly-0.0.0.dev13/tests/test_io_utilities.py +0 -22
- gnarly-0.0.0.dev13/uv.lock +0 -80
- /gnarly-0.0.0.dev13/README.md → /gnarly-0.1.1/gnarly/py.typed +0 -0
gnarly-0.1.1/.gitignore
ADDED
gnarly-0.1.1/LICENSE
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
BSD Zero Clause License (0BSD)
|
|
2
|
+
|
|
3
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
4
|
+
purpose with or without fee is hereby granted.
|
|
5
|
+
|
|
6
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
7
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
8
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
9
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
10
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
11
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
12
|
+
PERFORMANCE OF THIS SOFTWARE.
|
gnarly-0.1.1/PKG-INFO
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: gnarly
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: RDF 1.2 pretty-printer.
|
|
5
|
+
Project-URL: repository, https://github.com/niklasl/gnarly
|
|
6
|
+
Author-email: Niklas Lindström <lindstream@gmail.com>
|
|
7
|
+
License-Expression: 0BSD
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Python: >=3.13
|
|
10
|
+
Requires-Dist: pyoxigraph<2,>=0.5.11
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
|
|
13
|
+
# Gnarly
|
|
14
|
+
|
|
15
|
+
Gnarly is a pretty-printer for [RDF 1.2](https://www.w3.org/TR/rdf12-concepts/), used for serializing [Turtle](https://www.w3.org/TR/rdf12-turtle/), [TriG](https://www.w3.org/TR/rdf12-trig/), and related RDF syntaxes.
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
Install from source or PyPI (e.g. using `pip`). Gnarly is written in [Python](https://www.python.org/) and uses [pyoxigraph](https://pyoxigraph.readthedocs.io/) for parsing RDF.
|
|
20
|
+
|
|
21
|
+
Pass files or pipe to the CLI:
|
|
22
|
+
|
|
23
|
+
$ gnarly test/data/test-gnarly.trig
|
|
24
|
+
|
|
25
|
+
(See `gnarly -h` for all options.)
|
|
26
|
+
|
|
27
|
+
## Pretty-Printing Turtle/TriG
|
|
28
|
+
|
|
29
|
+
By default, Turtle/TriG is written with the following features:
|
|
30
|
+
|
|
31
|
+
- Uses given prefixes to compact IRIs into PNames,
|
|
32
|
+
- optional base IRI to shorten IRIs;
|
|
33
|
+
- group descriptions by subject,
|
|
34
|
+
- writes types first, on subject line if short enough, then
|
|
35
|
+
- predicates separated by semicolon, and
|
|
36
|
+
- multiple objects, separated by comma; with support for
|
|
37
|
+
- nested blank nodes,
|
|
38
|
+
- compact lists (with one line per item for longer values),
|
|
39
|
+
- boolean keywords, pure floats and doubles, and compact triple terms;
|
|
40
|
+
- compact forms of reifiers (including multiple and named reifiers), and
|
|
41
|
+
- compact annotations on asserted triples (including multiple and named annotations);
|
|
42
|
+
- takes multiple references into account and avoids blank node cycles.
|
|
43
|
+
|
|
44
|
+
### Example Output
|
|
45
|
+
```turtle
|
|
46
|
+
prefix : <https://example.net/ns/>
|
|
47
|
+
prefix ctg: <https://example.net/ns/category/>
|
|
48
|
+
|
|
49
|
+
<https://example.org/a> a :Thing ;
|
|
50
|
+
:category ctg:CommonThings ;
|
|
51
|
+
:name "A" ;
|
|
52
|
+
:references <https://example.org/b> ,
|
|
53
|
+
<https://example.org/c> ;
|
|
54
|
+
:value 1 ,
|
|
55
|
+
"a" .
|
|
56
|
+
|
|
57
|
+
<https://example.org/b> a :Thing ;
|
|
58
|
+
:category ctg:Regular ;
|
|
59
|
+
:references [ a :Thing ;
|
|
60
|
+
:name "C" ;
|
|
61
|
+
:references [
|
|
62
|
+
:category ctg:Special ;
|
|
63
|
+
:name "D" ;
|
|
64
|
+
:references [ :name "E" ]
|
|
65
|
+
]
|
|
66
|
+
] .
|
|
67
|
+
|
|
68
|
+
<https://example.org/c>
|
|
69
|
+
:items ( <https://example.org/b> <https://example.org/c> ) ;
|
|
70
|
+
:referenceList (
|
|
71
|
+
<https://example.org/b>
|
|
72
|
+
<https://example.org/c>
|
|
73
|
+
<https://example.org/d>
|
|
74
|
+
<https://example.org/e>
|
|
75
|
+
) ;
|
|
76
|
+
:valueList ( 1 "a" ) .
|
|
77
|
+
|
|
78
|
+
<https://example.org/d> :references <https://example.org/c> .
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Formatting Options
|
|
82
|
+
|
|
83
|
+
There are different style conventions for Turtle/TriG. Gnarly has options to tweak some things to adhere to different preferences.
|
|
84
|
+
|
|
85
|
+
The default settings are:
|
|
86
|
+
- Indent: 2 spaces
|
|
87
|
+
- Max column: 88 characters
|
|
88
|
+
|
|
89
|
+
There are three named styles, exemplified here with differences in output:
|
|
90
|
+
|
|
91
|
+
#### Modern
|
|
92
|
+
|
|
93
|
+
This is the default, described above.
|
|
94
|
+
```turtle
|
|
95
|
+
prefix : <https://example.net/ns/>
|
|
96
|
+
|
|
97
|
+
<https://example.org/a> a :Thing ;
|
|
98
|
+
:references <https://example.org/b> ,
|
|
99
|
+
[ a :Thing ;
|
|
100
|
+
:name "C" ;
|
|
101
|
+
:references [
|
|
102
|
+
:name "D" ;
|
|
103
|
+
:references [ :name "E" ]
|
|
104
|
+
]
|
|
105
|
+
] ;
|
|
106
|
+
:value 1 ,
|
|
107
|
+
"a" .
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
#### Classic
|
|
111
|
+
|
|
112
|
+
This form is more compact, but at the expense of readability for deeply nested blank nodes, and/or annotations. It also uses the classic, `@`-sigil for prefix and base, no explicit graph keyword, and no padding space before `;`, `,`, and `.` separators.
|
|
113
|
+
```turtle
|
|
114
|
+
@prefix : <https://example.net/ns/>.
|
|
115
|
+
|
|
116
|
+
<https://example.org/a> a :Thing;
|
|
117
|
+
:references <https://example.org/b>,
|
|
118
|
+
[ a :Thing;
|
|
119
|
+
:name "C";
|
|
120
|
+
:references [
|
|
121
|
+
:name "D";
|
|
122
|
+
:references [ :name "E" ] ] ];
|
|
123
|
+
:value 1,
|
|
124
|
+
"a".
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
#### Longhand
|
|
128
|
+
|
|
129
|
+
Puts predicates, including types, on new lines, and ends all statement lines with semicolon; ending a subject description with a period on its own line. Uses uppercase SPARQL keywords.
|
|
130
|
+
|
|
131
|
+
This style is useful for rapid copy&paste editing and line-based diffs:
|
|
132
|
+
```turtle
|
|
133
|
+
PREFIX : <https://example.net/ns/>
|
|
134
|
+
|
|
135
|
+
<https://example.org/a>
|
|
136
|
+
a :Thing ;
|
|
137
|
+
:references <https://example.org/b> ;
|
|
138
|
+
:references [
|
|
139
|
+
a :Thing ;
|
|
140
|
+
:name "C" ;
|
|
141
|
+
:references [
|
|
142
|
+
:name "D" ;
|
|
143
|
+
:references [ :name "E" ] ;
|
|
144
|
+
] ;
|
|
145
|
+
] ;
|
|
146
|
+
:value 1 ;
|
|
147
|
+
:value "a" ;
|
|
148
|
+
.
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Detailed Formatting
|
|
152
|
+
|
|
153
|
+
The following examples are serialized using the default formatting options. (Many are variations on examples in the main [RDF 1.2 Primer](https://www.w3.org/TR/rdf12-primer/).)
|
|
154
|
+
|
|
155
|
+
`#` Prefixes are sorted, and declared using *lowercase* SPARQL-style syntax by default:
|
|
156
|
+
```turtle
|
|
157
|
+
prefix : <http://example.net/ns/>
|
|
158
|
+
prefix dcterms: <http://purl.org/dc/terms/>
|
|
159
|
+
prefix foaf: <http://xmlns.com/foaf/0.1/>
|
|
160
|
+
prefix lio: <http://purl.org/net/lio#>
|
|
161
|
+
prefix prov: <http://www.w3.org/ns/prov#>
|
|
162
|
+
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
|
|
163
|
+
prefix wd: <http://www.wikidata.org/entity/>
|
|
164
|
+
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
|
|
165
|
+
```
|
|
166
|
+
`#` Types are written on the subject line:
|
|
167
|
+
```turtle
|
|
168
|
+
<http://example.org/bob#me> a foaf:Person ;
|
|
169
|
+
foaf:birthday "1990-07-04"^^xsd:date ;
|
|
170
|
+
foaf:knows <http://example.org/alice#me> .
|
|
171
|
+
```
|
|
172
|
+
`#` Multiple triples are written under the subject:
|
|
173
|
+
```turtle
|
|
174
|
+
wd:Q12418
|
|
175
|
+
dcterms:creator <http://dbpedia.org/resource/Leonardo_da_Vinci> ;
|
|
176
|
+
dcterms:title "Mona Lisa" .
|
|
177
|
+
```
|
|
178
|
+
`#` Single statements and simple embedded blank nodes are kept on one line:
|
|
179
|
+
```turtle
|
|
180
|
+
wd:Q12418 dcterms:creator <http://dbpedia.org/resource/Leonardo_da_Vinci> .
|
|
181
|
+
|
|
182
|
+
wd:Q12418 lio:shows [ a <http://dbpedia.org/resource/Cypress> ] .
|
|
183
|
+
```
|
|
184
|
+
`#` Long lines also result in line breaks:
|
|
185
|
+
```turtle
|
|
186
|
+
<http://data.europeana.eu/item/04802/243FA8618938F4117025F17A8B813C5F9AA4D619>
|
|
187
|
+
dcterms:subject wd:Q12418 .
|
|
188
|
+
|
|
189
|
+
<http://dbpedia.org/resource/Mona_Lisa> lio:shows [
|
|
190
|
+
a <http://dbpedia.org/resource/Cypress> ] .
|
|
191
|
+
```
|
|
192
|
+
`#` A single blank annotation is written as:
|
|
193
|
+
```turtle
|
|
194
|
+
<http://example.org/bob#me> a foaf:Person ;
|
|
195
|
+
foaf:topic_interest wd:Q12418 {| a rdf:Statement ;
|
|
196
|
+
dcterms:creator <http://example.org/alice#me> ;
|
|
197
|
+
dcterms:date "2004-01-12"^^xsd:date
|
|
198
|
+
|} .
|
|
199
|
+
```
|
|
200
|
+
`#` and a named annotation like:
|
|
201
|
+
```turtle
|
|
202
|
+
<http://example.org/bob#me> a foaf:Person ;
|
|
203
|
+
foaf:topic_interest wd:Q12418 ~ <http://example.org/alice#claim-1> .
|
|
204
|
+
```
|
|
205
|
+
`#` Multiple annotations are written beneath the statement:
|
|
206
|
+
```turtle
|
|
207
|
+
<http://example.org/bob#me> a foaf:Person ;
|
|
208
|
+
foaf:topic_interest wd:Q12418
|
|
209
|
+
{| a rdf:Statement ;
|
|
210
|
+
dcterms:creator <http://example.org/alice#me> ;
|
|
211
|
+
dcterms:date "2004-01-12"^^xsd:date
|
|
212
|
+
|}
|
|
213
|
+
{| a prov:Influence ;
|
|
214
|
+
dcterms:date "1998-10-04"^^xsd:date
|
|
215
|
+
|} .
|
|
216
|
+
```
|
|
217
|
+
`#` As are multiple named annotations:
|
|
218
|
+
```turtle
|
|
219
|
+
<http://example.org/bob#me> a foaf:Person ;
|
|
220
|
+
foaf:topic_interest wd:Q12418
|
|
221
|
+
~ <http://example.org/alice#claim-1>
|
|
222
|
+
~ <http://example.org/bob#interest-1> .
|
|
223
|
+
|
|
224
|
+
<http://example.org/alice#claim-1> a rdf:Statement ;
|
|
225
|
+
dcterms:creator <http://example.org/alice#me> ;
|
|
226
|
+
dcterms:date "2004-01-12"^^xsd:date .
|
|
227
|
+
|
|
228
|
+
<http://example.org/bob#interest-1> a prov:Influence ;
|
|
229
|
+
dcterms:date "1998-10-04"^^xsd:date .
|
|
230
|
+
```
|
|
231
|
+
`#` As shown in the example output above, lists are written on one or multiple lines, depending on resulting width:
|
|
232
|
+
```turtle
|
|
233
|
+
<https://example.org/c>
|
|
234
|
+
:items ( <https://example.org/b> <https://example.org/c> ) ;
|
|
235
|
+
:referenceList (
|
|
236
|
+
<https://example.org/b>
|
|
237
|
+
<https://example.org/c>
|
|
238
|
+
<https://example.org/d>
|
|
239
|
+
<https://example.org/e>
|
|
240
|
+
) ;
|
|
241
|
+
:valueList ( 1 "a" [ :value "b" ] ) .
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## Maintenance
|
|
245
|
+
|
|
246
|
+
Simple round-trip run of local examples, and (optionally) the official RDF Turtle/TriG tests:
|
|
247
|
+
|
|
248
|
+
$ ./test.sh clone/of/w3c/rdf-tests # from <https://github.com/w3c/rdf-tests>
|
|
249
|
+
|
gnarly-0.1.1/README.md
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
# Gnarly
|
|
2
|
+
|
|
3
|
+
Gnarly is a pretty-printer for [RDF 1.2](https://www.w3.org/TR/rdf12-concepts/), used for serializing [Turtle](https://www.w3.org/TR/rdf12-turtle/), [TriG](https://www.w3.org/TR/rdf12-trig/), and related RDF syntaxes.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
Install from source or PyPI (e.g. using `pip`). Gnarly is written in [Python](https://www.python.org/) and uses [pyoxigraph](https://pyoxigraph.readthedocs.io/) for parsing RDF.
|
|
8
|
+
|
|
9
|
+
Pass files or pipe to the CLI:
|
|
10
|
+
|
|
11
|
+
$ gnarly test/data/test-gnarly.trig
|
|
12
|
+
|
|
13
|
+
(See `gnarly -h` for all options.)
|
|
14
|
+
|
|
15
|
+
## Pretty-Printing Turtle/TriG
|
|
16
|
+
|
|
17
|
+
By default, Turtle/TriG is written with the following features:
|
|
18
|
+
|
|
19
|
+
- Uses given prefixes to compact IRIs into PNames,
|
|
20
|
+
- optional base IRI to shorten IRIs;
|
|
21
|
+
- group descriptions by subject,
|
|
22
|
+
- writes types first, on subject line if short enough, then
|
|
23
|
+
- predicates separated by semicolon, and
|
|
24
|
+
- multiple objects, separated by comma; with support for
|
|
25
|
+
- nested blank nodes,
|
|
26
|
+
- compact lists (with one line per item for longer values),
|
|
27
|
+
- boolean keywords, pure floats and doubles, and compact triple terms;
|
|
28
|
+
- compact forms of reifiers (including multiple and named reifiers), and
|
|
29
|
+
- compact annotations on asserted triples (including multiple and named annotations);
|
|
30
|
+
- takes multiple references into account and avoids blank node cycles.
|
|
31
|
+
|
|
32
|
+
### Example Output
|
|
33
|
+
```turtle
|
|
34
|
+
prefix : <https://example.net/ns/>
|
|
35
|
+
prefix ctg: <https://example.net/ns/category/>
|
|
36
|
+
|
|
37
|
+
<https://example.org/a> a :Thing ;
|
|
38
|
+
:category ctg:CommonThings ;
|
|
39
|
+
:name "A" ;
|
|
40
|
+
:references <https://example.org/b> ,
|
|
41
|
+
<https://example.org/c> ;
|
|
42
|
+
:value 1 ,
|
|
43
|
+
"a" .
|
|
44
|
+
|
|
45
|
+
<https://example.org/b> a :Thing ;
|
|
46
|
+
:category ctg:Regular ;
|
|
47
|
+
:references [ a :Thing ;
|
|
48
|
+
:name "C" ;
|
|
49
|
+
:references [
|
|
50
|
+
:category ctg:Special ;
|
|
51
|
+
:name "D" ;
|
|
52
|
+
:references [ :name "E" ]
|
|
53
|
+
]
|
|
54
|
+
] .
|
|
55
|
+
|
|
56
|
+
<https://example.org/c>
|
|
57
|
+
:items ( <https://example.org/b> <https://example.org/c> ) ;
|
|
58
|
+
:referenceList (
|
|
59
|
+
<https://example.org/b>
|
|
60
|
+
<https://example.org/c>
|
|
61
|
+
<https://example.org/d>
|
|
62
|
+
<https://example.org/e>
|
|
63
|
+
) ;
|
|
64
|
+
:valueList ( 1 "a" ) .
|
|
65
|
+
|
|
66
|
+
<https://example.org/d> :references <https://example.org/c> .
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Formatting Options
|
|
70
|
+
|
|
71
|
+
There are different style conventions for Turtle/TriG. Gnarly has options to tweak some things to adhere to different preferences.
|
|
72
|
+
|
|
73
|
+
The default settings are:
|
|
74
|
+
- Indent: 2 spaces
|
|
75
|
+
- Max column: 88 characters
|
|
76
|
+
|
|
77
|
+
There are three named styles, exemplified here with differences in output:
|
|
78
|
+
|
|
79
|
+
#### Modern
|
|
80
|
+
|
|
81
|
+
This is the default, described above.
|
|
82
|
+
```turtle
|
|
83
|
+
prefix : <https://example.net/ns/>
|
|
84
|
+
|
|
85
|
+
<https://example.org/a> a :Thing ;
|
|
86
|
+
:references <https://example.org/b> ,
|
|
87
|
+
[ a :Thing ;
|
|
88
|
+
:name "C" ;
|
|
89
|
+
:references [
|
|
90
|
+
:name "D" ;
|
|
91
|
+
:references [ :name "E" ]
|
|
92
|
+
]
|
|
93
|
+
] ;
|
|
94
|
+
:value 1 ,
|
|
95
|
+
"a" .
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
#### Classic
|
|
99
|
+
|
|
100
|
+
This form is more compact, but at the expense of readability for deeply nested blank nodes, and/or annotations. It also uses the classic, `@`-sigil for prefix and base, no explicit graph keyword, and no padding space before `;`, `,`, and `.` separators.
|
|
101
|
+
```turtle
|
|
102
|
+
@prefix : <https://example.net/ns/>.
|
|
103
|
+
|
|
104
|
+
<https://example.org/a> a :Thing;
|
|
105
|
+
:references <https://example.org/b>,
|
|
106
|
+
[ a :Thing;
|
|
107
|
+
:name "C";
|
|
108
|
+
:references [
|
|
109
|
+
:name "D";
|
|
110
|
+
:references [ :name "E" ] ] ];
|
|
111
|
+
:value 1,
|
|
112
|
+
"a".
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
#### Longhand
|
|
116
|
+
|
|
117
|
+
Puts predicates, including types, on new lines, and ends all statement lines with semicolon; ending a subject description with a period on its own line. Uses uppercase SPARQL keywords.
|
|
118
|
+
|
|
119
|
+
This style is useful for rapid copy&paste editing and line-based diffs:
|
|
120
|
+
```turtle
|
|
121
|
+
PREFIX : <https://example.net/ns/>
|
|
122
|
+
|
|
123
|
+
<https://example.org/a>
|
|
124
|
+
a :Thing ;
|
|
125
|
+
:references <https://example.org/b> ;
|
|
126
|
+
:references [
|
|
127
|
+
a :Thing ;
|
|
128
|
+
:name "C" ;
|
|
129
|
+
:references [
|
|
130
|
+
:name "D" ;
|
|
131
|
+
:references [ :name "E" ] ;
|
|
132
|
+
] ;
|
|
133
|
+
] ;
|
|
134
|
+
:value 1 ;
|
|
135
|
+
:value "a" ;
|
|
136
|
+
.
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Detailed Formatting
|
|
140
|
+
|
|
141
|
+
The following examples are serialized using the default formatting options. (Many are variations on examples in the main [RDF 1.2 Primer](https://www.w3.org/TR/rdf12-primer/).)
|
|
142
|
+
|
|
143
|
+
`#` Prefixes are sorted, and declared using *lowercase* SPARQL-style syntax by default:
|
|
144
|
+
```turtle
|
|
145
|
+
prefix : <http://example.net/ns/>
|
|
146
|
+
prefix dcterms: <http://purl.org/dc/terms/>
|
|
147
|
+
prefix foaf: <http://xmlns.com/foaf/0.1/>
|
|
148
|
+
prefix lio: <http://purl.org/net/lio#>
|
|
149
|
+
prefix prov: <http://www.w3.org/ns/prov#>
|
|
150
|
+
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
|
|
151
|
+
prefix wd: <http://www.wikidata.org/entity/>
|
|
152
|
+
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
|
|
153
|
+
```
|
|
154
|
+
`#` Types are written on the subject line:
|
|
155
|
+
```turtle
|
|
156
|
+
<http://example.org/bob#me> a foaf:Person ;
|
|
157
|
+
foaf:birthday "1990-07-04"^^xsd:date ;
|
|
158
|
+
foaf:knows <http://example.org/alice#me> .
|
|
159
|
+
```
|
|
160
|
+
`#` Multiple triples are written under the subject:
|
|
161
|
+
```turtle
|
|
162
|
+
wd:Q12418
|
|
163
|
+
dcterms:creator <http://dbpedia.org/resource/Leonardo_da_Vinci> ;
|
|
164
|
+
dcterms:title "Mona Lisa" .
|
|
165
|
+
```
|
|
166
|
+
`#` Single statements and simple embedded blank nodes are kept on one line:
|
|
167
|
+
```turtle
|
|
168
|
+
wd:Q12418 dcterms:creator <http://dbpedia.org/resource/Leonardo_da_Vinci> .
|
|
169
|
+
|
|
170
|
+
wd:Q12418 lio:shows [ a <http://dbpedia.org/resource/Cypress> ] .
|
|
171
|
+
```
|
|
172
|
+
`#` Long lines also result in line breaks:
|
|
173
|
+
```turtle
|
|
174
|
+
<http://data.europeana.eu/item/04802/243FA8618938F4117025F17A8B813C5F9AA4D619>
|
|
175
|
+
dcterms:subject wd:Q12418 .
|
|
176
|
+
|
|
177
|
+
<http://dbpedia.org/resource/Mona_Lisa> lio:shows [
|
|
178
|
+
a <http://dbpedia.org/resource/Cypress> ] .
|
|
179
|
+
```
|
|
180
|
+
`#` A single blank annotation is written as:
|
|
181
|
+
```turtle
|
|
182
|
+
<http://example.org/bob#me> a foaf:Person ;
|
|
183
|
+
foaf:topic_interest wd:Q12418 {| a rdf:Statement ;
|
|
184
|
+
dcterms:creator <http://example.org/alice#me> ;
|
|
185
|
+
dcterms:date "2004-01-12"^^xsd:date
|
|
186
|
+
|} .
|
|
187
|
+
```
|
|
188
|
+
`#` and a named annotation like:
|
|
189
|
+
```turtle
|
|
190
|
+
<http://example.org/bob#me> a foaf:Person ;
|
|
191
|
+
foaf:topic_interest wd:Q12418 ~ <http://example.org/alice#claim-1> .
|
|
192
|
+
```
|
|
193
|
+
`#` Multiple annotations are written beneath the statement:
|
|
194
|
+
```turtle
|
|
195
|
+
<http://example.org/bob#me> a foaf:Person ;
|
|
196
|
+
foaf:topic_interest wd:Q12418
|
|
197
|
+
{| a rdf:Statement ;
|
|
198
|
+
dcterms:creator <http://example.org/alice#me> ;
|
|
199
|
+
dcterms:date "2004-01-12"^^xsd:date
|
|
200
|
+
|}
|
|
201
|
+
{| a prov:Influence ;
|
|
202
|
+
dcterms:date "1998-10-04"^^xsd:date
|
|
203
|
+
|} .
|
|
204
|
+
```
|
|
205
|
+
`#` As are multiple named annotations:
|
|
206
|
+
```turtle
|
|
207
|
+
<http://example.org/bob#me> a foaf:Person ;
|
|
208
|
+
foaf:topic_interest wd:Q12418
|
|
209
|
+
~ <http://example.org/alice#claim-1>
|
|
210
|
+
~ <http://example.org/bob#interest-1> .
|
|
211
|
+
|
|
212
|
+
<http://example.org/alice#claim-1> a rdf:Statement ;
|
|
213
|
+
dcterms:creator <http://example.org/alice#me> ;
|
|
214
|
+
dcterms:date "2004-01-12"^^xsd:date .
|
|
215
|
+
|
|
216
|
+
<http://example.org/bob#interest-1> a prov:Influence ;
|
|
217
|
+
dcterms:date "1998-10-04"^^xsd:date .
|
|
218
|
+
```
|
|
219
|
+
`#` As shown in the example output above, lists are written on one or multiple lines, depending on resulting width:
|
|
220
|
+
```turtle
|
|
221
|
+
<https://example.org/c>
|
|
222
|
+
:items ( <https://example.org/b> <https://example.org/c> ) ;
|
|
223
|
+
:referenceList (
|
|
224
|
+
<https://example.org/b>
|
|
225
|
+
<https://example.org/c>
|
|
226
|
+
<https://example.org/d>
|
|
227
|
+
<https://example.org/e>
|
|
228
|
+
) ;
|
|
229
|
+
:valueList ( 1 "a" [ :value "b" ] ) .
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## Maintenance
|
|
233
|
+
|
|
234
|
+
Simple round-trip run of local examples, and (optionally) the official RDF Turtle/TriG tests:
|
|
235
|
+
|
|
236
|
+
$ ./test.sh clone/of/w3c/rdf-tests # from <https://github.com/w3c/rdf-tests>
|
|
237
|
+
|