SPARQL联合没有合并结果

时间:2015-12-04 12:37:32

标签: union sparql

我有一个sparql查询,它是三个单独查询的联合。在联合我应用过滤器。虽然我的个别查询返回行,但联合不返回任何行。我已经检查过各个查询的输出是否有满足外部过滤条件的行。

PREFIX dcterms: <http://purl.org/dc/terms/> 
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/> 
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>  
PREFIX yago: <http://dbpedia.org/class/yago/> 

SELECT * 
where{

       {
    SELECT (?LandingURI) AS ?URI ?category
        WHERE {
                        {
                         ?LandingURI rdfs:label ?term .
                         ?LandingURI (dcterms:subject|rdf:type) ?category .
                        }
                FILTER((?term ="Roger"@en))
                     }
       }
       UNION
       {
       SELECT (?redirects) AS ?URI ?category
                WHERE {

                         {
                         ?LandingURI rdfs:label ?term .
                         ?LandingURI <http://dbpedia.org/ontology/wikiPageRedirects> ?redirects .
                         ?redirects (dcterms:subject|rdf:type) ?category .
                         }          
                        FILTER((?term ="Roger"@en))         
              }
       }
       UNION
       {
       SELECT (?disambiguates) AS ?URI ?category
                WHERE {

                         {
                         ?LandingURI rdfs:label ?term .
                         ?LandingURI <http://dbpedia.org/ontology/wikiPageDisambiguates> ?disambiguates .
                         ?disambiguates (dcterms:subject|rdf:type) ?category .
                         }          
                        FILTER((?term ="Roger"@en))         
              }
       }
FILTER (?category = dbpedia-owl:TennisPlayer || 
        ?category = yago:TennisOrganisations ||
        ?category = <http://dbpedia.org/resource/Category:The_Championships,_Wimbledon>
       ) 
}

1 个答案:

答案 0 :(得分:3)

我不知道您使用哪种软件来处理您的查询,但它根本不应该接受该查询;它没有良好的形成。您可以在sparql.org's query validator查看您的查询。

您的查询中的包围很难确切地说出联合的确切位置,但万一它不是,联合应该出现在两个之间组图模式,例如: {...} UNION {...}

所有这一切,实际上根本不需要使用 union (或过滤器)。您可以使用property pathsvalues完成所有操作。如果我理解正确,您的查询可以重写为:

select ?uri ?term ?category where {
  #-- acceptable values of ?category
  values ?category {
    dbpedia-owl:TennisPlayer
    yago:TennisOrganisations
    <http://dbpedia.org/resource/Category:The_Championships,_Wimbledon>
  }

  #-- acceptable values of ?term
  values ?term {
    "Roger"@en
  }

  #-- get the rdfs:label of the ?landingUri, then
  #-- follow an optional redirect or disambiguation
  #-- link to the actual uri, and then get any
  #-- dcterms:subject or rdf:type from the actual uri.
  ?landingUri rdfs:label ?term .
  ?landingUri (dbpedia-owl:wikiPageRedirects|dbpedia-owl:wikiPageDisambiguates)? ?uri
  ?uri (dcterms:subject|rdf:type) ?category .
}