Save a list of rdf graphs in binary

I’m using: SWI-Prolog version 8.1.7

I want the code to: save a list of rdf graphs in binary.
rdf_save_db/1 - save all the rdf graphs
rdf_save_db/2 - save one graph

I have a need to save a list of graphs in binary.

But what I’m getting is:
I am using the code below (copy and paste of rdf_save_db/2 by adding a forall). It saved the graphs without error.
But rdf_load_db/1 only load one graph.

  1. how to accomplish with current version?
  2. I am requesting to update rdf_save_db/2 to save a list of graphs - to save one graph, just use [G]. Thanks for your consideration.

My code looks like this:

ip_model_save_db(File, Graphs) :-
	must_be(list, Graphs),
    current_prolog_flag(rdf_triple_format, Version),
    setup_call_cleanup(
        open(File, write, Out, [type(binary)]),
        ( set_stream(Out, record_position(false)),
          forall(member(Graph, Graphs),
          	rdf_db:rdf_save_db_(Out, Graph, Version))
        ),
        close(Out)).	

Thanks.

A binary graph dump is a self-contained object that includes a dictionary and thus cannot simply be concatenated to form a new binary graph. You might be able to use a similar trick to load all graphs from the input stream by calling rdf_load_db_/3 until you reach end-of-file.

I do not yet see that much point in this, but if it is that simple I I’m happy to accept a pull request. I advice to do that as calling internal predicates is likely to break sooner or later. Only changes to the exported predicates are announced, minimised and if possible the impact for user programs is minimized. Internal interfaces are changed without notice.

Thank you so much, Jan. Playing the same trick with rdf_load_db_/3 works.
I realize the peril of using internal APIs. I am using a wrapper in these cases so when things do change, it will impact only a few spots.

I do have a hard-need for saving a list of graphs. Here is the case in brief (hopefully you might be able to point me with better alternatives):
A base set of rdf graphs are loaded. Then a source document is processed and additional graphs are generated (we call it the training process). We only need to save the newly generated graphs.

Nan

You can of course save multiple graphs in a directory or zip file. Anyway, if you create a nice pull request I’m happy to process it. Please also update the PlDoc comments :slight_smile: