This project has moved. For the latest updates, please go here.

Ask about export import

Aug 5, 2015 at 5:26 AM
Hi,

I have two questions about export import using BrightstarDB
The first one is, if I have several data on my database, can I export only the the data that I selected?
Example, I have two classes, vehicle and sparepart.
Can I export only vehicle data number one and the sparepart?
I can export all the data with no problem
And I tried the single graph export code, but I don't understand the "http://example.org/graph/1" part, and it do nothing


The second one is, I can't import the .xml file using the code
var importJob = client.StartImport("mystore", "data.xml");
or
var importJob = client.StartImport("mystore", "data.xml", RdfFormat.RdfXml);
There's no error, so I don't know what's wrong.
I can import .nq file with no problem.

Thank You
Coordinator
Aug 5, 2015 at 7:17 AM
Hi,

When you export from BrightstarDB you have basically two options:

1) Export everything in the store
2) Export the content of a single named graph in the store.

The second option is where the additional parameter (e.g "http://example.org/graph/1") comes in. However to use this option you must have created your data originally in this named graph.

If you want to "export" just a subset of the data without having to create graphs in this way then the best approach is to use a SPARQL CONSTRUCT query. The CONSTRUCT query type allows you to create RDF data from your query (and you have complete control over this so you can actually create different RDF triples from the ones that you have in the database...it is really powerful). A simple introduction can be found here: http://www.snee.com/bobdc.blog/2009/09/appreciating-sparql-construct.html

On the second question, I'm not sure from the code you posted where the problem might be but here are a couple of pointers. Firstly remember that the import job is run as a batch process. You need to use the importJob return value to monitor the progress of the job - see http://brightstardb.readthedocs.org/en/latest/RDF_Client_API/#rdf-jobs for more information. Secondly, an import job does not just import from a local file, it imports specifically from the BrightstarDB import directory. This is a directory named "import" that is in the same folder as your data stores. If neither of those pointers help, can you post a bit more detail about the results of the job when it fails - the IJobInfo that is returned by GetJobInfo has properties on it that give you access to the current processing status of the job; the last status message; and if the job fails any exception details.

Cheers

Kal
Aug 8, 2015 at 4:01 PM
Edited Aug 10, 2015 at 4:49 AM
Hi Kal,

Thanks for the reply.

For the first question, I think I'm gonna stick only to export all data, kinda confuse with SPARQL.

For the second question, I did as you say, I added the GetJobInfo.
And I got an error
RDF parser error: Error parsing NTriples stream : Length cannot be less than zero. Parameter name: length.
The code I used:
var importJob = client.StartImport("Car", fileName2, Constants.DefaultGraphUri);
Is it because the app thinks that the file is NTriples, but my file is XML?
I tried adding RdfFormat.RdfXml into the parameter,
var importJob = client.StartImport("Car", fileName2, Constants.DefaultGraphUri, RdfFormat.RdfXml);
but it shows red line on the visual studio, saying :
The best overloaded method match for 'BrightstarDB.Client.IBrightstarService.StartImport(string, string, string, string)' has some invalid arguments
Argument 4: cannot convert from 'BrightstarDB.RdfFormat' to 'string'
I used the same parameter on StartExport and there's no problem, weird.

Thanks again for the reply.


Update 10th August 2015
Today I got a new error,
RDF parser error: Invalid triple. Predicate URI or blank node expected.
Coordinator
Aug 10, 2015 at 8:18 AM
Hi,

Currently there isn't a way to specify the file format explicitly in the StartImport API. This should probably be fixed (I've logged an issue at https://github.com/BrightstarDB/BrightstarDB/issues/236).

Anyway, right now what the code does is to try and "guess" based on the file extension. NTriples is used as the fallback if the file type cannot be determined from the file extension so my guess is that this is what is happening in your case.

Try ensuring that the file extension is either .rdf or .xml. These extensions should result in the RDF/XML parser being used.

Cheers

Kal