【问题标题】:SPARQL query for dbpedia to find ski lifts用于 dbpedia 的 SPARQL 查询以查找滑雪缆车
【发布时间】:2018-08-15 14:50:42
【问题描述】:

我目前正在尝试自学如何制定 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)。

我做错了什么?

【问题讨论】:

  • 你没有选择变量typeName,所以应该是BIND( 'Skilift' as ?category )
  • 此外,公共 DBpedia 端点的默认限制为 10000 行。您不会立即看到整个结果。使用OFFSET 对其进行分页
  • 我已将查询从“typeName”更改为“category”,但仍未乘坐滑雪缆车。

标签: sparql dbpedia


【解决方案1】:

这是因为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
      }
  }

【讨论】:

  • 谢谢,这很有趣,很高兴知道,但我仍然不明白如何获取 dbo:skiLift 等属性的信息?
  • 究竟是什么信息?您可以使用例如select ?subject ?object where { ?subject dbo:skiLift ?object . } LIMIT 10 之类的查询来查看一些具有特定属性的三元组。对于特定属性,它似乎未在数据集中使用,因此结果为空。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多