使用SPARQL查询链接的电影数据库(LMDB) [英] Querying the Linked Movie Database (LMDB) with SPARQL

查看:140
本文介绍了使用SPARQL查询链接的电影数据库(LMDB)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出如下RDF图:

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

和类似的查询:

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

但是我只能得到:

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

那是怎么回事?

顺便说一句,当我使用此查询时:

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

推荐答案

使用耶拿(Jena)的ARQ,我可以使用以下查询从链接的电影数据库SPARQL端点获取您似乎感兴趣的数据类型:

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是一个空文件,因为arq需要一个--data自变量,即使SERVICE关键字表示我们正在查询远程数据.

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"   |
-----------------------------------------------------------------------------------------

当然,删除VALUES ?filmTitle ...行会使搜索范围扩大到所有电影及其演员.

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

查询中使用的属性与LMDB中使用的实际属性有足够的差异,很难知道可能有什么有意义的差异.可能是rdfs:label而不是dcterms:title,或者是带有或不带有语言标签的字符串,依此类推.

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.

这篇关于使用SPARQL查询链接的电影数据库(LMDB)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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