使用SPARQL从DBpedia获取场所类别 [英] Get Place categories from DBpedia using SPARQL

查看:81
本文介绍了使用SPARQL从DBpedia获取场所类别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码在DBpedia中查询有界地理区域内的地点,并返回该地点的名称,纬度和经度。我还希望查询返回该地点的类别,例如公园,餐厅,博物馆等。

The following code queries DBpedia for places within a bounded geographic area and returns the name, lat, and long of the place. I'd also like the query to return the category of the place--e.g., park, restaurant, museum, etc.

以下代码可以正常工作。

The following code works fine.

        sparql = SPARQLWrapper("http://dbpedia.org/sparql")
        sparql.setQuery("""
        PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
        PREFIX dbo: <http://dbpedia.org/ontology/>
        PREFIX category: <http://dbpedia.org/resource/Category:>
        SELECT * WHERE {
        ?s a dbo:Place .
        ?s geo:lat ?lat .
        ?s geo:long ?long .

我尝试将以下代码添加到获取地点的类别,但这不起作用:

I tried to add the following code to get categories for places, but this doesn't work:

        ?s category:cat ?cat .

我应该添加/更改什么?谢谢。

What should I add/change? Thanks.

推荐答案

您可以通过找到类型(rdfs:type)或su来获得地点的类别(假设您是指类型)资源的bject(dcterms:subject)。在DBPedia中,第一个与DBPedia和Yago本体有关,第二个与DBPedia中的SKOS层次结构有关。这是一个示例查询:

You can get the category of a place (assuming you mean the type) by finding the type (rdfs:type) or the subject (dcterms:subject) of a resource. In DBPedia the first relates to the DBPedia and Yago ontologies and the second is a SKOS hierarchy in DBPedia. Here is an example query:

 PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
 PREFIX dbo: <http://dbpedia.org/ontology/>
 PREFIX dcterms: <http://purl.org/dc/terms/>
        SELECT * WHERE {
        ?s a dbo:Place .
        ?s geo:lat ?lat .
        ?s geo:long ?long .
        ?s a ?type . 
        ?s dcterms:subject ?sub
} 

请注意,您将获得每个地方都有多种类型和主题。

Note that you will get multiple types and subjects for each place.

这篇关于使用SPARQL从DBpedia获取场所类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆