4

I'm running the following query at the LinkedMDB SPARQL endpoint and it works. With it, I get all the information that I need about the director of the movie with id 72, which is Titanic, so I get information about James Cameron.

PREFIX mdb: <http://data.linkedmdb.org/resource/movie/>
SELECT ?director?nombre_director?id_director WHERE {
  ?pelicula mdb:filmid ?id .
  ?pelicula <http://data.linkedmdb.org/resource/movie/director> ?director .
  ?director <http://data.linkedmdb.org/resource/movie/director_name> ?nombre_director .
  ?director <http://data.linkedmdb.org/resource/movie/director_directorid> ?id_director .
  FILTER (?id = 72).
}

With movies that have a higher ID, e.g., example Star Trek with ID 44396, if I replace 72 with 44396, the query returns no results. The entry clearly has a directory, id, and name, though. Why doesn't the altered query work?

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
chomp
  • 1,352
  • 13
  • 31

1 Answers1

6

SPARQL lets you write 72 as shorthand for the literal "72"^^xsd:integer. As you've seen, you can retrieve the film with the ID "72"^^xsd:integer without a problem. However, the other film that you're looking for has the id "44396"^^xsd:int (note that the datatype is xsd:int, not xsd:integer). I don't know why the datatype is different, but it's enough to help us retrieve what we want:

PREFIX mdb: <http://data.linkedmdb.org/resource/movie/>
SELECT ?director?nombre_director?id_director WHERE {
  ?pelicula mdb:filmid "44396"^^xsd:int .
  ?pelicula <http://data.linkedmdb.org/resource/movie/director> ?director .
  ?director <http://data.linkedmdb.org/resource/movie/director_name> ?nombre_director .
  ?director <http://data.linkedmdb.org/resource/movie/director_directorid> ?id_director .
}

SPARQL results (one)

director          nombre_director  id_director
----------------------------------------------
db:director/9025  "J.J. Abrams"    9025

Note that rather than filtering, I just put the actual desired value into the query pattern. I find this to be a bit simpler, and if the query engine isn't optimized, it might be better performing (since it's not building a big result set and then filtering things out). In fact, that might explain why the semantically equivalent query that uses a variable and a filter returns no results, if there's a limit on how many results the query can return. (But this is pure speculation.) In any case, the following query doesn't work, but I think that it should:

PREFIX mdb: <http://data.linkedmdb.org/resource/movie/>
SELECT ?director?nombre_director?id_director WHERE {
  ?pelicula mdb:filmid ?id .
  ?pelicula <http://data.linkedmdb.org/resource/movie/director> ?director .
  ?director <http://data.linkedmdb.org/resource/movie/director_name> ?nombre_director .
  ?director <http://data.linkedmdb.org/resource/movie/director_directorid> ?id_director .
  filter ( ?id = "44396"^^xsd:int ) 
}

SPARQL results (none)

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
  • Filters are value based so "filter ( ?id = 44396 )" should work but the endpoint says it's running "Joseki 3.0 dev". When I tried, there was no match for "?pelicula mdb:filmid ?id" at an ?id that large of any datatype. If you do get a match for that, then the endpoint is behaving funny. – AndyS Feb 26 '14 at 11:58
  • @AndyS Just to make sure I'm not just imagining things, you do see the result for the first query in my answer where I've put in the triple pattern `?pelicula mdb:filmid "44396"^^xsd:int`, right? If that's matching, then the data must be there, right? I think there is something strange at that endpoint; there were other strange results described in http://stackoverflow.com/q/18783869/1281433 . – Joshua Taylor Feb 26 '14 at 14:48
  • @AndyS Ah, found the specific bit in http://stackoverflow.com/q/18783869/1281433 I'd been looking for: the OP there writes in the question "I've noticed that if I only search without filter and just print all the movies in the database, it looks like LinkedMDB have some sort of LIMIT on 2557 so that the webpage won't crash. And it looks like the FILTER only filters those 2557 movies. Is there a way to retrieve more movies?" – Joshua Taylor Feb 26 '14 at 15:02
  • I have something i think, if i use `PREFIX xsd: `, it works better than without it (without it, i sometimes get a error that says "Unresolved prefixed name: xsd:int" when the query doesn't work) – chomp Feb 26 '14 at 21:44
  • @chomp I was running queries in the web interface where the `xsd:` prefix (among others) is predefined. If you are running in a different way, you may need to define the prefix in your query. I think that's a different issue, though; not the same as the one that's causing the main problem here. – Joshua Taylor Feb 26 '14 at 21:47
  • Sorry @Joshua Taylor , but the sparql endpoint that i can find with xsd:int predefined it's dbpedia, i don´t see in the LinkedMDB sparql endpoint any predefined prefix's (maybe exists a way for creating, i don't know) , are you sure that you aren't mixing both endpoints? Because this can be the case for your second answer, if you can't see those results. – chomp Feb 26 '14 at 22:17
  • @chomp I'm sorry, I don't understand what you mean. This data was about LinkedMDB data, so you're running queries against the LinkedMDB endpoint, not the DBpedia endpoint, right? If you follow either of the "SPARQL results" links in my answer, you'll be at http://www.linkedmdb.org/snorql/, where there are 12 predefined prefixes, of which `xsd:` is one. – Joshua Taylor Feb 26 '14 at 22:24
  • @Joshua Taylor yes, i'm always running queries against LinkedMDB endpoint. Sorry for the offtopic, it isn't related to the main problem here, as you already say ;) – chomp Feb 27 '14 at 20:53