Here is how it is done with an example from Linked Movie Database

prefix movie: <http://data.linkedmdb.org/resource/movie/>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>

select ?s ?p ?o
WHERE {
    {
       <http://data.linkedmdb.org/resource/director/102> ?p ?o1 .
       optional {?o1 rdfs:label ?o.}
       BIND (<http://data.linkedmdb.org/resource/director/102> as ?s)
       FILTER(bound(?o))
    }
    UNION
    {
       <http://data.linkedmdb.org/resource/director/102> ?p ?o .
       optional {?o rdfs:label ?label.}
       BIND (<http://data.linkedmdb.org/resource/director/102> as ?s)
       FILTER(!bound(?label))
    }
}
order by ?p
limit 25
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s