【问题标题】:How do I write a SPARQL query for this如何为此编写 SPARQL 查询
【发布时间】:2020-05-07 20:44:40
【问题描述】:

我如何编写一个 SPARQL 查询来检索导演名为“George”的电影的所有电影和联合导演。

三元组

@prefix : <http://org.example/> .

:movie1 :hasDirectors :d1, :d2, :d3 .
:movie2 :hasDirectors :d3, :d4 .
:movie3 :hasDirectors :d1, :d3

:d1 :name "George" .
:d2 :name "Jack" .
:d6 :name "Raj" .
:d3 :name "Henry" .
:d4 :name "Williams" .

【问题讨论】:

  • 那么,到目前为止,您尝试了什么?我的意思是,如果您根本不了解 SPARQL,我们无法为您做所有事情。那不会有帮助的。您至少应该能够查询 "directors with name "George" " 这只是一个三元组模式。然后通过另一个三元组模式附加到电影的路径,然后一个以获取这部电影的所有导演,最后你需要一个过滤器来从联合导演中排除“乔治”。
  • PREFIX rdf: w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: w3.org/2000/01/rdf-schema#> PREFIX: org.example> SELECT ?movie ?name WHERE { ?movie :hasDirectors ?d. ?d : 名称 ? 名称。过滤器(?name="乔治")。 } 我使用这个查询得到了导演“乔治”的所有电影
  • 好吧,你就快到了:SELECT ?movie ?name ?coDirectors WHERE { ?movie :hasDirectors ?d. ?d :name "George". ?movie :hasDirectors ?coDirectors . FILTER(?coDirectors != "George") }
  • 非常感谢。我对其进行了一些修改,以便给我联合导演的名字。 SELECT ?movie ?name ?coDirectors_name WHERE { ?movie :hasDirectors ?d. ?d :name ?name. FILTER(?name="George") ?movie :hasDirectors ?coDirectors . ?coDirectors :name ?coDirectors_name FILTER(?coDirectors_name != "George") }

标签: sparql rdf jena semantic-web


【解决方案1】:

正如在 cmets 中发布的那样,查询应如下所示:

SELECT ?movie ?name ?coDirectors_name WHERE { ?movie :hasDirectors ?d. ?d :name ?
name. FILTER(?name="George") ?movie :hasDirectors ?coDirectors . ?coDirectors :name 
?coDirectors_name FILTER(?coDirectors_name != "George") }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-02-29
    • 1970-01-01
    • 1970-01-01
    • 2021-01-15
    • 2011-10-30
    • 2011-02-20
    • 2015-08-14
    • 1970-01-01
    相关资源
    最近更新 更多