Skip to content

Instantly share code, notes, and snippets.

@boaarmpit
Last active March 5, 2017 02:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boaarmpit/1c91d7c7849090e31307a701ae66abd4 to your computer and use it in GitHub Desktop.
Save boaarmpit/1c91d7c7849090e31307a701ae66abd4 to your computer and use it in GitHub Desktop.
Example using the open data provided by Osaka city
# Setup environment using 'source setup.sh'
# then run with 'python testosaka.py'
# (tested with blank c9.io workspace)
from SPARQLWrapper import SPARQLWrapper, JSON
sparql = SPARQLWrapper("https://data.city.osaka.lg.jp/sparql")
sparql.setQuery("""
PREFIX ic: <http://imi.ipa.go.jp/ns/core/rdf#>
PREFIX dsv: <http://datashelf.jp/ns/dsv#>
select distinct ?s ?label ?address ?lat ?long where {
?s a ic:施設型 ;
rdfs:label ?label ;
ic:住所 / ic:表記 ?address ;
ic:種別 "防災関連施設 - 災害時用へリポート" ;
ic:地理座標 / ic:緯度 ?lat ;
ic:地理座標 / ic:緯度 ?long .
} LIMIT 100
""")
sparql.setReturnFormat(JSON)
results = sparql.query().convert()
for result in results["results"]["bindings"]:
print(result["label"]["value"])
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh
bash ~/miniconda.sh -b -p $HOME/miniconda
echo 'export PATH="$HOME/miniconda/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
conda create -y -n py3 python=3
source activate py3
conda install -y Flask
pip install sparqlwrapper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment