Published on :

Local SPARQL Integration Test with SAS-SPARQLwrapper

This code is also available in: Deutsch Español Français
Awaiting validation
The script begins by configuring log options for macros and includes the definition of macros from 'sparqlquery.sas©'. It then uses the `%sparqlupdate` macro to insert a set of seven book titles into a specific SPARQL graph (`http://example/bookStore`) on a local server (`localhost:8890`). After insertion, the `%sparqlquery` macro is called to execute a `SELECT *` query to retrieve all previously added titles. The results of this query are stored in a SAS© table named 'query'. Finally, `PROC PRINT` is used to display the content of this 'query' table, allowing verification that data insertion and retrieval were successful.
Data Analysis

Type : EXTERNAL


Data is managed directly within an external SPARQL endpoint, accessible via `http://localhost:8890/sparql/`. The script proceeds with 'creating' this data via a SPARQL `INSERT DATA` instruction and retrieving it via a SPARQL `SELECT *` instruction. Although the script initiates data creation, the data resides in a third-party database, making it an external source from SAS's perspective.

1 Code Block
Configuration and Macro Inclusion
Explanation :
This block configures SAS options to display macro execution logs (`mprint`, `mlogic`) and includes the 'sparqlquery.sas' file, which contains the definitions of the `%sparqlupdate` and `%sparqlquery` macros needed to interact with a SPARQL endpoint.
Copied!
1options mprint mlogic nocenter;
2%include "sparqlquery.sas";
3 
2 Code Block
Macro %sparqlupdate Data
Explanation :
Call to the `%sparqlupdate` macro to send a SPARQL `INSERT DATA` instruction to the specified endpoint. This instruction adds seven triples (representing books with their titles) to the `<http://example/bookStore>` graph of the SPARQL database. The `debug=Y` parameter enables detailed execution logging.
Copied!
1%sparqlupdate(
2endpoint=http://localhost:8890/sparql/update,
3update=%str(
4PREFIX dc: 1.1/>
5INSERT DATA
6{
7GRAPH {
8 dc:title "A new book 1" .
9 dc:title "A new book 2" .
10 dc:title "A new book 3" .
11 dc:title "A new book 4" .
12 dc:title "A new book 5" .
13 dc:title "A new book 6" .
14 dc:title "A new book 7" .
15}
16}
17),
18resultdsn=updateresult,
19debug=Y
20);
3 Code Block
Macro %sparqlquery
Explanation :
Execution of a SPARQL `SELECT *` query via the `%sparqlquery` macro. This query aims to retrieve all subjects (`?s`) and their titles (`?o`) from the graph, corresponding to the previously inserted data. The results are stored in the SAS table `query` for later use in SAS.
Copied!
1%sparqlquery(
2endpoint=http://localhost:8890/sparql/query,
3query=%str(
4PREFIX dc: 1.1/>
5SELECT *
6{
7 ?s dc:title ?o .
8}
9 ),
10querymethod=queryGET,
11resultdsn=query,
12sparqlquerysxlemap=%str(sparqlquery-sxlemap.map),
13debug=Y
14);
4 Code Block
PROC PRINT
Explanation :
The `PROC PRINT` procedure is used to display the content of the SAS table `query`. This allows visualizing the results of the SPARQL query and confirming that the data has been correctly retrieved from the external endpoint.
Copied!
1PROC PRINT DATA=query width=min;
2RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : Program : example-localhost-virtuoso-01.sas Purpose : Basic test of SAS-SPARQLwrapper using a query and local server