Can't retrieve movies with high IDs from LinkedMDB with SPARQL

折月煮酒 提交于 2019-12-19 08:52:24

问题


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?


回答1:


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)



来源:https://stackoverflow.com/questions/22021040/cant-retrieve-movies-with-high-ids-from-linkedmdb-with-sparql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!