Letractively / rdflib

Automatically exported from code.google.com/p/rdflib
Other
0 stars 0 forks source link

value error when parsing n3 #68

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Is this a bug?

>>> from rdflib import ConjunctiveGraph
>>> g = ConjunctiveGraph()
>>> g.parse('/Users/jjc/Desktop/tempANLordsWales.n3', format='n3')

throws a Value error:
ValueError: Found a when expecting a
http://www.w3.org/2000/10/swap/grammar/n3#objecttail .

The puzzling thing is that the parse apparently succeeded, for a subsequent 
call to  
g.serialize(format='n3') returns exactly the graph I expected.

the error and trace:
No handlers could be found for logger "rdflib.Literal"
  File "build/bdist.macosx-10.3-i386/egg/rdflib/Graph.py", line 890, in parse
  File "build/bdist.macosx-10.3-i386/egg/rdflib/Graph.py", line 713, in parse
  File "build/bdist.macosx-10.3-i386/egg/rdflib/syntax/parsers/N3Parser.py", line 32, in parse
  File "build/bdist.macosx-10.3-i386/egg/rdflib/syntax/parsers/n3p/n3proc.py", line 119, in parse
  File "build/bdist.macosx-10.3-i386/egg/rdflib/syntax/parsers/n3p/n3p.py", line 83, in parse
ValueError: Found a when expecting a 
http://www.w3.org/2000/10/swap/grammar/n3#objecttail . 
todoStack=[['http://www.w3.org/2000/10/swap/grammar/n3#document', 
['http://www.w3.org/2000/10/swap/grammar/bnf#eof']], 
['http://www.w3.org/2000/10/swap/grammar/n3#statements_optional', []], 
['http://www.w3.org/2000/10/swap/grammar/n3#statements_optional', []], 
['http://www.w3.org/2000/10/swap/grammar/n3#statements_optional', []], 
['http://www.w3.org/2000/10/swap/grammar/n3#statements_optional', []], 
['http://www.w3.org/2000/10/swap/grammar/n3#statements_optional', []], 
['http://www.w3.org/2000/10/swap/grammar/n3#statements_optional', []], 
['http://www.w3.org/2000/10/swap/grammar/n3#statements_optional', []], 
['http://www.w3.org/2000/10/swap/grammar/n3#statements_optional', []], 
['http://www.w3.org/2000/10/swap/grammar/n3#statements_optional', []], 
['http://www.w3.org/2000/10/swap/grammar/n3#statements_optional', []], 
['http://www.w3.org/2000/10/swap/grammar/n3#statements_optional', []], 
['http://www.w3.org/2000/10/swap/grammar/n3#statements_optional', []], 
['http://www.w3.org/2000/10/swap/grammar/n3#statements_optional', []], 
['http://www.w3.org/2000/10/swap/grammar/n3#statements_optional', []], 
['http://www.w3.org/2000/10/swap/grammar/n3#statements_optional', []], 
['http://www.w3.org/2000/10/swap/grammar/n3#statements_optional', []], 
['http://www.w3.org/2000/10/swap/grammar/n3#statements_optional', []], 
['http://www.w3.org/2000/10/swap/grammar/n3#statements_optional', []], 
['http://www.w3.org/2000/10/swap/grammar/n3#statements_optional', []], 
['http://www.w3.org/2000/10/swap/grammar/n3#statements_optional', []], 
['http://www.w3.org/2000/10/swap/grammar/n3#statements_optional', []], 
['http://www.w3.org/2000/10/swap/grammar/n3#statements_optional', []], 
['http://www.w3.org/2000/10/swap/grammar/n3#statements_optional', []], 
['http://www.w3.org/2000/10/swap/grammar/n3#statements_optional', []], 
['http://www.w3.org/2000/10/swap/grammar/n3#statements_optional', []], 
['http://www.w3.org/2000/10/swap/grammar/n3#statements_optional', []], 
['http://www.w3.org/2000/10/swap/grammar/n3#statements_optional', []], 
['http://www.w3.org/2000/10/swap/grammar/n3#statements_optional', []], 
['http://www.w3.org/2000/10/swap/grammar/n3#statements_optional', []], 
['http://www.w3.org/2000/10/swap/grammar/n3#statements_optional', [u'.', 
'http://www.w3.org/2000/10/swap/grammar/n3#statements_optional']], 
['http://www.w3.org/2000/10/swap/grammar/n3#statement', []], 
['http://www.w3.org/2000/10/swap/grammar/n3#simpleStatement', []], 
['http://www.w3.org/2000/10/swap/grammar/n3#propertylist', []], 
['http://www.w3.org/2000/10/swap/grammar/n3#propertylisttail', []], 
['http://www.w3.org/2000/10/swap/grammar/n3#propertylist', []], 
['http://www.w3.org/2000/10/swap/grammar/n3#propertylisttail', []], 
['http://www.w3.org/2000/10/swap/grammar/n3#propertylist', []], 
['http://www.w3.org/2000/10/swap/grammar/n3#propertylisttail', []], 
['http://www.w3.org/2000/10/swap/grammar/n3#propertylist', []], 
['http://www.w3.org/2000/10/swap/grammar/n3#propertylisttail', []], 
['http://www.w3.org/2000/10/swap/grammar/n3#propertylist', 
['http://www.w3.org/2000/10/swap/grammar/n3#propertylisttail']], 
['http://www.w3.org/2000/10/swap/grammar/n3#objecttail', []], 
['http://www.w3.org/2000/10/swap/grammar/n3#objecttail', []]]

the .n3 file is attached.
cwm has no trouble parsing this file, in spite of its obvious peculiarities

rdflib 2.4.1; Python 2.5.2; MacBook OS X 10.5.5

Original issue reported on code.google.com by crumpj...@gmail.com on 17 Jun 2009 at 9:34

Attachments:

GoogleCodeExporter commented 9 years ago
OK, I've had the time now to go back through the attached file to find that the 
offending URI is :Bernard_of_Neufmarché as below. It 
would appear that rdflib is sensitive to diacritics in URIs. The n3p.py does 
not encode the UTF-8 characters it finds in URIs. Is this 
intended or a bug? My understanding, fragile as it is, is that diacritics are 
permitted in URIs, at least cwm and other rdf applications 
I'm aware of don't seem to object to them.

:Brecon a :Place;
    rdfs:label "Brecon";
    :hasValuation "valuation £1,543";
    :hasDynasty
        :Miles_of_Gloucester_and_sons_Brecon,
        :Braose_Brecon,
        :Bohun_Brecon,
        :Duchy_of_Lancaster;
    :hasLord
        :Henry_Bollingbroke,
        :Bernard_of_Neufmarché .

Original comment by crumpj...@gmail.com on 9 Jul 2009 at 8:06

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Hi,

I have tried to parse an RDF graph from the SP2Bench datset. This dataset has a 
some
prefixes like:
     @prefix dc: <http://purl.org/dc/elements/1.1/> .
     @prefix dcterms: <http://purl.org/dc/terms/> .
     @prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
     @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

When I have tried to parse it using RDFLib graph...
    g = Graph()
    g.parse('sp2b.n3',format="n3") method I have got the following error:

    raise ParseError("Invalid line: %r" % self.line)
    rdflib.syntax.parsers.ntriples.ParseError: Invalid line: '@prefix dcterms:
      <http://purl.org/dc/terms/> .'

Any help would be appriciated:

Manu:
manu.alem@gmail.com

Original comment by manu.a...@gmail.com on 31 Jul 2009 at 4:48

GoogleCodeExporter commented 9 years ago

Original comment by eik...@gmail.com on 1 Feb 2010 at 8:22

GoogleCodeExporter commented 9 years ago

Original comment by gromgull on 1 Feb 2010 at 9:40

GoogleCodeExporter commented 9 years ago
Fixed in r1755, test-case in test_n3.py

Original comment by gromgull on 2 Feb 2010 at 9:41