Package RDFClosure :: Package serializers
[hide private]
[frames] | no frames]

Source Code for Package RDFClosure.serializers

 1  # -*- coding: utf-8 -*- 
 2  """ 
 3  Serializer module with a slightly improved versions of the Turtle and Pretty XML serializers. 
 5  Both are, actually, almost verbatim copy of the RDFLib Turtle and pretty XML serializer module, respectively. 
 6  For more detailed on how serializers work and are registered by RDFLib, please refer to the RDFLib  
 7  descriptions and source code. 
 9  The differences, v.a.v. the original, for the Pretty XML serializer: 
10   - there were bugs in the original in case an rdf:List was generated with Literal content 
11   - added a pretty print branch for Seq/Alt/Bag 
12   - removal of the CDATA sections when generating an XML Literal (it is a cautionary support in RDFLib but, because XML literals can be generated under very controlled circumstances only in the case of RDFa, it is unnecessary).  
13   - use the character " instead of ' for namespace declarations (to make it uniform with the way attributes are handled 
14   - increased the initial depth for nesting (to 8) 
16  The differences, v.a.v. the original, for the Turtle serializer: 
17   - there was a bug in the syntax of the @prefix setting 
18   - the original Turtle serializer insisted on creating prefixes for all URI references, ending up with a large number of fairly unnecessary prefixes that made the output a bit unreadable. This has been changed so that only the 'registered' prefixes are used, ie, those that the original RDFa source contains 
19   - the original Turtle had a bug and did not generate the shorhands for lists 
20   - changed the indentation rules for anonymous ('squared') blank nodes   
22  Obviously, these serializers can be used directly, too. Here is a way to do it (for the turtle one):: 
23    from rdflib.plugin import register 
24    from rdflib.syntax import serializer, serializers 
25    register("my-turtle",serializers.Serializer,"RDFClosure.serializers.TurtleSerializer","TurtleSerializer") 
26    ... 
27    graph.serialize(format="my-turtle") 
29  @requires: U{RDFLib<>}, 2.2.2. and higher 
30  @license: This software is available for use under the U{W3C Software License<>} 
31  @organization: U{World Wide Web Consortium<>} 
32  @author: U{Ivan Herman<a href="">} 
33  """ 
35  """ 
36  $Id:,v 1.2 2009/08/20 13:40:33 ivan Exp $ $Date: 2009/08/20 13:40:33 $ 
37  """ 
39  __author__  = 'Ivan Herman' 
40  __contact__ = 'Ivan Herman,' 
41  __license__ = u'W3C® SOFTWARE NOTICE AND LICENSE,'