0

I am looking to add triples in a certain order using Python's RDFLib Library. I'm aware RDF triples have no ordering, however, I was hoping to add the triples in the order in which the add() function is called. For example,

If I add the following triples

bob = URIRef("http://example.org/people/Bob")
name = Literal("Bob")

g.add((bob, RDF.type, FOAF.Person))
g.add((bob, FOAF.name, name))

The output generated

ex:Bob foaf:name "Bob"; 
       rdf:type foaf:Person. 

Would there be a way to ensure the order in which the add function is called correlates with the output file? E.g

ex:Bob rdf:type foaf:Person.
       foaf:name "Bob". 
 

Thanks for any help!

Alex
  • 47
  • 1
  • 9
  • no, that's not possible, but you can simply extend/write the Turtle or N-Triples serializer - I mean, the code is open source. – UninformedUser Aug 13 '21 at 05:48

1 Answers1

1

Unfortunately not. From the documentation,

RDFLib graphs are un-sorted containers; they have ordinary set operations (e.g. add() to add a triple) plus methods that search triples and return them in arbitrary order.

Thomas
  • 720
  • 9
  • 22