【问题标题】:Querying the Linked Movie Database (LMDB) with SPARQL使用 SPARQL 查询链接的电影数据库 (LMDB)
【发布时间】:2012-10-12 18:19:17
【问题描述】:

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

【问题讨论】:

  • sparql 端点是linkedmdb.org,它使用 D2R,我使用 python SPARQLWrapper 来查询端点。我的期望错了吗?
  • 对我来说看起来不错 - 我只能建议删除 rdfs:label 三重模式和/或将其放在最后。这不应该有什么不同,但是你应该得到你期望的结果。
  • 谢谢!我目前正在使用一种解决方法来获取相关数据,但我会尝试您的建议并报告是否可行。但即使它会起作用,我也会很困惑,因为在我看来,描述子图的三元组的顺序并不重要。而且我在 w3c 规范中找不到任何描述这种行为的内容。

标签: rdf sparql semantic-web linked-data


【解决方案1】:

使用 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,或者带有或不带有语言标签的字符串,等等。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-24
    • 1970-01-01
    • 1970-01-01
    • 2012-01-09
    相关资源
    最近更新 更多