Virtuoso SPARQL 1.1. Built-In Functions Usage Examples
What?
This guide contains Virtuoso SPARQL 1.1. Built-In Functions Usage Examples Usage example queries which you can run against any SPARQL endpoint that supports SPARQL 1.1 and the ability to allow a verified user perform INSERT operations.Why?
Using built-In functions provides flexibility to build accurate and complex queries.How?
Here are examples showcasing Virtuoso's support for this functionality:
Functions on RDF Terms
-
isNumeric: See live results
SELECT * WHERE { ?x ?t ?o . FILTER isNumeric(?o) } LIMIT 10
Functions on Strings
-
STRDT: See live results
SELECT ?o, STRDT("123", xsd:integer) WHERE { ?x ?t ?o . } LIMIT 10
-
STRLANG: See live results
SELECT ?o, STRLANG("chat", "en") WHERE { ?x ?t ?o . } LIMIT 10
-
STRLEN: See live results
SELECT ?o, STRLEN(?t) WHERE { ?x ?t ?o . } LIMIT 10
-
SUBSTR: See live results ****
SELECT DISTINCT ?name1 WHERE { ?x <http://xmlns.com/foaf/0.1/name> ?name1 . ?x <http://xmlns.com/foaf/0.1/mbox> ?mbox1 . ?y <http://xmlns.com/foaf/0.1/name> ?name2 . ?y <http://xmlns.com/foaf/0.1/mbox> ?mbox2 . FILTER (?mbox1 = ?mbox2 && ?name1 != ?name2) . FILTER( bif:length(str(?name1)) > 2 && SUBSTR(?name1, 1) LIKE "%Kingsley%" ) } LIMIT 10
-
UCASE: See live results
SELECT UCASE(?name1 ) WHERE { ?x <http://xmlns.com/foaf/0.1/name> ?name1 . } LIMIT 10
-
LCASE: See live results
SELECT LCASE(?name1 ) WHERE { ?x <http://xmlns.com/foaf/0.1/name> ?name1 . } LIMIT 10
-
strStarts: See live results
SELECT ?name1 WHERE { ?x <http://xmlns.com/foaf/0.1/name> ?name1 . FILTER ( strStarts(?name1, "Kingsley") ). } LIMIT 10
-
strEnds: See live results
PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT distinct ?name1 WHERE { ?x foaf:name ?name1 . ?x foaf:mbox ?mbox1 . FILTER ( strEnds(?name1, "hen") ). } LIMIT 10
-
encode_for_uri: See live results
SELECT encode_for_uri(?name1) as ?name WHERE { ?x <http://xmlns.com/foaf/0.1/name> ?name1 . FILTER ( bif:contains(?name1, "France") ). } LIMIT 10
-
contains: See live results
SELECT * WHERE { ?s ?p ?o . FILTER (if (isliteral(?o), contains(str(?o), "Virtuoso"), false)) } LIMIT 10
-
concat: See live results
SELECT concat (?name1 ,?name2 ) WHERE { ?x <http://xmlns.com/foaf/0.1/name> ?name1 . ?x <http://xmlns.com/foaf/0.1/mbox> ?mbox1 . ?y <http://xmlns.com/foaf/0.1/name> ?name2 . ?y <http://xmlns.com/foaf/0.1/mbox> ?mbox2 . FILTER (?mbox1 = ?mbox2 && ?name1 != ?name2) . FILTER ( contains(?name1, "Dan") ). } LIMIT 10
-
langMatches: See live results
SELECT ?title WHERE { ?x <http://purl.org/dc/elements/1.1/title> ?title . FILTER langMatches( lang(?title), "EN" ) } LIMIT 10
-
regex: See live results
SELECT ?name WHERE { ?x <http://xmlns.com/foaf/0.1/name> ?name . FILTER regex(?name, "^ali", "i") . } LIMIT 10
Functions on Numerics
-
round: See live results
SELECT round(?o) WHERE { ?s a ?c . ?s geo:geometry ?geo . ?s ?p ?o . FILTER ( bif:isnumeric(?o) ) } LIMIT 10
-
abs: See live results
SELECT abs (?o) ?geo WHERE { ?s a ?c . ?s geo:geometry ?geo . ?s ?p ?o . FILTER (bif:isnumeric(?o) ) } LIMIT 10
-
ceil: See live results
SELECT ceil (?o) WHERE { ?s a ?c . ?s geo:geometry ?geo . ?s ?p ?o . FILTER (bif:isnumeric(?o) ) } LIMIT 10
-
floor: See live results
SELECT floor(?o) WHERE { ?s a ?c . ?s geo:geometry ?geo . ?s ?p ?o . FILTER (bif:isnumeric(?o) ) } LIMIT 10
-
rand: See live results
SELECT floor(?o) rand () WHERE { ?s a ?c . ?s geo:geometry ?geo . ?s ?p ?o . FILTER (bif:isnumeric(?o) ) } LIMIT 10
Functions on Dates and Times
-
now: See live results
SELECT now() WHERE { ?s ?p ?o } LIMIT 1
-
year: See live results
SELECT year("2011-01-10T14:45:13.815-05:00"^^xsd:dateTime) WHERE { ?s ?p ?o } LIMIT 1
-
month: See live results
SELECT month ("2011-01-10T14:45:13.815-05:00"^^xsd:dateTime) WHERE { ?s ?p ?o } LIMIT 1
-
day: See live results
SELECT day("2011-01-10T14:45:13.815-05:00"^^xsd:dateTime) WHERE { ?s ?p ?o } LIMIT 1
-
hours: See live results
SELECT hours("2011-01-10T14:45:13.815-05:00"^^xsd:dateTime) WHERE { ?s ?p ?o } LIMIT 1
-
minutes: See live results
SELECT minutes("2011-01-10T14:45:13.815-05:00"^^xsd:dateTime) WHERE { ?s ?p ?o } LIMIT 1
-
seconds: See live results
SELECT seconds ("2011-01-10T14:45:13.815-05:00"^^xsd:dateTime) WHERE { ?s ?p ?o } LIMIT 1
-
TIMEZONE: See live results
SELECT TIMEZONE ("2011-01-10T14:45:13.815-05:00"^^xsd:dateTime) WHERE { ?s ?p ?o } LIMIT 1
-
tz: See live results
SELECT tz("2011-01-10T14:45:13.815-05:00"^^xsd:dateTime) WHERE { ?s ?p ?o } LIMIT 1
Hash Functions
-
MD5: See live results
SELECT MD5 ('test') WHERE { ?s ?p ?o } LIMIT 1
-
SHA1: See live results
SELECT SHA1 ('test') WHERE { ?s ?p ?o } LIMIT 1
-
SHA256: See live results
SELECT SHA256 ('test') WHERE { ?s ?p ?o } LIMIT 1
-
SHA384: See live results
SELECT SHA384('test') WHERE { ?s ?p ?o } LIMIT 1
-
SHA512: See live results
SELECT SHA512('test') WHERE { ?s ?p ?o } LIMIT 1
Related
- SPARQL 1.1. Functions Definitions
- SPARQL Protocol (HTTP based Query Service)
- Virtuoso Tips and Tricks Collection
- Virtuoso SPARQL 1.1 Usage Examples Collection
- Virtuoso SPARQL 1.1 Syntax Tutorial
- Virtuoso Documentation