繁体   English   中英

Factforge sparql端点要使用的限制图

[英]Limiting graphs to be used by Factforge sparql endpoint

使用http://www.sparql.org/sparql.html运行此查询

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#>
prefix gn: <http://www.geonames.org/ontology#>

select *

from <http://www.ophileon.com/ox/poi.rdf>

where
{
   ?poi rdfs:label ?poiname.
   ?poi owl:sameAs ?geonameuri.
   SERVICE <http://factforge.net/sparql>{
   ?geonameuri gn:population ?population.
   }
   FILTER(langMatches(lang(?poiname), "EN")).
}

回报

-------------------------------------------------------------------------------------------------------
| poi                            | poiname          | geonameuri                         | population |
=======================================================================================================
| <http://ophileon.com/ox/poi/2> | "Wageningen"@en  | <http://sws.geonames.org/2745088/> | "35433"    |
| <http://ophileon.com/ox/poi/3> | "Netherlands"@en | <http://sws.geonames.org/2750405/> | "16645000" |
| <http://ophileon.com/ox/poi/1> | "Amsterdam"@en   | <http://sws.geonames.org/2759794/> | "767457"   |
| <http://ophileon.com/ox/poi/1> | "Amsterdam"@en   | <http://sws.geonames.org/2759794/> | "741636"   |
-------------------------------------------------------------------------------------------------------

即具有多个人口值。 显然,factforge来自不同的图形进行查询。 有没有一种方法可以将factforge限制或确定其优先级,例如,地名图? 顺便说一句,地名没有提供开放的SPARQL端点,这就是我使用Factforge的原因。

让我们从稍微更改查询开始。 让我们将?poiname强制为"Amsterdam"@en ?poiname ,这样我们只会得到有问题的结果:

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#>
prefix gn: <http://www.geonames.org/ontology#>

select *

from <http://www.ophileon.com/ox/poi.rdf>

where
{
   values ?poiname { "Amsterdam"@en }
   ?poi rdfs:label ?poiname.
   ?poi owl:sameAs ?geonameuri.
   SERVICE <http://factforge.net/sparql> {
     ?geonameuri gn:population ?population.
   }
   FILTER(langMatches(lang(?poiname), "EN")).
}

SPARQL结果

现在,我们可以将graph ?g { ... }中的service块中的查询包装起来,以找出这些三元组来自何处。 也就是说,我们现在有:

   SERVICE <http://factforge.net/sparql> {
     graph ?g { ?geonameuri gn:population ?population. }
   }

SPARQL结果

----------------------------------------------------------------------------------------------------------------------------
| poiname        | poi                            | geonameuri                         | population | g                    |
============================================================================================================================
| "Amsterdam"@en | <http://ophileon.com/ox/poi/1> | <http://sws.geonames.org/2759794/> | "741636"   | <http://nytimes.com> |
----------------------------------------------------------------------------------------------------------------------------

现在只有一个结果。 似乎其他结果在默认图中。

您可以通过这种方式使用graph关键字来指定要查询的graph 有关详细信息,请参见13.3查询 SPARQL 1.1建议书的数据集

通过在查询中使用graph ?g { } ,您可以强制将数据存储在命名图中(即,您将不再从默认图中获取三元组)。 不幸的是,这似乎删除了一些您想要的结果。 例如,将其应用于您的原始查询(不限于阿姆斯特丹):

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#>
prefix gn: <http://www.geonames.org/ontology#>

select *

from <http://www.ophileon.com/ox/poi.rdf>

where
{
   ?poi rdfs:label ?poiname.
   ?poi owl:sameAs ?geonameuri.
   SERVICE <http://factforge.net/sparql>{
    graph ?g { ?geonameuri gn:population ?population. }
   }
   FILTER(langMatches(lang(?poiname), "EN")).
}

SPARQL结果

------------------------------------------------------------------------------------------------------------------------------
| poi                            | poiname          | geonameuri                         | population | g                    |
==============================================================================================================================
| <http://ophileon.com/ox/poi/3> | "Netherlands"@en | <http://sws.geonames.org/2750405/> | "16645000" | <http://nytimes.com> |
| <http://ophileon.com/ox/poi/1> | "Amsterdam"@en   | <http://sws.geonames.org/2759794/> | "741636"   | <http://nytimes.com> |
------------------------------------------------------------------------------------------------------------------------------

仅给出两个结果; 您不再需要Wageningen的结果。 您可以尝试使用和不使用图形来询问结果,方法是

{ graph ?g { ?geonameuri gn:population ?population. } }
union
{ ?geonameuri gn:population ?population. }

SPARQL结果

------------------------------------------------------------------------------------------------------------------------------
| poi                            | poiname          | geonameuri                         | population | g                    |
==============================================================================================================================
| <http://ophileon.com/ox/poi/2> | "Wageningen"@en  | <http://sws.geonames.org/2745088/> | "35433"    |                      |
| <http://ophileon.com/ox/poi/3> | "Netherlands"@en | <http://sws.geonames.org/2750405/> | "16645000" | <http://nytimes.com> |
| <http://ophileon.com/ox/poi/3> | "Netherlands"@en | <http://sws.geonames.org/2750405/> | "16645000" |                      |
| <http://ophileon.com/ox/poi/1> | "Amsterdam"@en   | <http://sws.geonames.org/2759794/> | "741636"   | <http://nytimes.com> |
| <http://ophileon.com/ox/poi/1> | "Amsterdam"@en   | <http://sws.geonames.org/2759794/> | "767457"   |                      |
| <http://ophileon.com/ox/poi/1> | "Amsterdam"@en   | <http://sws.geonames.org/2759794/> | "741636"   |                      |
------------------------------------------------------------------------------------------------------------------------------

现在我们可以更清楚地看到数据。 我们不能肯定地说,但是看起来nytimes数据在默认图中重复,这在荷兰(可能没有值)的情况下很好,但在阿姆斯特丹(默认值)的情况下不好已经具有一个值,并且不同于命名图中的值。

那么,直接的答案可以控制要查询哪些图形,但是在这种情况下根本不清楚要使用什么数据。 您最好对每个位置的期望值进行分组,然后以某种方式组合总体结果(例如,取最大值或最小值,或将它们串联起来,等等)。请注意,我们添加了xsd:前缀用于强制转换为xsd:integer ,并且?population值是字符串,因此需要强制转换为xsd:integer才能取平均值):

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#>
prefix gn: <http://www.geonames.org/ontology#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>

select
  ?poi
  ?poiname
  ?geonameuri
  (min(?population) as ?minPopulation)
  (max(?population) as ?maxPopulation)
  (group_concat(?population;separator=' ') as ?allPopulations)
  (avg(xsd:integer(?population)) as ?avgPopulation)
  (sample(?population) as ?somePopulation)

from <http://www.ophileon.com/ox/poi.rdf>

where
{
   ?poi rdfs:label ?poiname.
   ?poi owl:sameAs ?geonameuri.
   SERVICE <http://factforge.net/sparql> {
     ?geonameuri gn:population ?population.
   }
   FILTER(langMatches(lang(?poiname), "EN")).
}
group by ?poi ?poiname ?geonameuri

SPARQL结果

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| poi                            | poiname          | geonameuri                         | minPopulation | maxPopulation | allPopulations  | avgPopulation | somePopulation |
=============================================================================================================================================================================
| <http://ophileon.com/ox/poi/2> | "Wageningen"@en  | <http://sws.geonames.org/2745088/> | "35433"       | "35433"       | "35433"         | 35433.0       | "35433"        |
| <http://ophileon.com/ox/poi/3> | "Netherlands"@en | <http://sws.geonames.org/2750405/> | "16645000"    | "16645000"    | "16645000"      | 16645000.0    | "16645000"     |
| <http://ophileon.com/ox/poi/1> | "Amsterdam"@en   | <http://sws.geonames.org/2759794/> | "741636"      | "767457"      | "767457 741636" | 754546.5      | "767457"       |
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM