0

我正在编写一个联合查询来获取基于 dbpedia 中电影的书籍,然后使用 dbpedia 中的电影名称来检索相应的 imdblink 链接。添加linkedmdb的服务时,我得到一个空集。

这是我的代码

PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX movie: <http://data.linkedmdb.org/resource/movie/>
PREFIX dc: <http://purl.org/dc/terms/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dbp: <http://dbpedia.org/property/>

 SELECT distinct ?name ?author ?filmname ?imdbID WHERE {
 SERVICE <http://dbpedia.org/sparql> {
    ?book rdf:type dbo:Book .
   ?book foaf:name ?name .
   ?book dbp:author ?author .
   ?author foaf:name ?authname .
  ?book ^dbo:basedOn ?movie . 
   ?movie a dbo:Film .
   ?movie foaf:name ?filmname
   FILTER (str(?name) IN ("Royal Flash","White Oleander", "Possession: A Romance", "Misery", "Intensity", "The War of The Roses", "Momo", "The Sicilian", "Derailed", "Ragtime"))

}
SERVICE <http://data.linkedmdb.org/sparql> {
    ?filmname foaf:page ?imdbID .  
    ?filmname dc:title ?title .
 FILTER(regex(str(?imdbID), "www.imdb.com" ) )
}

}

我正在使用以下端点http://www.sparql.org/query.html

4

1 回答 1

0

?filename由于变量,这不起作用

  1. 因此,在您得到的第一SERVICE个子句中 ?movie foaf:name ?filmname,这些是字符串文字
  2. 在第二SERVICE个子句中?filmname是 URI

如果您分别运行两个 SPARQL 查询,将会很容易看出。

您要做的是匹配标题,即更改

?filmname dc:title ?title .

?filmname dc:title ?filmname .

请注意,由于字符串类型不同,这可能不起作用,例如带有和不带有语言标签等。在这种情况下,您将不得不再次匹配词法形式,即使用临时变量?filmname1?filmname2使用

FILTER(str(?filmname1) = str(?filmname2))

PREFIX  dbo:  <http://dbpedia.org/ontology/>
PREFIX  dbp:  <http://dbpedia.org/property/>
PREFIX  movie: <http://data.linkedmdb.org/resource/movie/>
PREFIX  owl:  <http://www.w3.org/2002/07/owl#>
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX  rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX  foaf: <http://xmlns.com/foaf/0.1/>
PREFIX  dc:   <http://purl.org/dc/terms/>

SELECT DISTINCT  ?name ?author ?filmname1 ?imdbID
WHERE
  { SERVICE <http://dbpedia.org/sparql>
      { ?book    rdf:type    dbo:Book ;
                 foaf:name   ?name ;
                 dbp:author  ?author .
        ?author  foaf:name   ?authname .
        ?book   ^dbo:basedOn ?movie .
        ?movie  rdf:type   dbo:Film ;
                foaf:name  ?filmname1
        FILTER ( str(?name) IN ("Royal Flash", "White Oleander", "Possession: A Romance", "Misery", "Intensity", "The War of The Roses", "Momo", "The Sicilian", "Derailed", "Ragtime") )
      }
    SERVICE <http://data.linkedmdb.org/sparql>
      { ?filmname  foaf:page  ?imdbID ;
                  dc:title   ?filmname2
        FILTER regex(str(?imdbID), "www.imdb.com")
      }
    FILTER ( str(?filmname1) = str(?filmname2) )
  }
于 2017-03-17T04:13:05.780 回答