查询与SPARQL链接的电影数据库(LMDB)(Querying the Linked Movie

2019-09-24 01:44发布

给定一个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

Answer 1:

使用耶拿的ARQ我能够使用以下查询来获取数据的排序,你似乎是有意从链接的电影数据库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 ...线扩大了搜索过程的所有电影和自己的演员。

在您的查询中使用的属性是从它很难看到有什么不同themeaningful可能已经在LMDB使用的实际性能足够不同。 这本来是rdfs:label ,而不是dcterms:title ,或串用或不用语言的标签,等等。



文章来源: Querying the Linked Movie Database (LMDB) with SPARQL