[redland-dev] [Redland librdf RDF API 0000602]: Generating triples as we are parsing an input file

Mantis Bug Tracker mantis-bug-sender at librdf.org
Wed Sep 16 14:38:51 EDT 2015


The following issue has been SUBMITTED. 
====================================================================== 
http://bugs.librdf.org/mantis/view.php?id=602 
====================================================================== 
Reported By:                Delaram
Assigned To:                
====================================================================== 
Project:                    Redland librdf RDF API
Issue ID:                   602
Category:                   api
Reproducibility:            unable to reproduce
Severity:                   major
Priority:                   high
Status:                     new
====================================================================== 
Date Submitted:             2015-09-16 11:38
Last Modified:              2015-09-16 11:38
====================================================================== 
Summary:                    Generating triples as we are parsing an input file
Description: 
We are developing a C++ library to parse some files and generate an ontology
from them.
I couldn't figure out a way to load in our schema(RDF schema, N3 format) and add
triples to it.

I'm using a sample pizza ontology untill I get it to work.



Steps to Reproduce: 
    librdf_world* world;
    librdf_storage* storage;
    librdf_parser* parser;
    librdf_model* model;
    librdf_statement *statement;
    librdf_uri *uri;
    raptor_iostream* iostr;
    raptor_world *raptor_world_ptr;
    librdf_serializer* serializer;
    char *program="PopulateOntology";

    world=librdf_new_world();
    librdf_world_open(world);

    raptor_world_ptr = librdf_world_get_raptor(world);

    storage=librdf_new_storage(world, "file", file_name, NULL);
    if(!storage) {
      fprintf(stderr, "%s: Failed to create new storage\n", program);
      return(1);
    }
    cout << "Storage OK!" << endl;

    model=librdf_new_model(world, storage, NULL);
    if(!model) {
      fprintf(stderr, "%s: Failed to create model\n", program);
      return(1);
    }
    cout << "Model OK!" << endl;

    parser=librdf_new_parser(world, NULL, "application/n-triples", NULL);
    if(!parser) {
      fprintf(stderr, "%s: Failed to create new parser\n", program);
      return(1);
    }
    cout << "Parser OK!" << endl;

    uri=librdf_new_uri_from_filename(world, (const char*)"../pizza.n3");
    if(!uri) {
      fprintf(stderr, "%s: Failed to create URI\n", program);
      return(1);
    }
    cout << "URI OK!: " << librdf_uri_as_string(uri) << endl;

    fprintf(stdout, "%s: Parsing URI %s\n", program, librdf_uri_as_string(uri));
    if(librdf_parser_parse_into_model(parser, uri, uri, model)) {
      fprintf(stderr, "%s: Failed to parse RDF into model\n", program);
      return(1);
    }
    cout << "Parsing URI into model OK!" << endl;



    statement=librdf_new_statement_from_nodes(world,
librdf_new_node_from_uri(world, librdf_new_uri_from_uri_local_name(uri, (const
unsigned char*)"C1")),
                                              librdf_new_node_from_uri(world,
librdf_new_uri_from_uri_local_name(uri, (const unsigned char*)"hasNeighbor")),
                                             
librdf_new_node_from_literal(world, (const unsigned char*)"O1", NULL, 0)
                                              );

    librdf_model_add_statement(model, statement);
    librdf_free_statement(statement);

serializer=librdf_new_serializer(world, "ntriples", "application/n-triples",
NULL);
librdf_serializer_serialize_model_to_file(serializer, "pizza.n3", NULL, model);


///
    /* Print out the model*/
//    fprintf(stdout, "%s: Resulting model is:\n", program);
//    iostr = raptor_new_iostream_to_file_handle(raptor_world_ptr, stdout);
//    librdf_model_write(model, iostr);
//    raptor_free_iostream(iostr);

    librdf_free_statement(statement);
    librdf_free_serializer(serializer);
    librdf_free_uri(uri);
    librdf_free_parser(parser);
    librdf_free_model(model);
    librdf_free_storage(storage);
    librdf_free_world(world);

Additional Information: 
We also tried:

    /* Print out the model*/
    fprintf(stdout, "%s: Resulting model is:\n", program);
    iostr = raptor_new_iostream_to_file_handle(raptor_world_ptr, stdout);
    librdf_model_write(model, iostr);
    raptor_free_iostream(iostr);
But we weren't successful.
Somehow we can't get the Redland lib to load our schema and add triples to it.
====================================================================== 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2015-09-16 11:38 Delaram        New Issue                                    
======================================================================



More information about the redland-dev mailing list