%META:TOPICPARENT{name="VirtTipsAndTricksSPARQL11FeaturesExamplesCollection"}%
---+ Using SPARQL 1.1 Property Paths in Virtuoso
%TOC%
---++ What are Property Paths?
A property path is a possible route through a graph between two graph nodes.
---++ Why use SPARQL 1.1 Property Paths?
SPARQL 1.1 Property Paths are syntactic sugar, allowing for more concise expression
of some SPARQL basic graph patterns, and adding the ability to match paths of arbitrary
length. They are not necessary nor required, but they can make queries shorter and
easier to both write and read.
---++ How can I use SPARQL 1.1 Property Paths with Virtuoso?
Here are some examples demonstrating Virtuoso's support of SPARQL 1.1 Property Paths. These
example queries should work against any SPARQL endpoint that supports SPARQL 1.1 and has the
ability to allow a verified user to perform INSERT operations.
---+++ Basic Usage
## Basic
SELECT DISTINCT ?x ?name
WHERE
{
?x foaf:mbox
; foaf:knows/foaf:name ?name
}
* [[http://bit.ly/1fqlgGl][View the SPARQL Query Definition via SPARQL Protocol URL]]
* [[http://bit.ly/1fql7CM][View the SPARQL Query Results via SPARQL Protocol URL]]
---+++ Usage of Sequence
SELECT DISTINCT ?x
?name
WHERE
{
?x foaf:mbox
; foaf:knows/foaf:knows/foaf:name ?name
}
* [[http://bit.ly/1bLsYtQ][View the SPARQL Query Definition via SPARQL Protocol URL]]
* [[http://bit.ly/1crUpFN][View the SPARQL Query Results via SPARQL Protocol URL]]
---+++ Usage of Inverse
## Mutual foaf:knows relationships: ?x knows someone who knows ?x
SELECT DISTINCT ?x
?name
WHERE
{
?x foaf:mbox
; foaf:knows/^foaf:knows ?y
. ?y foaf:name ?name
FILTER ( ?x != ?y )
}
* [[http://bit.ly/UmERvA][View the SPARQL Query Definition via SPARQL Protocol URL]]
* [[http://bit.ly/RzOVVm][View the SPARQL Query Results via SPARQL Protocol URL]]
---+++ Usage of Negation of a Unary Operator
SELECT DISTINCT *
WHERE
{
?x !rdf:type foaf:Person
}
LIMIT 10
* [[http://bit.ly/SvKQP1][View the SPARQL Query Definition via SPARQL Protocol URL]]
* [[http://bit.ly/VyqogS][View the SPARQL Query Results via SPARQL Protocol URL]]
---+++ Constructing an Object using Terms from vCard, FOAF, and OWL
1 Assume the following Raw Data Representation in Turtle of a Address Book Data Object constructed
using terms from the vCard vocabulary:
<#vcardRick> "Richard"
; "Mutt"
;
.
<#vcardAl> "Alan"
; "Smithee"
;
.
1 Load the sample data:
PREFIX dc:
INSERT DATA
{
GRAPH
{
<#vcardRick> "Richard"
; "Mutt"
;
.
<#vcardAl> "Alan"
; "Smithee"
;
} }
* [[http://bit.ly/14FAx04][View the SPARQL Query Definition via SPARQL Protocol URL]]
* [[http://bit.ly/WQKi9i][View the SPARQL Query Results via SPARQL Protocol URL]]
1 Assume the following Raw Data Representation in Turtle of a Address Book Data Object constructed using terms from the FOAF vocabulary:
<#foafBill> "Billy"
; "Shears"
;
.
<#foafNate> "Nanker"
; "Phelge"
;
.
1 Load the sample data:
PREFIX dc:
INSERT DATA
{
GRAPH
{
<#foafBill> "Billy"
; "Shears"
;
.
<#foafNate> "Nanker"
; "Phelge"
;
} }
* [[http://bit.ly/UDTwaG][View the SPARQL Query Definition via SPARQL Protocol URL]]
* [[http://bit.ly/12vEk1w][View the SPARQL Query Results via SPARQL Protocol URL]]
1 Assume the following Raw Data Representation in Turtle of a mapping oriented Data Object constructed using terms from the OWL Ontology that describe entity relationship semantics:
# This data object is comprised of statements (triples) that map certain
# properties across the vCard and FOAF vocabularies.
#
# These mappings express machine readable entity relationship semantics
# usable by a Reasoner to produce (by inference) smart query results.
.
.
.
1 Load the sample data:
PREFIX dc:
INSERT DATA
{
GRAPH
{
.
.
} }
* [[http://bit.ly/Xnawyj][View the SPARQL Query Definition via SPARQL Protocol URL]]
* [[http://bit.ly/14Uvmut][View the SPARQL Query Results via SPARQL Protocol URL]]
1 Query the graphs:
PREFIX owl:
SELECT bif:sprintf ( "<%s> = %s\t<%s> = %s"
, str(?givenNameProp)
, ?fn
, str(?lastNameProp)
, ?ln
)
FROM
FROM
FROM
WHERE
{
(owl:equivalentProperty|^owl:equivalentProperty)* ?givenNameProp
.
(owl:equivalentProperty|^owl:equivalentProperty)* ?lastNameProp
. ?s
?givenNameProp ?fn
; ?lastNameProp ?ln
}
LIMIT 10
* [[http://bit.ly/Pw5KjO][View the SPARQL Query Definition via SPARQL Protocol URL]]
* [[http://bit.ly/1hnpbRY][View the SPARQL Query Results via SPARQL Protocol URL]]
---++ Related
* [[http://www.w3.org/TR/sparql11-property-paths/][W3 documentation of SPARQL 1.1. Property Paths]]
* [[VirtTipsAndTricksGuide][Virtuoso Tips and Tricks Collection]]
* [[VirtTipsAndTricksSPARQL11FeaturesExamplesCollection][Examples of SPARQL 1.1 Feature Usage in Virtuoso]]
* [[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]]