Are Custom SPARQL Extension Functions supported and How can I use them?
Virtuoso provides supported 2 ways to write one's own custom SPARQL extension functions:
Using Stored Procedure
You can create a stored procedure in Virtuoso PL and call it using the sql: prefix:
SQL> create procedure testfunc()
{
-- your code here
}
;
Done;
SQL> SPARQL
SELECT *
WHERE
{
?s ?p `sql:testfunc(?o)`
}
For more details see Calling SQL from SPARQL Virtuoso Documentation.
Create a build in function
You can also make a build in function which is basically a C function that can be called from both SQL and SPARQL as in the example from below, using the bif: prefix.
In this example we use the CONTAINS function to do a freetext search on all ?o that contain words starting with Timo.
SELECT *
FROM <http://www.w3.org/people#>
WHERE
{
?s ?p ?o . ?o
bif:contains '"Timo*"'
}
For more details see Using Full Text Search in SPARQL Virtuoso Documentation.
You can basically use relevant functions from the Virtuoso Functions Guide inside your SPARQL query. See Virtuoso supported functions list.