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

Source Code for Package RDFClosure.parsers

 1  # -*- coding: utf-8 -*- 
 2  """ 
 3  Parser module with a slightly improved versions of the Turtle parser. 
 4   
 5  The main issue is that the parser distributed by rdflib does not handle literals properly when they are not in quotes. Ie, for example,:: 
 6    <aaa> <bbbb> true . 
 7   
 8  is not recognized as::  
 9    <aaa> <bbbb> "true"^^xsd:boolean . 
10   
11  The errors are: 
12   
13   - Constants of the form 1234 should be interpreted as xsd integers, which is done correctly by the parser. 
14   - Constants of the form 1.2345 should be interpreted as xsd:decimal. Unfortunately, the original parser interprets them as xsd:double 
15   - Constants of the form 'true' or 'false' (whithout the quotes, that is) should be interpreted as xsd:boolean. Instead, they are put as symbols into the default namespace by the original parser. 
16   - Constants of the form 1.2345E12 should be interpreted as xsd:doubles. Unfortunately, the original parser crashes on those 
17    
18  This module provides an alternative parser that takes care of the first three problems. 
19   
20  Obviously, this parser can be used directly, too. Here is a way to do it:: 
21    from rdflib.plugin import register 
22    from rdflib.syntax import parsers 
23    register("my_turtle", parsers.Parser, "RDFClosure.parsers.N3Parser","N3Parser") 
24    ... 
25    graph.parse(<file>,format="my_turtle") 
26   
27           
28  @requires: U{RDFLib<http://rdflib.net>}, 2.2.2. and higher 
29  @license: This software is available for use under the U{W3C Software License<http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231>} 
30  @organization: U{World Wide Web Consortium<http://www.w3.org>} 
31  @author: U{Ivan Herman<a href="http://www.w3.org/People/Ivan/">} 
32  """ 
33   
34  """ 
35  $Id: __init__.py,v 1.2 2009/08/20 13:40:27 ivan Exp $ $Date: 2009/08/20 13:40:27 $ 
36  """ 
37   
38  __author__  = 'Ivan Herman' 
39  __contact__ = 'Ivan Herman, ivan@w3.org' 
40  __license__ = u'W3C® SOFTWARE NOTICE AND LICENSE, http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231' 
41