3

给定这样的 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 .
}

我希望得到如下结果:

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

那是怎么回事?

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

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

结果是(如预期的那样):

id | name       | actor
23 | The Matrix | Laurence Fishburne
23 | The Matrix | Keanu Reaves
4

1 回答 1

3

使用 Jena 的 ARQ,我能够使用以下查询从 Linked Movie DataBase SPARQL 端点获取您似乎感兴趣的数据:

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关键字意味着我们正在查询远程数据。

$ 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 ...条线会将搜索范围扩大到所有电影及其演员。

您的查询中使用的属性与 LMDB 中使用的实际属性有很大的不同,很难看出可能有什么有意义的不同。它可以rdfs:label代替dcterms:title,或者带有或不带有语言标签的字符串,等等。

于 2013-06-29T16:35:29.223 回答