{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Exploring data with SPARQL\n",
"
"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"
\n",
"\n",
"````{panels_fairplus}\n",
":identifier_text: FCB040\n",
":identifier_link: 'https://w3id.org/faircookbook/FCB040'\n",
":difficulty_level: 4\n",
":recipe_type: hands_on\n",
":reading_time_minutes: 30\n",
":intended_audience: principal_investigator, data_manager, data_scientist\n",
":maturity_level: 2\n",
":maturity_indicator: 1, 2\n",
":has_executable_code: yeah\n",
":recipe_name: FAIRifying Data Matrices - Step3 - Exploring data with SPARQL\n",
"````\n",
"\n",
"\n",
"## Background:\n",
"\n",
"Here, we show how to query the LinkedData graph using SPARQL to retrieve information about key study design\n",
"descriptors such as study group size and treatment groups."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import rdflib\n",
"from rdflib import Graph, RDF\n",
"from IPython.core.display import display, HTML\n",
"import os\n",
"import json\n",
"import csv\n",
"import uuid\n",
"\n",
"from SPARQLWrapper import SPARQLWrapper, SPARQLWrapper2, JSON, JSONLD, CSV, TSV, N3, RDF, RDFXML, TURTLE\n",
"import pandas as pds\n",
"import itertools\n",
"\n",
"import numpy as np\n",
"from plotnine import *\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def queryResultToHTMLTable(queryResult):\n",
" \n",
" HTMLResult = '
' + varName + ' | '\n", " HTMLResult = HTMLResult + '|
' + str(column) + ' | '\n", " else:\n", " HTMLResult = HTMLResult + '' + \"N/A\"+ ' | '\n", " HTMLResult = HTMLResult + '