RDFLib/rdflib — pull request #422 by rory (2014-08-18 09:39:46+00:00)
Title: Convience method to add nested/abbreviated triples to graphs (like Turtle)

Hi.

This is a suggested convenience method to allow adding many triples in one call. It is similar to Turtle's nested/abbreviated syntax, but in python.

e.g.:

graph.add_nested( (self.michel, [(self.likes, self.pizza), (self.hates, self.cheese)]) )

Is the same as:

graph.add( (self.michel, self.likes, self.pizza) )
graph.add( (self.michel, self.hates, self.cheese) )

This is inspired by the `` ; . `` turtle format.

And it can support adding ``BNodes`` if needed:

graph.add_nested( (self.michel, self.likes, [(self.likes, self.pizza), (self.likes, self.cheese)]) )

Is the same as:

new_person = BNode()
graph.add( (self.michel, self.likes, new_person) )
graph.add( (new_person self.likes, self.pizza) )
graph.add( (new_person self.likes, self.cheese) )

This is inspired by the `` [ ; ] . `` turtle format.

All the logic is in ``rdflib.graph.expand_nested_triples``, and unittests are included.