Skip to content

Instantly share code, notes, and snippets.

@hkwi
Last active October 28, 2016 04:15
Show Gist options
  • Save hkwi/bc125ace095e9add26b2cec2cc4c04ff to your computer and use it in GitHub Desktop.
Save hkwi/bc125ace095e9add26b2cec2cc4c04ff to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"`CodeChangeEvent` で現在のコード一覧が出せないか計算してみる。"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:rdflib:RDFLib Version: 4.2.1\n"
]
}
],
"source": [
"import rdflib\n",
"g = rdflib.Graph()\n",
"g.load(\"http://data.e-stat.go.jp/lodw/download/rdfschema/StandardAreaCode.ttl\", format=\"turtle\")"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3710\n"
]
}
],
"source": [
"r = g.query('''\n",
"PREFIX org: <http://www.w3.org/ns/org#>\n",
"PREFIX sac: <http://data.e-stat.go.jp/lod/sac/>\n",
"PREFIX sacs: <http://data.e-stat.go.jp/lod/terms/sacs#>\n",
"PREFIX sace: <http://data.e-stat.go.jp/lod/sace/>\n",
"\n",
"SELECT DISTINCT ?s WHERE {\n",
" ?s a sacs:StandardAreaCode .\n",
" ?e a sacs:CodeChangeEvent ;\n",
" org:resultingOrganization ?s .\n",
"\n",
" FILTER NOT EXISTS {\n",
" ?e2 org:originalOrganization ?s .\n",
" }\n",
"}\n",
"''')\n",
"print(len(r))"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2296\n"
]
}
],
"source": [
"r = g.query('''\n",
"PREFIX sacs: <http://data.e-stat.go.jp/lod/terms/sacs#>\n",
"\n",
"SELECT DISTINCT ?s WHERE {\n",
" ?sc a sacs:CurrentStandardAreaCode ;\n",
" owl:sameAs ?s .\n",
"}\n",
"''')\n",
"print(len(r))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"一致しませんね…"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda env:geo]",
"language": "python",
"name": "conda-env-geo-py"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment