pchampin / sophia_rs

Sophia: a Rust toolkit for RDF and Linked Data
Other
210 stars 23 forks source link

Bad turtle serialization (... or I am doing something wrong) #104

Closed hoijui closed 7 months ago

hoijui commented 2 years ago

(related to #17)

I see that there is now code to serialize to turtle, but I get strange results. Taking the sample code provided in the docu - modified to export turtle instead of n-triples, pretty with prefixes - I am expecting this:

(code: https://gist.github.com/hoijui/72aa8e5bf8dd7381425dfb6676e7fe62)

@prefix ex: <http://example.org/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .

bla:alice
  foaf:name "Alice" ;
  foaf:mbox <mailto:alice@work.example> .

bla:bob
  foaf:name "Bob" ;
  foaf:knows bla:alice .

but I get this: (NOTE: PREFIX instead of @prefix, and duplicated : (this RDF looks quite rusty... ;-) ))

PREFIX bla:: <http://example.org/>
PREFIX ex:: <http://example.org/>
PREFIX foaf:: <http://xmlns.com/foaf/0.1/>

bla::alice
  foaf::name "Alice";
  foaf::mbox <mailto:alice@work.example>.

bla::bob
  foaf::name "Bob";
  foaf::knows bla::alice.
hoijui commented 2 years ago

PS: I tried leaving out the addition of the ":" when creating Prefix::new, but then I get an "invalid prefix" error, right there.

pchampin commented 2 years ago

This is embarrassing. It is actually a stupid bug in Sophia, which I have fixed some time ago (553a1fa3) but hadn't yet pushed nor released that fix.

The intended behavior of Prefix::new is to take the prefix without the trailing colon. The stupid bug is that it rejects valid prefixes, and accepts invalid prefixes. This give you the wrong impression that the colon was required, and produced the buggy result.

I plan to release Sophia 0.7.1 with this bug fix and another few minor improvements, but I don't have much time for that in the next week or two, unfortunately... In the meantime, you can now use the github version. Sorry for the inconvenience.

hoijui commented 2 years ago

ahh perfect, that works for me, thanks! :-)

what about the PREFIX format? I imagine that is an other bug (if any at all), right?

pchampin commented 2 years ago

It is not a bug. This syntax (PREFIX instead of @prefix) has been included in Turtle when it was standardized by W3C in 2014. See https://www.w3.org/TR/turtle/#h_note_1

I favored this syntax to ease the copy-paste to SPARQL queries, but this could be made configurable (by adding a field to TurtleConfig).

mbarbieri77 commented 1 year ago

Please also support RDF 1.1 Turtle according to spec: https://www.w3.org/TR/turtle/

Especially also the ability to specify the @base IRI.

pchampin commented 1 year ago

@mbarbieri77 as far as I can tell, @base is supported...

pchampin commented 7 months ago

This bug was fixed a while ago