[redland-dev] Parsing ntriples from a string

DeeJay-G615 deejay at g615.co.uk
Sat Aug 19 04:52:29 UTC 2006


After a fair bit of digging through redland and raptor I found the 
source of my issues.

ntriples_parse.c :: raptor_ntriples_parse_chunk

   if(is_end) {
       if(ntriples_parser->offset != ntriples_parser->line_length)
           raptor_parser_error(rdf_parser, "Junk at end of input.\"");
       return 0;
   }

I guess I should have read the grammar for N-Triples 
(http://www.w3.org/TR/rdf-testcases/#ntriples) as I would have 
discovered that each triple must be terminated by an end of line character.

So

"<http://example/q?abc=1&def=2> 
<http://www.w3.org/1999/02/22-rdf-syntax-ns#value> \"xxx\" ."

should be

"<http://example/q?abc=1&def=2> 
<http://www.w3.org/1999/02/22-rdf-syntax-ns#value> \"xxx\" .\n"

Going back to the code exerpt above: surely it should be

   if(is_end) {
       if(ntriples_parser->offset != ntriples_parser->line_length) {
           raptor_parser_error(rdf_parser, "Junk at end of input.\"");
           return 1;
       } else {
           return 0;
       }
   }

As the procedure should return non zero on failure.


Something else I wanted to bring up as a result of my travels through 
the parsing parts of the API...

rdf_parser_raptor.c :: librdf_parser_raptor_parse_into_model_common

which encapsulates the functionality of parsing from a uri, from a 
string and from a counted.

the parameter list is
(void *context,
  librdf_uri *uri,
  const unsigned char *string,
  size_t length,
  librdf_uri *base_uri,
  librdf_model* model)

Procedures that use this to parse from a uri, pass the URI, null for the 
string and 0 for the length. Functions that parse from a string, pass 
null for the uri, pass the string and then 0 if they don't have the length.

How that calling convention interacts with the following code is my 
point of interest.

   if(!base_uri)
     base_uri=uri;

   /* No base URI given, cannot proceed */
   if(!base_uri)
     return 1;

If you don't pass a base uri when you are parsing from a URI you are ok, 
as it sets the base_uri to the uri as a default.
However if you are parsing from a string, and you don't supply 
base_uri... base_uri (which is already NULL) gets set to NULL, and then 
the second if block executes and it returns a failure.

Was this the intended behaviour? I'm guessing yes, as back up in 
rdf_parse.c, the 'parse from string' procedures check for the base URI 
being null, however the 'parse from uri' procedures don't.

What is the ryhme or reason to this?

DeeJay

DeeJay-G615 wrote:
> Ok, I've spent the last day trying to debug this and I finally have some 
> results.
> 
> I have no problems parsing rdf content, my Haskell version of example2.c 
> works fine. I also have had no issues with n-triples accessed from 
> URI's. Works fine with 
> http://www.w3.org/2000/10/rdf-tests/rdfcore/amp-in-url/test001.nt.
> 
> However I seem to have run into major issues when trying to parse 
> n-triples from strings. When I copy the the triple from the URL above I 
> can neither parse it to a stream or into a model. The ntriples triple is 
> "<http://example/q?abc=1&def=2> 
> <http://www.w3.org/1999/02/22-rdf-syntax-ns#value> \"xxx\" ."
> 
> If I pass a null as a base URI, redland fails internally and indicates 
> with the return value (null for the stream version and !=0 for the model 
> version), but it doesn't call the logging callback.
> 
> If I pass a valid URI as the base URI the procedure returns normally but 
> calls the logging function with code = 0, level = ERROR, facility = 
> PARSER, message = "Junk at end of input.\""
> 
> I have found this to be the case with both 
> librdf_parser_parse_string_as_stream and 
> librdf_parser_parse_string_into_model. Using the counted string versions 
> don't make any difference.
> 
> I am using the 1.0.3 Win32 Dev version. (I lament not being at home with 
> my linux desktop).
> 
> Thanks, DeeJay
> _______________________________________________
> redland-dev mailing list
> redland-dev at lists.librdf.org
> http://lists.gnomehack.com/mailman/listinfo/redland-dev
> 
> 
> 


More information about the redland-dev mailing list