简体   繁体   English

Factforge sparql端点要使用的限制图

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

Using http://www.sparql.org/sparql.html to run this query 使用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")).
}

returns 回报

-------------------------------------------------------------------------------------------------------
| 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"   |
-------------------------------------------------------------------------------------------------------

ie with multiple values for population. 即具有多个人口值。 Apparently coming from different graphs that factforge is querying. 显然,factforge来自不同的图形进行查询。 Is there a way to limit or prioritize factforge to for instance the geonames graph ? 有没有一种方法可以将factforge限制或确定其优先级,例如,地名图? BTW, geonames does not provide an open SPARQL endpoint, that's why I'm using Factforge. 顺便说一句,地名没有提供开放的SPARQL端点,这就是我使用Factforge的原因。

Let's start by changing your query just a little bit. 让我们从稍微更改查询开始。 Let's force ?poiname to be "Amsterdam"@en , so that we're only getting the problematic results: 让我们将?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 results SPARQL结果

Now, we can wrap the query that's in the service block inside graph ?g { ... } to find out where those triples are coming from. 现在,我们可以将graph ?g { ... }中的service块中的查询包装起来,以找出这些三元组来自何处。 That is, we now have: 也就是说,我们现在有:

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

SPARQL results SPARQL结果

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

There's only one result now; 现在只有一个结果。 it seems that the other result was in the default graph. 似乎其他结果在默认图中。

You can specify which graphs you want to query by using the graph keyword this way. 您可以通过这种方式使用graph关键字来指定要查询的graph The details are described in 13.3 Querying the Dataset of the SPARQL 1.1 Recommendation. 有关详细信息,请参见13.3查询 SPARQL 1.1建议书的数据集

By using the graph ?g { } in the query, you're forcing the data to be in a named graph (ie, you won't be getting triples from the default graph anymore). 通过在查询中使用graph ?g { } ,您可以强制将数据存储在命名图中(即,您将不再从默认图中获取三元组)。 This seems to remove some of the results that you wanted, unfortunately. 不幸的是,这似乎删除了一些您想要的结果。 Eg, Applying this to you original query (not restricted to Amsterdam): 例如,将其应用于您的原始查询(不限于阿姆斯特丹):

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 results 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> |
------------------------------------------------------------------------------------------------------------------------------

gives just two results; 仅给出两个结果; you no longer have a result for Wageningen. 您不再需要Wageningen的结果。 You can try asking for results with and without a graph, using 您可以尝试使用和不使用图形来询问结果,方法是

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

SPARQL results 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"   |                      |
------------------------------------------------------------------------------------------------------------------------------

and now we see the data a bit more clearly. 现在我们可以更清楚地看到数据。 We can't say for sure, but it looks like the nytimes data is duplicated in the default graph, which is good in the case of Netherlands which might not have a value otherwise, but bad in the case of Amsterdam, where the default graph already has a value, and it differs from the one in the named graph. 我们不能肯定地说,但是看起来nytimes数据在默认图中重复,这在荷兰(可能没有值)的情况下很好,但在阿姆斯特丹(默认值)的情况下不好已经具有一个值,并且不同于命名图中的值。

The direct answer, then, is yes you can control which graphs are queried, but in the case it's not at all clear what data you'd want to use. 那么,直接的答案可以控制要查询哪些图形,但是在这种情况下根本不清楚要使用什么数据。 You might be better off grouping by the values that expect to be the same for each location, and then combining the population results in some fashion (eg, taking the maximum, or the minimum, or concatenating them, or something else. Eg, (note that we added a xsd: prefix for casting to xsd:integer , and that the ?population values are strings, hence the need for casting to xsd:integer in order to take the average): 您最好对每个位置的期望值进行分组,然后以某种方式组合总体结果(例如,取最大值或最小值,或将它们串联起来,等等)。请注意,我们添加了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 results 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