{ "cells": [ { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "5015a0106025436eb233cd60fca8acae", "version_major": 2, "version_minor": 0 }, "text/plain": [ "VBox(children=(VBox(children=(HTML(value='
Waiting for input
',\n", " description=''\n", ")\n", "\n", "def handle_creators(incoming):\n", " # Record creators into our dict\n", " query_dict['creators'] = incoming['new']\n", " draw_kg()\n", " \n", "def handle_institutions(incoming):\n", " # Record institutions into our dict\n", " if 'ALL' in incoming['new']:\n", " query_dict['institutions'] = []\n", " else:\n", " query_dict['institutions'] = incoming['new']\n", " draw_kg()\n", " \n", "def draw_kg():\n", " creator_values = ''\n", " institution_values = ''\n", " institution_statement = ''\n", " \n", " if (query_dict['creators']):\n", " creator_values = 'VALUES ?creator ' + sparql_qidlist_to_values_string(list(query_dict['creators']))\n", " if (query_dict['institutions']):\n", " institution_values = 'VALUES ?institution ' + sparql_qidlist_to_values_string(list(query_dict['institutions']))\n", " institution_statement = '?item1 wdt:P195 ?institution .'\n", "\n", " # Create the SPARQL query\n", " # graphurl = creator_depictions_query_template_url.format(values_string)\n", " \n", " # TODO - eventually want to support as many UNION subqueries as needed\n", " query = creator_depictions_query_template % \\\n", " (creator_values, institution_values, institution_statement, institution_statement)\n", "\n", " # Create Wikidata query URL\n", " graphurl = 'https://query.wikidata.org/embed.html#' + urllib.parse.quote(query)\n", "\n", " # Poke iframe\n", " iframecode = ''\n", " graphoutput.value=iframecode\n", " \n", "a_selector = VBox([Label('Artists'),selector])\n", "i_selector = VBox([Label('Institutions'),institution_selector])\n", "\n", "topbox = HBox([a_selector, i_selector])\n", "headerbox = VBox([textheader,topbox])\n", "bottombox = HBox([graphoutput])\n", "\n", "bigbox = VBox([headerbox,bottombox])\n", "\n", "display(bigbox)\n", "\n", "selector.observe(handle_creators, names='value')\n", "institution_selector.observe(handle_institutions, names='value')" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "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.8.5" } }, "nbformat": 4, "nbformat_minor": 4 }