3

Given an RDF graph like this:

:Matrix [rdfs:label] :The Matrix .
:Matrix [movie:id] :23 .
:Matrix [movie:actor] :Keanu Reaves .
:Matrix [movie:actor] :Laurence Fishburne .
:Die Hard 3 [rdfs:label] :Die Hard 3 .
:Die Hard 3 [movie:id] :42 .
:Die Hard 3 [movie:actor] :Bruce Willis .
:Die Hard 3 [movie:actor] :Samuel L. Jackson .

and a query like this:

SELECT ?id ?name ?actor
WHERE {
  ?instance movie:id ?id .
  ?instance rdfs:label ?name .
  ?instance movie:actor ?actor .
}

I would expect a result like:

id | name       | actor
23 | The Matrix | Laurence Fishburne
23 | The Matrix | Keanu Reaves
42 | Die Hard 3 | Bruce Willis
42 | Die Hard 3 | Samuel L. Jackson

but instead I only get:

id | name       | actor
23 | The Matrix | Laurence Fishburne
42 | Die Hard 3 | Bruce Willis

What is the matter with that?

By the way, when I use this query:

SELECT *
WHERE {
  ?instance movie:id ?id .
  ?instance rdfs:label "The Matrix" .
  ?instance movie:actor ?actor .
}

The result is (as expected):

id | name       | actor
23 | The Matrix | Laurence Fishburne
23 | The Matrix | Keanu Reaves
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
s1ck
  • 158
  • 7
  • the sparql endpoint is http://www.linkedmdb.org/ which uses D2R and I'm using python SPARQLWrapper to query the endpoint. am i wrong with my expectation? – s1ck Oct 13 '12 at 12:18
  • Looks OK to me - all I can suggest is removing the rdfs:label triple pattern and/or putting it at the end. This should not make a difference, but then you should be getting the results you expect. – AndyS Oct 17 '12 at 08:35
  • thx! I'm currently using a workaround to get the relevant data but I will try out your suggestion and report if it worked out. But even if it would work, I would be really confused, because in my opinion the order of the triples to describe the subgraph doesn't matter. And I couldn't find anything in the w3c spec describing such an behaviour. – s1ck Oct 20 '12 at 12:03

1 Answers1

3

Using Jena's ARQ I was able to use the following query to get the sort of data you seem to be interested in from the Linked Movie DataBase SPARQL endpoint:

PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX movie: <http://data.linkedmdb.org/resource/movie/>

SELECT ?id ?filmTitle ?actorName WHERE { 
  VALUES ?filmTitle { "The Matrix" }
  SERVICE <http://data.linkedmdb.org/sparql> {
    ?film a movie:film ;
          movie:filmid ?id ;
          dcterms:title ?filmTitle ;
          movie:actor [ a movie:actor ;
                        movie:actor_name ?actorName ].
  }
}

data.n3 is an empty file, since arq requires a --data argument, even though the SERVICE keyword means that that we're querying remote data.

$ arq --query query.sparql --data data.n3 
-----------------------------------------------------------------------------------------
| id                                              | filmTitle    | actorName            |
=========================================================================================
| "38146"^^<http://www.w3.org/2001/XMLSchema#int> | "The Matrix" | "Keanu Reeves"       |
| "38146"^^<http://www.w3.org/2001/XMLSchema#int> | "The Matrix" | "Laurence Fishburne" |
| "38146"^^<http://www.w3.org/2001/XMLSchema#int> | "The Matrix" | "Hugo Weaving"       |
| "38146"^^<http://www.w3.org/2001/XMLSchema#int> | "The Matrix" | "Joe Pantoliano"     |
| "38146"^^<http://www.w3.org/2001/XMLSchema#int> | "The Matrix" | "Gloria Foster"      |
| "38146"^^<http://www.w3.org/2001/XMLSchema#int> | "The Matrix" | "Carrie-Anne Moss"   |
-----------------------------------------------------------------------------------------

Removing the VALUES ?filmTitle ... line broadens the search to all movies and their actors, of course.

The properties used in your query are different enough from the actual properties used in the LMDB that it's hard to see what themeaningful different might have been. It could have been rdfs:label instead of dcterms:title, or strings with or without language tags, and so on.

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353