无法使用SPARQL从LinkedMDB检索具有高ID的电影 [英] Can't retrieve movies with high IDs from LinkedMDB with SPARQL

查看:85
本文介绍了无法使用SPARQL从LinkedMDB检索具有高ID的电影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 LinkedMDB SPARQL端点上运行以下查询,并且可以正常运行.有了它,我得到了我需要的所有有关ID为72的电影的导演的信息,这些导演是《泰坦尼克号》,所以我得到了关于詹姆斯·卡梅隆的信息.

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).
}

对于ID较高的电影,例如 ID为44396的星际迷航 ,如果我将72396替换为44396,则查询不会返回任何结果.不过,条目显然具有目录,ID和名称.为什么更改后的查询不起作用?

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?

推荐答案

SPARQL允许您编写72作为文字"72"^^xsd:integer的简写.如您所见,您可以毫无问题地检索ID为"72"^^xsd:integer的电影.但是,您要查找的另一部电影的ID为"44396"^^xsd:int(请注意,数据类型为xsd:int不是 xsd:integer).我不知道为什么为什么数据类型不同,但这足以帮助我们检索想要的内容:

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 .
}

请注意,我只是将实际的期望值放入查询模式中,而不是进行filter处理.我发现这要简单一些,如果查询引擎未进行优化,它的性能可能会更好(因为它没有构建大的结果集然后将其过滤掉).实际上,这可能解释了为什么在查询可以返回多少个结果有限制的情况下,使用变量和过滤器的语义等效查询不返回任何结果. (但这纯粹是猜测.)无论如何,以下查询不起作用,但我认为应该这样做:

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 ) 
}

查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆