{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "name": "01_BNB_SPARQL_Compare_Publication_Year_for_two_Subjects.ipynb", "provenance": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3", "language": "python" }, "language_info": { "name": "python", "version": "3.7.6", "mimetype": "text/x-python", "codemirror_mode": { "name": "ipython", "version": 3 }, "pygments_lexer": "ipython3", "nbconvert_exporter": "python", "file_extension": ".py" } }, "cells": [ { "cell_type": "markdown", "metadata": { "id": "dMyRmL5szJPO", "colab_type": "text" }, "source": [ "
This notebook explains how to query it to retrieve records of resources indexed under two given Subjects / Topics (LCSH), and compare their number by publication year.
\n", "\n",
"\n",
"## Define the Subjects to Compare\n",
"\n",
"Set the Subject to search from [LCSH list](http://id.loc.gov/authorities/subjects.html):"
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "jbYUkXcXIoLC",
"trusted": false,
"colab": {}
},
"source": [
"# Examples -- uncomment the desired subject, or added your own set of Subject and Label, and do \"Run\" or \"Runtime\" > \"Run all\" or \"Run all cells\":\n",
"\n",
"Label = ''\n",
"\n",
"# Subject = 'Nanotubes'\n",
"# Label = 'Nanotubes'\n",
"\n",
"Subject1 = 'Climaticchanges'\n",
"Label1 = 'Climatic Changes'\n",
"\n",
"Subject2 = 'Globalwarming'\n",
"Label2 = 'Global Warming'"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "qt0a7zDeIoLH"
},
"source": [
"#### Required modules / libraries"
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "grVj5kG8IoLH",
"trusted": true,
"colab": {}
},
"source": [
"import requests\n",
"import pandas as pd\n",
"import json\n",
"import csv\n",
"import matplotlib.pyplot as plt\n",
"from pandas import json_normalize"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "OGC6e5K8IoLL"
},
"source": [
"## Let's query the repository by asking the publications indexed by the defined Subjects\n",
"We will use the [SPARQL endpoint](https://bnb.data.bl.uk/flint-sparql) to create the query and configure the request to retrieve json as a result."
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "orhVTXt0IoLL",
"trusted": false,
"colab": {
"base_uri": "https://localhost:8080/",
"height": 34
},
"outputId": "5fe9cbee-7b1f-4c98-bcf3-f7084761c33c"
},
"source": [
"url = 'https://bnb.data.bl.uk/sparql'\n",
"query = \"\"\"\n",
"PREFIX bibo: \n",
" \n",
"
\n",
"\n",
" \n",
" \n",
" \n",
" \n",
" resource.type \n",
" resource.value \n",
" title.type \n",
" title.value \n",
" date.type \n",
" date.value \n",
" author.type \n",
" author.value \n",
" authorUri.type \n",
" authorUri.value \n",
" \n",
" \n",
" 0 \n",
" uri \n",
" http://bnb.data.bl.uk/id/resource/019483741 \n",
" literal \n",
" Dwelling in the age of climate change : the et... \n",
" literal \n",
" 2019-08 \n",
" literal \n",
" Kelly, Elaine \n",
" uri \n",
" http://bnb.data.bl.uk/id/person/KellyElaine \n",
" \n",
" \n",
" \n",
"1 \n",
" uri \n",
" http://bnb.data.bl.uk/id/resource/019483741 \n",
" literal \n",
" Dwelling in the age of climate change : the et... \n",
" literal \n",
" 2019-08 \n",
" literal \n",
" Kelly, Elaine \n",
" uri \n",
" http://bnb.data.bl.uk/id/person/KellyElaine \n",
" \n",
" \n",
"
\n",
"\n",
" \n",
" \n",
" \n",
" \n",
" resource.type \n",
" resource.value \n",
" title.type \n",
" title.value \n",
" date.type \n",
" date.value \n",
" author.type \n",
" author.value \n",
" authorUri.type \n",
" authorUri.value \n",
" \n",
" \n",
" 0 \n",
" uri \n",
" http://bnb.data.bl.uk/id/resource/018543304 \n",
" literal \n",
" Global climate change : turning knowledge into... \n",
" literal \n",
" 2017-09 \n",
" literal \n",
" Kitchen, David, 1956- \n",
" uri \n",
" http://bnb.data.bl.uk/id/person/KitchenDavid1956- \n",
" \n",
" \n",
" \n",
"1 \n",
" uri \n",
" http://bnb.data.bl.uk/id/resource/018543304 \n",
" literal \n",
" Global climate change : turning knowledge into... \n",
" literal \n",
" 2017-09 \n",
" literal \n",
" Kitchen, David, 1956- \n",
" uri \n",
" http://bnb.data.bl.uk/id/person/KitchenDavid1956- \n",
"