%META:TOPICPARENT{name="VirtR2RML"}% ---+Generate Linked Data Views via R2RML from iSQL %TOC% Using Virtuoso you can programmatically generate Linked Data Views atop Relational Data Sources, using R2RML via the built-in function: R2RML_GENERATE_LINKED_VIEW function. In order to use this function, you need to have the [[https://virtuoso.openlinksw.com/download/][rdb2rdf_dav.vad]] package installed. ---++Function Description R2RML_GENERATE_LINKED_VIEW ( in source varchar, in destination_graph varchar, in graph_type int default 0, in clear_source_graph int default 1 ) ---+++Parameters Description * source: The source R2RMLdocument URI. Acceptable schemes include: file:, dav:, http: and https:. These are also acceptable as source graph URI.; * destination graph: This is a default graph name (an IRI) applicable to either virtual or physical graph. * graph_type: 0 - virtual; 1 - physical graph which sets the actual graph type; * clear_source_graph: Determines if existing R2RML source graphs (those holding view declarations) are replaced as part of processing pipeline. Note: The R2RML mapping script may have a triples like [] rr:graph <graph_name> and in this case they take precedence and virtual graph would be defined as in the R2RML. If so, then if destination graph is specified as physical, all virtual graphs found in the R2RML would go in the destination_graph. ---++Usage Example ---+++Prerequisites Ensure the R2RML VAD package [[https://virtuoso.openlinksw.com/download/][ rdb2rdf_dav.vad]] is installed. ---+++Steps 1. To clear out existing mappings execute: SQL> SELECT RDF_VIEW_DROP_STMT_BY_GRAPH ('http://example.com'); VARCHAR _______________________________________________________________________________ SPARQL drop silent quad map .; 1 Rows. -- 16 msec. SQL> SPARQL DROP SILENT QUAD MAP ; STATE MESSAGE VARCHAR VARCHAR _______________________________________________________________________________ 00000 Quad map is no longer used in storage 00000 Quad map is deleted 00000 Transaction committed, SPARQL compiler re-configured 00000 2 RDF metadata manipulation operations done 4 Rows. -- 406 msec. SQL> SPARQL CLEAR ; callret-0 VARCHAR _______________________________________________________________________________ Clear -- done 1 Rows. -- 15 msec. SQL> DROP TABLE "R2RML"."TEST"."PRODUCT" ; Done. -- 0 msec. SQL> CREATE TABLE "R2RML"."TEST"."PRODUCT" ( "id" INTEGER, "name" VARCHAR(100), PRIMARY KEY ("id") ); Done. -- 16 msec. 1 Insert sample data into a Table by executing: SQL> INSERT SOFT "R2RML"."TEST"."PRODUCT" VALUES(1, 'Virtuoso'); Done. -- 0 msec. 1 Locate or create your R2RML mapping document, for example: [[http://demo.openlinksw.com/r2rmldemo.n3][.n3 file]] with the following content: @prefix rr: . @prefix exa: . @prefix product: . a rr:TriplesMap; rr:logicalTable [ rr:tableSchema "R2RML"; rr:tableOwner "TEST"; rr:tableName "PRODUCT" ]; rr:subjectMap [ rr:template "http://example.com/product/{id}"; rr:class exa:product; ]; rr:predicateObjectMap [ rr:predicate product:id; rr:objectMap [ rr:column "id" ]; ]; rr:predicateObjectMap [ rr:predicate product:name; rr:objectMap [ rr:column "name" ]; ]; . 1 Generate a Linked Data View from the R2RML document that applies to the sample data (created earlier) by executing the statement: SQL> DB.DBA.R2RML_GENERATE_LINKED_VIEW('http://demo.openlinksw.com/r2rmldemo.n3', 'http://example.com', 0); STATE MESSAGE VARCHAR VARCHAR _______________________________________________________________________________ 00000 IRI class has been defined (inherited from rdfdf:sql-integer-uri-nullable) 00000 Literal class has been defined (inherited from rdfdf:sql-integer-literal-nullable) 00000 Quad storage is flagged as being edited 00000 Quad map has been created and added to the 00000 Quad map has been created and added to the 00000 Quad map has been created and added to the 00000 Quad map has been created and added to the 00000 Quad storage is unflagged and can be edited by other transactions 00000 Transaction committed, SPARQL compiler re-configured 00000 9 RDF metadata manipulation operations done 10 Rows. -- 1109 msec. SQL> 1 Verify successful creation of the Linked Data View by executing the following SPARQL query via iSQL or Conductor interfaces: SQL> SPARQL SELECT * FROM WHERE {?s ?p ?o} ; s p o VARCHAR VARCHAR VARCHAR _______________________________________________________________________________ http://example.com/product/1 http://example.com/product#id 1 http://example.com/product/1 http://example.com/product#name Virtuoso http://example.com/product/1 http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://example.com/ns#product 3 Rows. -- 15 msec. ---++Related * [[VirtR2RML][Virtuoso R2RML Support]] * [[VirtConductorR2RMLImport][Virtuoso Conductor R2RML Import Wizard]] * [[VirtTipsAndTricksGuideConductorR2RML][Generating Transient and/or Persistent Linked Data Views atop Remote Relational Data Sources Using Conductor]] * W3C page for [[http://www.w3.org/TR/r2rml/][R2RML: RDB to RDF Mapping Language]]