如何从 dbpedia 的单个记录查询 sparql 中获取电影标题、3 位艺术家和 1 位导演?

How to get movie title, 3 artist, and 1 director on single record query sparql from dbpedia?

我正在尝试使用此查询获取电影属性。

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> 
SELECT ?movie ?movieTitle ?directorName ?DistributorName ?ArtistName ?Country (CONCAT(STR(MONTH(?ReleaseDate)), 
                 "/", 
                 STR(DAY(?ReleaseDate)), 
                 "/", 
                STR(YEAR(?ReleaseDate))) as ?displayDate)
WHERE{ 

  ?movie rdf:type <http://dbpedia.org/ontology/Film> .
  ?movie foaf:name ?movieTitle .
  ?movie dbpedia2:director ?directorName .
  ?movie dbpedia2:distributor ?DistributorName .
  ?movie dbpedia2:starring ?ArtistName .
  ?movie dbpedia2:country ?Country .
  ?movie <http://dbpedia.org/ontology/releaseDate> ?ReleaseDate  .

  FILTER(!isLiteral(?movieTitle) || langMatches(lang(?movieTitle), "EN"))
  FILTER ((?ReleaseDate >= "2001-01-01"^^xsd:date) && (?ReleaseDate < "2016-01-01"^^xsd:date))

}
ORDER BY DESC(?ReleaseDate)
LIMIT 500 OFFSET 0

但是,结果是这样的格式:

movieA - directorA - distributorA - ArtistA - Indonesia - 2012/06/10
movieA - directorA - distributorA - ArtistB - Indonesia - 2012/06/10
movieA - directorA - distributorA - ArtistC - Indonesia - 2012/06/10
movieB - directorD - distributorA - ArtistA - Malaysia - 2013/06/10
movieC - directorA - distributorS - ArtistD - France - 2013/03/10

我想通过这种格式获取数据:

movieA - directorA - distributorA - ArtistA,ArtistB,ArtistC - Indonesia - 2012/06/10
movieB - directorD - distributorA - ArtistA - Malaysia - 2013/06/10
movieC - directorA - distributorS - ArtistD - France - 2013/03/10

您可以使用 GroupConcat 执行此操作。因此,您可以修改查询以包括 (GROUP_CONCAT(?ArtistName ; separator=",") 作为 ?artists)。当我 运行 查询时,我注意到导演(列出多个导演的电影)等也可能发生同样的情况。因此,如果您希望每部电影都排成一行,您可能还需要将它们分组。

示例查询。

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> 
SELECT ?movie ?movieTitle ?directorName ?DistributorName(GROUP_CONCAT(?ArtistName ; separator=",") as ?artists) ?Country (CONCAT(STR(MONTH(?ReleaseDate)), 
                 "/", 
                 STR(DAY(?ReleaseDate)), 
                 "/", 
                STR(YEAR(?ReleaseDate))) as ?displayDate)
WHERE{ 

  ?movie rdf:type <http://dbpedia.org/ontology/Film> .
  ?movie foaf:name ?movieTitle .
  ?movie dbp:director ?directorName .
  ?movie dbp:distributor ?DistributorName .
  ?movie dbp:starring ?ArtistName .
  ?movie dbp:country ?Country .
  ?movie <http://dbpedia.org/ontology/releaseDate> ?ReleaseDate  .

  FILTER(!isLiteral(?movieTitle) || langMatches(lang(?movieTitle), "EN"))
  FILTER ((?ReleaseDate >= "2001-01-01"^^xsd:date) && (?ReleaseDate < "2016-01-01"^^xsd:date))

}
ORDER BY DESC(?ReleaseDate)
LIMIT 500 OFFSET 0