SPARQL查询dbpedia以查找滑雪缆车

时间:2018-08-15 14:50:42

标签: sparql dbpedia

我目前正在试图教自己如何制定SPARQL查询,以从DBpedia中提取旅游相关信息(通过http://dbpedia.org/sparql/)。

到目前为止,我已经设法获得一个国家的所有博物馆。

select ?thing ?type ?category ?long ?lat ?country 
where
  {      
    VALUES ?country { <http://dbpedia.org/resource/Canada> }

    optional
      { 
        ?city  dbo:country  ?country 
      }

    ?thing  dbo:location  ?city.

    optional
      { 
        ?thing  a  ?type  .
        VALUES ?type { dbo:Museum }
        BIND( 'Museum' as ?category )
      }

    optional
      { 
        ?thing a ?type.
        VALUES ?type { dbo:skiLift }
        BIND( 'Skilift' as ?category )
      }

    optional
      {
        ?thing geo:long ?long.
        ?thing geo:lat ?lat
      }

    {
      ?thing a dbo:Place
    }

    filter (BOUND (?type))
  }

但是,我不了解为获得dbo:skiLiftdbo:touristicSite之类的东西(在这里http://dbpedia.org/ontology/Place之类)也要获得相同的信息而需要做什么。 / p>

我在做什么错了?

1 个答案:

答案 0 :(得分:2)

这是因为dbo:skiLiftdbo:touristicSite都是属性。这些资源在Place页面中显示的不是Place的子类,而是以Place类为其域或范围的属性。如果要查找Place的子类,则可以执行探索性查询(该查询还使用属性路径来检索subClassOf属性的传递闭包):

select ?thing 
where 
  {
    ?thing rdfs:subClassOf+ <http://dbpedia.org/ontology/Place> .
  } 

除此之外,我不明白为什么您在同一查询中对不同类型使用两个可选子句。例如,以下查询检索位于加拿大城市的博物馆,可能带有其纬度和经度,而不使用其他可选子句:

select ?thing ?city ?long ?lat  
where
  {
    ?city   dbo:country   <http://dbpedia.org/resource/Canada> .
    ?thing  dbo:location  ?city .
    ?thing  a             dbo:Museum .

    optional
      {
        ?thing  geo:long  ?long .
        ?thing  geo:lat   ?lat
      }
  }
相关问题