给出这样的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
答案 0 :(得分: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
,或带或不带语言标记的字符串,依此类推。