HowTo – Load JSON-LD files into Virtuoso

HowTo – Load JSON-LD files into Virtuoso

The RDF_LOAD_JSON_LD( ) function enables the loading of JSON-LD files into Virtuoso, across multiple threads and as part of a transaction as required.

Name

RDF_LOAD_JSON_LD( ) - enables the loading of JSON-LD files into Virtuoso.

Synopsis

DB.DBA.RDF_LOAD_JSON_LD(
       in strg varchar, 
       in base varchar, 
       in graph varchar := null, 
       in flags integer := 0, 
       in threads int := 3,
       in transactional int := 0,
       in log_enable int := null)

Parameters

strg. - text of the resource

base - base IRI to resolve relative IRIs to absolute

graph - target graph IRI, parsed triples will appear in that graph.

flags - not used currently

threads - number of threads to use in call

transactional - enable or disable transactions

log_enable - controls transaction logging and in-statement autocommit as detailed at log_enable

Example

Given the following JSON_LD file in the database directory :

$ cat test.jsonld 
{
  "@context": "https://json-ld.org/contexts/person.jsonld",
  "@id": "http://dbpedia.org/resource/John_Lennon",
  "name": "John Lennon",
  "born": "1940-10-09",
  "spouse": "http://dbpedia.org/resource/Cynthia_Lennon"
}

It can be loaded into the database with the command:

SQL> rdf_load_json_ld (file_to_string('test.jsonld'),'', 'urn:test');

Done. -- 77 msec.
SQL>

producing the following graph in the database:

SQL> sparql select * from <urn:test> where {?s ?p ?o};
s                                                                                 p                                                                                 o
LONG VARCHAR                                                                      LONG VARCHAR                                                                      LONG VARCHAR
_______________________________________________________________________________

http://dbpedia.org/resource/John_Lennon                                           http://xmlns.com/foaf/0.1/name                                                    John Lennon
http://dbpedia.org/resource/John_Lennon                                           http://schema.org/birthDate                                                       1940-10-09
http://dbpedia.org/resource/John_Lennon                                           http://schema.org/spouse                                                          http://dbpedia.org/resource/Cynthia_Lennon

3 Rows. -- 1 msec.
SQL>

Related

Hi,

I also tried to import a JSON-LD file, but I encountered an error due to the large file size, as shown below. If there is a way to import large JSON-LD files, please let me know.

/opt/virtuoso-opensource/database/MassBank.jsonld                                 http://example.com/test                                                           2           2024.1.25 8:13.33 967
044000  2024.1.25 8:13.33 967407000  0           NULL        39000 FA008: File '/opt/virtuoso-opensource/database/MassBank.jsonld' is too large (414984612 bytes), cannot return string content large
r than 10485760 bytes

The Virtuoso RDF Bulk Loader should be used for loading large RDF datasets ie JSON-LD and other …

Does it mean that one large file needs to be split into several parts?

Depends on the size of the actual dataset. Typically anything less than 1GB can be bulk loaded as a single file. If larger then it is recommended to split which enables the bulk loader to be run across multiple threads depending on the number of cores available for optimal loading of the dataset files in parallel, improving the performance of the load, as detailed in the documentation.