【发布时间】:2015-04-06 22:43:35
【问题描述】:
我正在尝试使用 SPARQL 查询对 DBPedia 进行相当复杂的调用。我想获取有关城市的一些信息(区、联邦州/»Bundesland«、邮政编码、坐标和地理相关城市)。
SELECT * WHERE {
#input
?x rdfs:label "Bentzin"@de.
#district
OPTIONAL {
?x dbpedia-owl:district ?district
# ?x dbpprop:landkreis ?district
{ SELECT * WHERE {
?district rdfs:label ?districtName
FILTER(lang(?districtName) = "de")
?district dbpprop:capital ?districtCapital
{ SELECT * WHERE {
?districtCapital rdfs:label ?districtCapitalName
FILTER(lang(?districtCapitalName) = "de")
}}
}}
}
#federal state
OPTIONAL {
# ?x dbpprop:bundesland ?land
?x dbpedia-owl:federalState ?land
{ SELECT * WHERE {
?land rdfs:label ?landName
FILTER(lang(?landName) = "de")
}}
}
#postal codes
?x dbpedia-owl:postalCode ?zip.
#coordinates
?x geo:lat ?lat.
?x geo:long ?long
#cities in the south
OPTIONAL {
?x dbpprop:south ?south
{SELECT * WHERE {
?south rdfs:label ?southName
FILTER(lang(?southName) = "de")
}}
}
#cities in the north
OPTIONAL {
?x dbpprop:north ?north
{ SELECT * WHERE {
?north rdfs:label ?northName
FILTER(lang(?northName) = "de")
}}
}
#cities in the west
...
}
这在某些情况下有效,但是存在一些主要问题。
有几个不同的属性可能包含联邦州或地区的值。有时是
dbpprop:landkreis(德语区的意思,在其他情况下是dbpedia-owl:district。如果只设置了一个,是否可以将这两者结合起来?-
此外,我想念出北部、西北部……的城市名称。有时,
dbpprop:north等会引用这些城市。每个方向的基本查询都是一样的:OPTIONAL { ?x dbpprop:north ?north { SELECT * WHERE { ?north rdfs:label ?northName FILTER(lang(?northName) = "de") }} }我真的不想每个方向都重复八次,有什么办法可以简化吗?
-
有时,还会引用多个其他城市 (example)。在这些情况下,会返回多个数据集。是否有可能在单个数据集中获取这些城市的名称列表?
+---+---+---------------------------------------------------------------+ | x | … | southName | +---+---+---------------------------------------------------------------+ | … | … | "Darmstadt"@de, "Stuttgart"@de, "Karlsruhe"@de, "Mannheim"@de | +---+---+---------------------------------------------------------------+
非常感谢您的反馈和想法!
直到
【问题讨论】: