On 4/11/13 8:52 PM, Sandeep Gupta wrote:
select q1."y",q2.name <http://q2.name>, q2.age from (sparql PREFIX : <http://people.example/> SELECT ?y WHERE { :alice :knows ?y } ) as q1. people as q2 where q2.y=q1."y"-Sandeep
As you can see from the example above, a SPARQL SELECT (which returns a tabular structured result-set/solution) is treated as a Relational View -- which is why you can use it in the FROM CLAUSE of a SQL statement.
Building on the basic pattern above, you can go further by making Stored Procedures that serve as SPARQL built-in functions:
Procedure creation passed to SQL command processor:
CREATE PROCEDURE DB.DBA.ComposeInfo (
in pname varchar,
in pnick varchar := '',
in pbox varchar := '')
{
declare ss varchar;
ss := concat(pname, ' ', pnick, ' ', pbox);
ss := rtrim (ss, ' ');
return ss;
};
-- Grant execute privileges to user: demo
GRANT EXECUTE ON DB.DBA.ComposeInfo to demo ;
Usage in SPARQL:
## Execute via a Digest Authentication, WebID, or OAuth protected endpoint
## so that identity and privileges are matched up via Virtuoso ACL engine.
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT (sql:ComposeInfo (?name, ?nick, ?box))
FROM <http://www.w3.org/People/Berners-Lee/card>
WHERE
{
?s rdf:type foaf:Person .
optional{?s foaf:name ?name }.
optional{?s foaf:nick ?nick }.
optional{?s foaf:box ?box }.
filter (?nick like '%TimBL%') .
}
Usage via SQL command processor:
SPARQL
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT (sql:ComposeInfo (?name, ?nick, ?box))
FROM <http://www.w3.org/People/Berners-Lee/card>
WHERE
{
?s rdf:type foaf:Person .
optional{?s foaf:name ?name }.
optional{?s foaf:nick ?nick }.
optional{?s foaf:box ?box }.
filter (?nick like '%TimBL%') .
};
Query Result output:
callret-0
VARCHAR
_______________________________________________________________________________
Timothy Berners-Lee TimBL
1 Rows. -- 30 msec.
--
Regards,
Kingsley Idehen
Founder & CEO
OpenLink Software
Company Web: http://www.openlinksw.com
Personal Weblog: http://www.openlinksw.com/blog/~kidehen
Twitter/Identi.ca handle: @kidehen
Google+ Profile: https://plus.google.com/112399767740508618350/about
LinkedIn Profile: http://www.linkedin.com/in/kidehen
smime.p7s
Description: S/MIME Cryptographic Signature
------------------------------------------------------------------------------ Precog is a next-generation analytics platform capable of advanced analytics on semi-structured data. The platform includes APIs for building apps and a phenomenal toolset for data science. Developers can use our toolset for easy data analysis & visualization. Get a free account! http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________ Virtuoso-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/virtuoso-users
