Skip to content

Commit 0c16362

Browse files
fix namespace prefixes in longturtle serialization (#3134)
Co-authored-by: Daan de Schepper <[email protected]>
1 parent 95eda41 commit 0c16362

File tree

3 files changed

+49
-45
lines changed

3 files changed

+49
-45
lines changed

rdflib/plugins/serializers/longturtle.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class LongTurtleSerializer(RecursiveSerializer):
4444

4545
def __init__(self, store):
4646
self._ns_rewrite = {}
47+
namespace_manager = store.namespace_manager
4748
store = to_canonical_graph(store)
4849
content = store.serialize(format="application/n-triples")
4950
lines = content.split("\n")
@@ -53,6 +54,7 @@ def __init__(self, store):
5354
data="\n".join(lines), format="application/n-triples", skolemize=True
5455
)
5556
graph = graph.de_skolemize()
57+
graph.namespace_manager = namespace_manager
5658
super(LongTurtleSerializer, self).__init__(graph)
5759
self.keywords = {RDF.type: "a"}
5860
self.reset()
Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,74 @@
1+
PREFIX cn: <https://linked.data.gov.au/def/cn/>
2+
PREFIX ex: <http://example.com/>
13
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
24
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
3-
PREFIX schema: <https://schema.org/>
5+
PREFIX sdo: <https://schema.org/>
46
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
57

6-
<http://example.com/nicholas>
7-
a schema:Person ;
8-
schema:age 41 ;
9-
schema:alternateName
8+
ex:nicholas
9+
a sdo:Person ;
10+
sdo:age 41 ;
11+
sdo:alternateName
1012
[
11-
schema:name "Dr N.J. Car" ;
13+
sdo:name "Dr N.J. Car" ;
1214
] ,
1315
"N.J. Car" ,
1416
"Nick Car" ;
15-
schema:name
17+
sdo:name
1618
[
17-
a <https://linked.data.gov.au/def/cn/CompoundName> ;
18-
schema:hasPart
19+
a cn:CompoundName ;
20+
sdo:hasPart
1921
[
20-
a <https://linked.data.gov.au/def/cn/CompoundName> ;
21-
schema:hasPart
22+
a cn:CompoundName ;
23+
sdo:hasPart
2224
[
23-
a <https://linked.data.gov.au/def/cn/CompoundName> ;
25+
a cn:CompoundName ;
2426
rdf:value "Car" ;
2527
] ,
2628
[
27-
a <https://linked.data.gov.au/def/cn/CompoundName> ;
29+
a cn:CompoundName ;
2830
rdf:value "Maxov" ;
2931
] ;
3032
] ,
3133
[
32-
a <https://linked.data.gov.au/def/cn/CompoundName> ;
34+
a cn:CompoundName ;
3335
rdf:value "Nicholas" ;
3436
] ,
3537
[
36-
a <https://linked.data.gov.au/def/cn/CompoundName> ;
38+
a cn:CompoundName ;
3739
rdf:value "John" ;
3840
] ;
3941
] ;
40-
schema:worksFor <https://kurrawong.ai> ;
42+
sdo:worksFor <https://kurrawong.ai> ;
4143
.
4244

4345
<https://kurrawong.ai>
44-
a schema:Organization ;
45-
schema:location <https://kurrawong.ai/hq> ;
46+
a sdo:Organization ;
47+
sdo:location <https://kurrawong.ai/hq> ;
4648
.
4749

4850
<https://kurrawong.ai/hq>
49-
a schema:Place ;
50-
schema:address
51+
a sdo:Place ;
52+
sdo:address
5153
[
52-
a schema:PostalAddress ;
53-
schema:addressCountry
54+
a sdo:PostalAddress ;
55+
sdo:addressCountry
5456
[
55-
schema:identifier "au" ;
56-
schema:name "Australia" ;
57+
sdo:identifier "au" ;
58+
sdo:name "Australia" ;
5759
] ;
58-
schema:addressLocality "Shorncliffe" ;
59-
schema:addressRegion "QLD" ;
60-
schema:postalCode 4017 ;
61-
schema:streetAddress (
60+
sdo:addressLocality "Shorncliffe" ;
61+
sdo:addressRegion "QLD" ;
62+
sdo:postalCode 4017 ;
63+
sdo:streetAddress (
6264
72
6365
"Yundah"
6466
"Street"
6567
) ;
6668
] ;
67-
schema:geo
69+
sdo:geo
6870
[
69-
schema:polygon "POLYGON((153.082403 -27.325801, 153.08241 -27.32582, 153.082943 -27.325612, 153.083010 -27.325742, 153.083543 -27.325521, 153.083456 -27.325365, 153.082403 -27.325801))"^^geo:wktLiteral ;
71+
sdo:polygon "POLYGON((153.082403 -27.325801, 153.08241 -27.32582, 153.082943 -27.325612, 153.083010 -27.325742, 153.083543 -27.325521, 153.083456 -27.325365, 153.082403 -27.325801))"^^geo:wktLiteral ;
7072
] ;
71-
schema:name "KurrawongAI HQ" ;
73+
sdo:name "KurrawongAI HQ" ;
7274
.

test/test_serializers/test_serializer_longturtle_sort.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,48 +69,48 @@ def test_sort_semiblank_graph() -> None:
6969
serialization_counter[graph_text] += 1
7070

7171
expected_serialization = """\
72-
PREFIX ns1: <http://example.org/ex/>
72+
PREFIX ex: <http://example.org/ex/>
7373
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
7474
75-
ns1:A
75+
ex:A
7676
rdfs:comment "Thing A" ;
7777
.
7878
79-
ns1:C
79+
ex:C
8080
rdfs:comment "Thing C" ;
8181
.
8282
83-
ns1:B
83+
ex:B
8484
rdfs:comment "Thing B" ;
8585
.
8686
87-
[] ns1:has
87+
[] ex:has
8888
[
89-
rdfs:seeAlso ns1:A ;
89+
rdfs:seeAlso ex:A ;
9090
] ;
9191
.
9292
93-
[] rdfs:seeAlso ns1:B ;
93+
[] rdfs:seeAlso ex:B ;
9494
.
9595
96-
[] ns1:has
96+
[] ex:has
9797
[
98-
rdfs:seeAlso ns1:C ;
98+
rdfs:seeAlso ex:C ;
9999
] ;
100100
.
101101
102-
[] rdfs:seeAlso ns1:A ;
102+
[] rdfs:seeAlso ex:A ;
103103
.
104104
105-
[] rdfs:seeAlso ns1:C ;
105+
[] rdfs:seeAlso ex:C ;
106106
.
107107
108-
[] rdfs:seeAlso ns1:B ;
108+
[] rdfs:seeAlso ex:B ;
109109
.
110110
111-
[] ns1:has
111+
[] ex:has
112112
[
113-
rdfs:seeAlso ns1:B ;
113+
rdfs:seeAlso ex:B ;
114114
] ;
115115
.
116116

0 commit comments

Comments
 (0)