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. 
 4   
 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. 
 8   
 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) 
15           
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   
21    
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") 
28    
29  @requires: U{RDFLib<http://rdflib.net>}, 2.2.2. and higher 
30  @license: This software is available for use under the U{W3C Software License<http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231>} 
31  @organization: U{World Wide Web Consortium<http://www.w3.org>} 
32  @author: U{Ivan Herman<a href="http://www.w3.org/People/Ivan/">} 
33  """ 
34   
35  """ 
36  $Id: __init__.py,v 1.2 2009/08/20 13:40:33 ivan Exp $ $Date: 2009/08/20 13:40:33 $ 
37  """ 
38   
39  __author__  = 'Ivan Herman' 
40  __contact__ = 'Ivan Herman, ivan@w3.org' 
41  __license__ = u'W3C® SOFTWARE NOTICE AND LICENSE, http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231' 
42