Virtuoso Open-Source Edition

  • Topic
  • Discussion
  • Are custom SPARQL extension functions supported? How can I use them?

    Virtuoso supports two ways to write one's own custom SPARQL extension functions:

    Use a Stored Procedure

    You can create a SQL 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 built-in function

    You can also make a built-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 SPARQL 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.

    This feature also allows you to use relevant functions from the Virtuoso SQL Functions Guide inside a SPARQL query.

    Related