我正在尝试收集美国各州的POI。原始查询是
select distinct ?s ?state
where {
?s a dbpedia-owl:Place; dcterms:subject/skos:broader{,9} ?state .
?state skos:broader category:Buildings_and_structures_in_the_United_States_by_state .
filter contains(str(?state),'_in_') .
filter(!contains(str(?state),'United_States'))
}
过滤器部分是为了找到美国各州(如下所示),最后我们知道每个POI属于哪个州。
这种方法不起作用,因为我获得了一个POI的多个状态。 例如,如果我运行以下查询以查找五角大楼
的美国州select distinct ?state
where {
dbpedia:The_Pentagon dcterms:subject/skos:broader{,9} ?state .
?state skos:broader category:Buildings_and_structures_in_the_United_States_by_state .
filter contains(str(?state),'_in_') .
filter(!contains(str(?state),'United_States'))
}
这将导致五角大楼进入所有州。我知道这是由于skos:broader{,9}
,但我怎么知道,设置它的最佳水平。有更好的方法吗?
答案 0 :(得分:1)
我不确定您的查询究竟是在尝试什么,我无法理解他们。但根据你的描述,我认为你只需要感兴趣的地方以及它们所处的状态。如果是这样的话,我写了下面的查询。
SELECT distinct ?POI ?state WHERE {
?POI a dbpedia-owl:Place.
?POI dbpedia-owl:location ?location.
?location dbpedia-owl:country ?country.
?location dbpprop:state ?state.
filter(?country =dbpedia:United_States)
}
如果您愿意,您甚至可以进一步将该地方描述为建筑物,但我不认为POI必然是建筑物。但如果你想把它们命名为建筑物,那么:
SELECT distinct ?POI ?state WHERE {
?POI a dbpedia-owl:Place.
?POI a dbpedia-owl:Building.
?POI dbpedia-owl:location ?location.
?location dbpedia-owl:country ?country.
?location dbpprop:state ?state.
filter(?country =dbpedia:United_States)
}
要显示用例,您可以过滤五角大楼的?POI:
SELECT distinct ?POI ?state WHERE {
?POI a dbpedia-owl:Place.
?POI a dbpedia-owl:Building.
?POI dbpedia-owl:location ?location.
?location dbpedia-owl:country ?country.
?location dbpprop:state ?state.
filter(?country =dbpedia:United_States)
filter(?POI=dbpedia:The_Pentagon)
}