我正在尝试从以下 SPARQL 中的地名获取链接数据,但显然我做错了。
prefix oxprop: <http://ophileon.com/ox/property#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix wgs84_pos: <http://www.w3.org/2003/01/geo/wgs84_pos#>
select ?poi ?poiname ?geonames ?latitude
from <http://www.ophileon.com/ox/poi.rdf>
# from <http://sws.geonames.org/ >
where
{
?poi rdfs:label ?poiname.
?poi owl:sameAs ?geonames.
# ?geonames wgs84_pos:lat ?latitude.
FILTER(langMatches(lang(?poiname), "EN")).
}
其中,使用 sparql.org 的 JSON 输出:
{
"head": {
"vars": [ "poi" , "poiname" , "geonames" , "latitude" ]
} ,
"results": {
"bindings": [
{
"poi": { "type": "uri" , "value": "http://ophileon.com/ox/poi/2" } ,
"poiname": { "type": "literal" , "xml:lang": "en" , "value": "Wageningen" } ,
"geonames": { "type": "uri" , "value": "http://sws.geonames.org/2745088" }
} ,
{
"poi": { "type": "uri" , "value": "http://ophileon.com/ox/poi/3" } ,
"poiname": { "type": "literal" , "xml:lang": "en" , "value": "Netherlands" } ,
"geonames": { "type": "uri" , "value": "http://sws.geonames.org/2750405" }
} ,
{
"poi": { "type": "uri" , "value": "http://ophileon.com/ox/poi/1" } ,
"poiname": { "type": "literal" , "xml:lang": "en" , "value": "Amsterdam" } ,
"geonames": { "type": "uri" , "value": "http://sws.geonames.org/2759794" }
}
]
}
}
我想要实现的是它使用 geonames rdf 服务检索每个节点的纬度,地址如“ http://sws.geonames.org/2745088/about.rdf ”
以“#”开头的行是我怀疑不正确的行。
下一次迭代
在 geonamesID 后面添加“/”,然后运行:
prefix oxprop: <http://ophileon.com/ox/property#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix wgs84_pos: <http://www.w3.org/2003/01/geo/wgs84_pos#>
select *
from <http://www.ophileon.com/ox/poi.rdf>
from <http://sws.geonames.org/2745088/about.rdf>
from <http://sws.geonames.org/2750405/about.rdf>
from <http://sws.geonames.org/2759794/about.rdf>
where
{
?poi rdfs:label ?poiname.
?poi owl:sameAs ?geonames.
?geonames wgs84_pos:lat ?latitude.
FILTER(langMatches(lang(?poiname), "EN")).
}
返回这个:
-------------------------------------------------------------------------------------------------------
| poi | poiname | geonames | latitude |
=======================================================================================================
| <http://ophileon.com/ox/poi/2> | "Wageningen"@en | <http://sws.geonames.org/2745088/> | "51.97" |
| <http://ophileon.com/ox/poi/3> | "Netherlands"@en | <http://sws.geonames.org/2750405/> | "52.5" |
| <http://ophileon.com/ox/poi/1> | "Amsterdam"@en | <http://sws.geonames.org/2759794/> | "52.37403" |
-------------------------------------------------------------------------------------------------------
下一次迭代:使用“SERVICE”关键字
prefix oxprop: <http://ophileon.com/ox/property#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix wgs84_pos: <http://www.w3.org/2003/01/geo/wgs84_pos#>
select ?poi ?poiname ?geonameuri ?latitude
from <http://www.ophileon.com/ox/poi.rdf>
where
{
?poi rdfs:label ?poiname.
?poi owl:sameAs ?geonameuri.
SERVICE <http://factforge.net/sparql>{
?geonameuri wgs84_pos:lat ?latitude.
}
FILTER(langMatches(lang(?poiname), "EN")).
}
这导致了我想要的结果,除了 factforge 返回各种数据类型的多个值。
这个资源http://wifo5-03.informatik.uni-mannheim.de/latc/www2012/Session%201.html被证明是非常有用的。