Attributes | Values |
---|
type
| |
Date Created
| |
Date Modified
| |
label
| - VirtTipsAndTricksSPARQL11BuiltInF
|
maker
| |
Title
| - VirtTipsAndTricksSPARQL11BuiltInF
|
isDescribedUsing
| |
has creator
| |
content
| - %META:TOPICPARENT{name="VirtTipsAndTricksSPARQL11FeaturesExamplesCollection"}%
---+ Virtuoso SPARQL 1.1. Built-In Functions Usage Examples
%TOC%
---++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
* <b>isNumeric</b>: [[http://bit.ly/X5ZawI][See live results]]
<verbatim>
SELECT *
WHERE
{
?x ?t ?o .
FILTER isNumeric(?o)
}
LIMIT 10
</verbatim>
---+++Functions on Strings
* <b>STRDT</b>: [[http://bit.ly/XPpVGs][See live results]]
<verbatim>
SELECT ?o, STRDT("123", xsd:integer)
WHERE
{
?x ?t ?o .
}
LIMIT 10
</verbatim>
* <b>STRLANG</b>: [[http://bit.ly/VmEenq][See live results]]
<verbatim>
SELECT ?o, STRLANG("chat", "en")
WHERE
{
?x ?t ?o .
}
LIMIT 10
</verbatim>
* <b>STRLEN</b>: [[http://bit.ly/14qoF1P][See live results]]
<verbatim>
SELECT ?o, STRLEN(?t)
WHERE
{
?x ?t ?o .
}
LIMIT 10
</verbatim>
* <b>SUBSTR</b>: [[http://bit.ly/1Nz9PfV][See live results]] ****
<verbatim>
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
</verbatim>
* <b><nowiki>UCASE</nowiki></b>: [[http://bit.ly/1JAMSaT][See live results]]
<verbatim>
SELECT UCASE(?name1 )
WHERE
{
?x <http://xmlns.com/foaf/0.1/name> ?name1 .
}
LIMIT 10
</verbatim>
* <b><nowiki>LCASE</nowiki></b>: [[http://bit.ly/1GQLtbS1][See live results]]
<verbatim>
SELECT LCASE(?name1 )
WHERE
{
?x <http://xmlns.com/foaf/0.1/name> ?name1 .
}
LIMIT 10
</verbatim>
* <b><nowiki>strStarts</nowiki></b>: [[http://bit.ly/1Hy8gOu][See live results]]
<verbatim>
SELECT ?name1
WHERE
{
?x <http://xmlns.com/foaf/0.1/name> ?name1 .
FILTER ( strStarts(?name1, "Kingsley") ).
}
LIMIT 10
</verbatim>
* <b><nowiki>strEnds</nowiki></b>: [[http://bit.ly/1FUNDGB][See live results]]
<verbatim>
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
</verbatim>
* <b><nowiki>encode_for_uri</nowiki></b>: [[http://bit.ly/1JALipk][See live results]]
<verbatim>
SELECT encode_for_uri(?name1) as ?name
WHERE
{
?x <http://xmlns.com/foaf/0.1/name> ?name1 .
FILTER ( bif:contains(?name1, "France") ).
}
LIMIT 10
</verbatim>
* <b>contains</b>: [[http://bit.ly/1oxy85a][See live results]]
<verbatim>
SELECT *
WHERE
{
?s ?p ?o .
FILTER (if (isliteral(?o), contains(str(?o), "Virtuoso"), false))
}
LIMIT 10
</verbatim>
* <b>concat</b>: [[http://bit.ly/1zkMZoY][See live results]]
<verbatim>
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
</verbatim>
* <b>langMatches</b>: [[http://bit.ly/1hnvTYg][See live results]]
<verbatim>
SELECT ?title
WHERE
{
?x <http://purl.org/dc/elements/1.1/title> ?title .
FILTER langMatches( lang(?title), "EN" )
}
LIMIT 10
</verbatim>
* <b>regex</b>: [[http://bit.ly/Wvgz5K][See live results]]
<verbatim>
SELECT ?name
WHERE
{
?x <http://xmlns.com/foaf/0.1/name> ?name .
FILTER regex(?name, "^ali", "i") .
}
LIMIT 10
</verbatim>
---+++Functions on Numerics
* <b>round</b>: [[http://bit.ly/14qpOXh][See live results]]
<verbatim>
SELECT round(?o)
WHERE
{
?s a ?c .
?s geo:geometry ?geo .
?s ?p ?o .
FILTER ( bif:isnumeric(?o) )
}
LIMIT 10
</verbatim>
* <b>abs</b>: [[http://bit.ly/XI03LQ][See live results]]
<verbatim>
SELECT abs (?o) ?geo
WHERE
{
?s a ?c .
?s geo:geometry ?geo .
?s ?p ?o .
FILTER (bif:isnumeric(?o) )
}
LIMIT 10
</verbatim>
* <b>ceil</b>: [[http://bit.ly/117XiWS][See live results]]
<verbatim>
SELECT ceil (?o)
WHERE
{
?s a ?c .
?s geo:geometry ?geo .
?s ?p ?o .
FILTER (bif:isnumeric(?o) )
}
LIMIT 10
</verbatim>
* <b>floor</b>: [[http://bit.ly/126XTNt][See live results]]
<verbatim>
SELECT floor(?o)
WHERE
{
?s a ?c .
?s geo:geometry ?geo .
?s ?p ?o .
FILTER (bif:isnumeric(?o) )
}
LIMIT 10
</verbatim>
* <b>rand</b>: [[http://bit.ly/14rT5lj][See live results]]
<verbatim>
SELECT floor(?o) rand ()
WHERE
{
?s a ?c .
?s geo:geometry ?geo .
?s ?p ?o .
FILTER (bif:isnumeric(?o) )
}
LIMIT 10
</verbatim>
---+++Functions on Dates and Times
* <b>now</b>: [[http://bit.ly/1CWJOA4][See live results]]
<verbatim>
SELECT now()
WHERE
{
?s ?p ?o
}
LIMIT 1
</verbatim>
* <b>year</b>: [[http://bit.ly/1waxzRP][See live results]]
<verbatim>
SELECT year("2011-01-10T14:45:13.815-05:00"^^xsd:dateTime)
WHERE
{
?s ?p ?o
}
LIMIT 1
</verbatim>
* <b>month</b>: [[http://bit.ly/ZGV4na][See live results]]
<verbatim>
SELECT month ("2011-01-10T14:45:13.815-05:00"^^xsd:dateTime)
WHERE
{
?s ?p ?o
}
LIMIT 1
</verbatim>
* <b>day</b>: [[http://bit.ly/1t5hbzU][See live results]]
<verbatim>
SELECT day("2011-01-10T14:45:13.815-05:00"^^xsd:dateTime)
WHERE
{
?s ?p ?o
}
LIMIT 1
</verbatim>
* <b>hours</b>: [[http://bit.ly/1zkNi2Q][See live results]]
<verbatim>
SELECT hours("2011-01-10T14:45:13.815-05:00"^^xsd:dateTime)
WHERE
{
?s ?p ?o
}
LIMIT 1
</verbatim>
* <b>minutes</b>: [[http://bit.ly/1t5hdYI][See live results]]
<verbatim>
SELECT minutes("2011-01-10T14:45:13.815-05:00"^^xsd:dateTime)
WHERE
{
?s ?p ?o
}
LIMIT 1
</verbatim>
* <b>seconds</b>: [[http://bit.ly/10oe4bp][See live results]]
<verbatim>
SELECT seconds ("2011-01-10T14:45:13.815-05:00"^^xsd:dateTime)
WHERE
{
?s ?p ?o
}
LIMIT 1
</verbatim>
* <b>TIMEZONE</b>: [[http://bit.ly/1tfTogz][See live results]]
<verbatim>
SELECT TIMEZONE ("2011-01-10T14:45:13.815-05:00"^^xsd:dateTime)
WHERE
{
?s ?p ?o
}
LIMIT 1
</verbatim>
* <b>tz</b>: [[http://bit.ly/ZNWY5S][See live results]]
<verbatim>
SELECT tz("2011-01-10T14:45:13.815-05:00"^^xsd:dateTime)
WHERE
{
?s ?p ?o
}
LIMIT 1
</verbatim>
---+++Hash Functions
* <b>MD5</b>: [[http://bit.ly/1x9GAau][See live results]]
<verbatim>
SELECT MD5 ('test')
WHERE
{
?s ?p ?o
}
LIMIT 1
</verbatim>
* <b>SHA1</b>: [[http://bit.ly/1t5hpan][See live results]]
<verbatim>
SELECT SHA1 ('test')
WHERE
{
?s ?p ?o
}
LIMIT 1
</verbatim>
* <b>SHA256</b>: [[http://bit.ly/1t5hqed][See live results]]
<verbatim>
SELECT SHA256 ('test')
WHERE
{
?s ?p ?o
}
LIMIT 1
</verbatim>
* <b>SHA384</b>: [[http://bit.ly/1wtOddL][See live results]]
<verbatim>
SELECT SHA384('test')
WHERE
{
?s ?p ?o
}
LIMIT 1
</verbatim>
* <b>SHA512</b>: [[http://bit.ly/VlnjQo][See live results]]
<verbatim>
SELECT SHA512('test')
WHERE
{
?s ?p ?o
}
LIMIT 1
</verbatim>
---++Related
* [[http://www.w3.org/TR/sparql11-query/#SparqlOps][SPARQL 1.1. Functions Definitions]]
* [[http://www.w3.org/TR/rdf-sparql-protocol/][SPARQL Protocol (HTTP based Query Service)]]
* [[VirtTipsAndTricksGuide][Virtuoso Tips and Tricks Collection]]
* [[VirtTipsAndTricksSPARQL11FeaturesExamplesCollection][Virtuoso SPARQL 1.1 Usage Examples Collection]]
* [[http://virtuoso.openlinksw.com/tutorials/sparql/SPARQL_Tutorials_Part_9/SPARQL_Tutorials_Part_9.html][Virtuoso SPARQL 1.1 Syntax Tutorial]]
* [[http://docs.openlinksw.com/virtuoso/rdfsparql.html][Virtuoso Documentation]]
|
id
| - 2368a20ae9704f1b6cdd7ca83bd28990
|
link
| |
has container
| |
http://rdfs.org/si...ices#has_services
| |
atom:title
| - VirtTipsAndTricksSPARQL11BuiltInF
|
links to
| |
atom:source
| |
atom:author
| |
atom:published
| |
atom:updated
| |
topic
| |
is made
of | |
is container of
of | |
is link
of | |
is http://rdfs.org/si...vices#services_of
of | |
is creator of
of | |
is atom:entry
of | |
is atom:contains
of | |