Last active
November 20, 2017 13:27
-
-
Save dogrunjp/67b469a574802e2a5bbb968bf06b3741 to your computer and use it in GitHub Desktop.
PythonのSPARQLWrapperを使ってSPRQL endpointからJSON形式でデータを取得しようとした時、うまくいかないことがあったので、SPARQLWrapperを使わない方法を書いておきます。意外にこちらの方がシンプルかも。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib.request | |
import urllib.parse | |
data = urllib.parse.quote(''' | |
PREFIX refexo: <http://purl.jp/bio/01/refexo#> | |
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> | |
PREFIX refexs: <http://refex.dbcls.jp/sample/> | |
SELECT DISTINCT ?organism | |
WHERE { | |
refexs:RES00000003 refexo:organism ?organism . | |
} | |
''') | |
# 細かい設定をするため、Request objectを使う | |
req = urllib.request.Request("https://integbio.jp/rdf/sparql?query=%s" % data) | |
req.add_header('Accept', 'application/sparql-results+json') | |
response = urllib.request.urlopen(req) | |
result = response.read() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment