概要
paiza.ioでelixirやってみた。
e-statのsparqlを叩いてみた。
サンプルコード
:inets.start
:ssl.start
query = URI.encode_query(%{query: """
SELECT ?subject ?predicate ?object
WHERE {
?subject ?predicate ?object
}
LIMIT 3
"""})
#|> IO.inspect
{:ok, {{_, _, _}, _, body}} = :httpc.request(:post, {
'https://data.e-stat.go.jp/lod/sparql/alldata/query',
[{'Accept', 'application/sparql-results+json'}],
'application/x-www-form-urlencoded',
query
}, [], [])
#|> IO.inspect
body = IO.iodata_to_binary(body)
IO.puts(body)
実行結果
{
"head": {
"vars": [ "subject" , "predicate" , "object" ]
} ,
"results": {
"bindings": [
{
"subject": { "type": "uri" , "value": "http://data.e-stat.go.jp/lod/dataset/gridCode/dm012015302/obsQ24DSKRZDMDOMMQ7TRTQI5FT4PMVNYLM" } ,
"predicate": { "type": "uri" , "value": "http://purl.org/linked-data/cube#dataSet" } ,
"object": { "type": "uri" , "value": "http://data.e-stat.go.jp/lod/dataset/g00200521/dm012015302" }
} ,
{
"subject": { "type": "uri" , "value": "http://data.e-stat.go.jp/lod/dataset/gridCode/dm012015302/obsCEQ5NOWDXG5C747HEVQOVGER3CSFZ55J" } ,
"predicate": { "type": "uri" , "value": "http://purl.org/linked-data/cube#dataSet" } ,
"object": { "type": "uri" , "value": "http://data.e-stat.go.jp/lod/dataset/g00200521/dm012015302" }
} ,
{
"subject": { "type": "uri" , "value": "http://data.e-stat.go.jp/lod/dataset/gridCode/dm012015302/obsSZGCBG3D4RSYDR5OQ22QZ7G62U2PJPXA" } ,
"predicate": { "type": "uri" , "value": "http://purl.org/linked-data/cube#dataSet" } ,
"object": { "type": "uri" , "value": "http://data.e-stat.go.jp/lod/dataset/g00200521/dm012015302" }
}
]
}
}
成果物
以上。