Gra*_*eon 0 rdf sparql geonames
我试图在以下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")).
}
Run Code Online (Sandbox Code Playgroud)
哪个,使用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" }
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
我想要实现的是它使用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")).
}
Run Code Online (Sandbox Code Playgroud)
返回此:
-------------------------------------------------------------------------------------------------------
| 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" |
-------------------------------------------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)
下一次迭代:使用"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")).
}
Run Code Online (Sandbox Code Playgroud)
这导致了我想要的东西,除了factforge返回不同数据类型的多个值.
此资源http://wifo5-03.informatik.uni-mannheim.de/latc/www2012/Session%201.html被证明是非常有用的.
我认为这里有两个问题.首先是一个小错字.当我运行您的查询时,注释行未注释,因为该行我得到一个解析错误
from <http://sws.geonames.org/ >
Run Code Online (Sandbox Code Playgroud)
因为IRI中不应该有空格.虽然这很容易解决.修复后,sparql.org上的服务会回复该问题
Error 400: Failed to load URL (parse error) http://sws.geonames.org/ : Failed to determine the triples content type: (URI=http://sws.geonames.org/ : stream=null : hint=null)
Fuseki - version 1.0.0 (Build date: 2013-09-12T10:49:49+0100)
Run Code Online (Sandbox Code Playgroud)
我认为,这意味着Jena能够提取IRI的内容,但无法弄清楚如何将其作为RDF阅读.虽然快速的谷歌搜索显示了大量的查询,其中IRI被用作命名空间前缀,但我没有看到它被用作可以选择三元组的图形的位置.我认为这与geonames.org在其文档中所说的相符:
进入GeoNames语义Web的入口点
您可以通过多种方式进入GeoNames语义Web:
- 从大地母亲开始,按照关联数据链接.
- 使用带有type = rdf参数选项的geonames搜索webservice.
- 下载数据库转储并使用模式" http://sws.geonames.org/geonameId/ " 构建功能的URL
- RDF转储具有8514201功能和大约125 mio rdf三倍(2013 08 27).转储在文件的每一行上每个地址都有一个rdf文档.注意:文件非常大.确保用于解压缩的工具能够处理大小,并且在2GB之后不会停止,这是一些旧的(Windows)工具版本会出现的问题.
我没有看到该列表中的SPARQL端点,我有点惊讶,但我希望如果有一个,它将在这个选项列表中.
现在,成功的查询(没有注释行)返回以下结果:
poi poiname geonames latitude
<http://ophileon.com/ox/poi/2> "Wageningen"@en <http://sws.geonames.org/2745088>
<http://ophileon.com/ox/poi/3> "Netherlands"@en <http://sws.geonames.org/2750405>
<http://ophileon.com/ox/poi/1> "Amsterdam"@en <http://sws.geonames.org/2759794>
Run Code Online (Sandbox Code Playgroud)
注意:这些是我开始撰写此答案时的结果.但是,这是基于http://www.ophileon.com/ox/poi.rdf可能已更改的数据.在此查询的后续运行中,我得到的值geonames具有最终值/,例如http://sws.geonames.org/2745088/.
基于相同的文档,其中也说:
对于法国的Embrun镇,我们有两个URI:
第一个URI [1]代表法国的城镇.如果要引用城镇,请使用此URI.第二个URI [2]是具有关于Embrun的geonames信息的文档.
这表明使用那些特定地理名称IRI的查询也可以用作图名称.也就是说,像这样的查询可能会起作用:
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/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")).
}
Run Code Online (Sandbox Code Playgroud)
现在这仍然没有返回任何结果,但似乎所有数据都应该存在.让我们尝试一个更简单的查询.如果您使用这样的查询:
select *
from <http://sws.geonames.org/2759794/about.rdf>
where { ?s ?p ?o }
Run Code Online (Sandbox Code Playgroud)
关于那个地方,你会得到一堆三倍.这也适用于多个from子句.例如,如果您使用以下查询使用该数据和数据,则会得到组合结果.
select *
from <http://www.ophileon.com/ox/poi.rdf>
from <http://sws.geonames.org/2745088/about.rdf>
where { ?s ?p ?o }
Run Code Online (Sandbox Code Playgroud)
在查看该数据集的结果时,我们终于可以看到问题出在哪里:地理名称资源的IRI /以其实际形式结束,但/在数据中没有.您需要相应地更改数据.
注意:似乎http://www.ophileon.com/ox/poi.rdf已经更正了数据.
看起来您可能最终需要运行第一个查询来确定要从地理名称获取的数据,检索该信息,然后对其运行第二个查询.或者,您可以下载Geonames提供的大数据转储并在本地使用它(可能是最简单的解决方案).