Here’s a brief example:
--
-- Inserts triples of the form ?s meshv:active "true|false"^^xsd:boolean
--
CREATE PROCEDURE meshrdf_insert_active(in graph_uri varchar, in active varchar)
{
DECLARE stmt varchar;
IF (active <> 'false' AND active <> 'true')
signal('INVALID', 'The <active> argument must be either "true" or
"false"');
stmt := sprintf('PREFIX meshv: <http://id.nlm.nih.gov/mesh/vocab#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
WITH <%s>
INSERT { ?s meshv:active "%s"^^xsd:boolean }
WHERE { ?s a ?o }', graph_uri, active);
LOG_ENABLE(2,1);
CALL SPARQL_EVAL(stmt, graph_uri, 0);
}
When performance is the overriding concern, and when the SQL is sufficiently
clear, you can use SQL – This is one of the main advantages of using Virtuoso:
--
-- Deletes all triples of the form ?s meshv:active ?o from a particular graph.
--
-- The equivalent SPARUL would be:
--
-- PREFIX meshv: <http://id.nlm.nih.gov/mesh/vocab#>
-- WITH <graph_uri>
-- DELETE { ?s meshv:active ?a } WHERE { ?s meshv:active ?a }
--
-- SQL is compiled when the stored procedure is defined, even though graph_uri
-- is an argument. This would not be the case for SPARUL.
--
CREATE PROCEDURE meshrdf_clear_active(in graph_uri varchar) {
LOG_ENABLE(2,1);
DELETE FROM RDF_QUAD
WHERE g = rdf_make_iid_of_qname(graph_uri)
AND p =
rdf_make_iid_of_qname('http://id.nlm.nih.gov/mesh/vocab#active');
}
From: Beppe Mazzola [mailto:beppemazz...@gmail.com]
Sent: Monday, June 19, 2017 1:27 PM
To: virtuoso-users@lists.sourceforge.net
Subject: [Virtuoso-users] how to pass as parameter the virtual graph IRI to a
SPARQL statement ?
Hi to all
I am trying to develop a SPARQL statement in a stored procedure related to a
virtual graph (result of a R2RML mapping) having its IRI not hard coded, but
contained in a variable.
I have tried for example the following syntax, but the query does not return
any triple.
declare graphName varchar;
graphName := 'http://example.com/resource';
for (sparql define input:storage
"http://www.openlinksw.com/schemas/virtrdf#DefaultQuadStorage"
select distinct ?class where
{
graph ?:graphName
{
?s <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?class
}
} order by ?class
) do
{
-- do something
string_to_file ('./dump/out.txt',"class" || '\n',-1);
} ;
As soon as I use the hard coded graph name in the SPARQL statement it works
fine.
...
select distinct ?class where
{
graph <http://example.com/resource>
{
?s <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?class
}
} order by ?class
) do
...
The same if I switch from a virtual graph to a real one. It works immediately
with te graph in a variable. Like in the following code.
declare graphName varchar;
graphName := 'http://xmlns.com/foaf/0.1/';
for (sparql define input:storage ""
select distinct ?class where
{
graph ?:graphName
{
?s <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?class
}
} order by ?class limit 10
) do
{
-- do something
string_to_file ('./dump/out.txt',"class" || '\n',-1);
} ;
Any chance to have a virtual graph IRI contained in a variable in a working
SPARQL statement?
Thanks!
Cheers
Beppe
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Virtuoso-users mailing list
Virtuoso-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/virtuoso-users