概要
paiza.ioでelixirやってみた。
dbpediaのsparqlを叩いてみた。
サンプルコード
:inets.start
:ssl.start
query = URI.encode_query(%{query: """
SELECT DISTINCT * WHERE {<http://ja.dbpedia.org/resource/東京都> ?p ?o . } LIMIT 3
"""})
#|> IO.inspect
{:ok, {{_, _, _}, _, body}} = :httpc.request(:post, {
'https://ja.dbpedia.org/sparql',
[{'Accept', 'application/sparql-results+json'}],
'application/x-www-form-urlencoded',
query
}, [], [])
#|> IO.inspect
body = IO.iodata_to_binary(body)
IO.puts(body)
実行結果
{ "head": { "link": [], "vars": ["p", "o"] },
"results": { "distinct": false, "ordered": true, "bindings": [
{ "p": { "type": "uri", "value": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" } , "o": { "type": "uri", "value": "http://www.w3.org/2002/07/owl#Thing" }},
{ "p": { "type": "uri", "value": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" } , "o": { "type": "uri", "value": "http://dbpedia.org/ontology/AdministrativeRegion" }},
{ "p": { "type": "uri", "value": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" } , "o": { "type": "uri", "value": "http://schema.org/Place" }} ] } }
成果物
以上。