簡體   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