3

大規模なデータ セット (ほぼ 20 年間にわたって 1 時間ごとに記録された気温) をクエリしており、毎日の気温などの要約を取得したいと考えています。

クエリの例は次のとおりです: http://www.boisvert.me.uk/opendata/sparql_aq+.html?pasteid=hu5rbc7W

PREFIX opensheff: <uri://opensheffield.org/properties#>

select ?time ?temp where {
    ?m opensheff:sensor <uri://opensheffield.org/datagrid/sensors/Weather_Mast/Weather_Mast.ic> ;
       opensheff:rawValue ?temp ;
       <http://purl.oclc.org/NET/ssnx/ssn#endTime> ?time .
  FILTER (str(?time) > "2011-09-24")
}
ORDER BY ASC(?time)

結果は次のようになります。

time                temp
"2011-09-24T00:00Z" 12.31
"2011-09-24T01:00Z" 11.68
"2011-09-24T02:00Z" 11.92
"2011-09-24T03:00Z" 11.59

ここで、日付文字列の一部でグループ化して、毎日の平均気温を取得したいと思います。

time            temp
"2011-09-24"    12.3  # or whatever
"2011-09-23"    11.7
"2011-09-22"    11.9
"2011-09-21"    11.6

では、?time の部分文字列でグループ化するにはどうすればよいですか?

4

1 に答える 1

3

最終的にそれを解決しました。ここで実行:

http://www.boisvert.me.uk/opendata/sparql_aq+.html?pasteid=j8m0Qk6s

コード: PREFIX opensheff:

select ?d AVG(?temp) as ?day_temp
where {
    ?m opensheff:sensor <uri://opensheffield.org/datagrid/sensors/Weather_Mast/Weather_Mast.ic> ;
       opensheff:rawValue ?temp ;
       <http://purl.oclc.org/NET/ssnx/ssn#endTime> ?time .
    BIND( SUBSTR(?time, 1, 10) AS ?d ) .
}
GROUP BY ?d
ORDER BY ASC(?d)

BIND を使用して新しい変数を必要な部分文字列に設定すると、その変数によるグループ化と平均化は簡単になります。

于 2015-07-24T21:43:17.767 に答える