diff --git a/.buildinfo b/.buildinfo index 3d80744..f8ec53b 100644 --- a/.buildinfo +++ b/.buildinfo @@ -1,4 +1,4 @@ # Sphinx build info version 1 # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. -config: 6e5b5563c32065e5a15c612b5ceb8315 +config: 6a181b6a8ed75411ef568b977944179f tags: 645f666f9bcd5a90fca523b33c5a78b7 diff --git a/_sources/about.rst.txt b/_sources/about.rst.txt index 284aa4a..a759375 100644 --- a/_sources/about.rst.txt +++ b/_sources/about.rst.txt @@ -1,3 +1,9 @@ +.. toctree:: + :hidden: + + example_person_jsonld_nb.ipynb + + About the Battery Ontology ========================================== diff --git a/_sources/example_person_jsonld_nb.ipynb.txt b/_sources/example_person_jsonld_nb.ipynb.txt new file mode 100644 index 0000000..75a7cb3 --- /dev/null +++ b/_sources/example_person_jsonld_nb.ipynb.txt @@ -0,0 +1,394 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "aw_lp5wfXRSl" + }, + "source": [ + "# JSON-LD Demonstration\n", + "\n", + "In this notebook, we will explore the principles of JSON-LD using the example of a person. JSON-LD stands for \"JSON for Linking Data\" and it provides a method to enrich your JSON data with semantics.\n", + "\n", + "An operational version of this notebook can be accessed [here](https://colab.research.google.com/drive/14XqRJPWs07RUQgZmDZEu3yb2m1xGvxEQ?usp=sharing)." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "y-aalpcNb223", + "outputId": "565a219c-1d10-4b55-fd75-a1fcb2257022" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Requirement already satisfied: jsonschema in /usr/local/lib/python3.10/dist-packages (4.19.0)\n", + "Requirement already satisfied: attrs>=22.2.0 in /usr/local/lib/python3.10/dist-packages (from jsonschema) (23.1.0)\n", + "Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /usr/local/lib/python3.10/dist-packages (from jsonschema) (2023.7.1)\n", + "Requirement already satisfied: referencing>=0.28.4 in /usr/local/lib/python3.10/dist-packages (from jsonschema) (0.30.2)\n", + "Requirement already satisfied: rpds-py>=0.7.1 in /usr/local/lib/python3.10/dist-packages (from jsonschema) (0.10.2)\n", + "Collecting rdflib\n", + " Downloading rdflib-7.0.0-py3-none-any.whl (531 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m531.9/531.9 kB\u001b[0m \u001b[31m6.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hCollecting isodate<0.7.0,>=0.6.0 (from rdflib)\n", + " Downloading isodate-0.6.1-py2.py3-none-any.whl (41 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m41.7/41.7 kB\u001b[0m \u001b[31m4.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hRequirement already satisfied: pyparsing<4,>=2.1.0 in /usr/local/lib/python3.10/dist-packages (from rdflib) (3.1.1)\n", + "Requirement already satisfied: six in /usr/local/lib/python3.10/dist-packages (from isodate<0.7.0,>=0.6.0->rdflib) (1.16.0)\n", + "Installing collected packages: isodate, rdflib\n", + "Successfully installed isodate-0.6.1 rdflib-7.0.0\n" + ] + } + ], + "source": [ + "# Install the required library for JSON schema validation\n", + "!pip install jsonschema\n", + "!pip install rdflib" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "tNjkjGNEXJXP" + }, + "outputs": [], + "source": [ + "import jsonschema\n", + "from jsonschema import validate\n", + "import json\n", + "import rdflib\n", + "\n", + "# Regular JSON representation of a person\n", + "person_data = {\n", + " \"@context\": {\n", + " \"schema\": \"https://schema.org/\",\n", + " \"firstName\": \"schema:givenName\",\n", + " \"lastName\": \"schema:lastName\",\n", + " \"birthdate\": \"schema:birthDate\",\n", + " \"institute\": \"schema:affiliation\",\n", + " \"name\": \"schema:name\",\n", + " \"street\": \"schema:streetAddress\",\n", + " \"city\": \"schema:locality\",\n", + " \"zip\": \"schema:postalCode\"\n", + " },\n", + " \"@id\": \"https://www.example.com/SimonClark\",\n", + " \"@type\": \"schema:Person\",\n", + " \"firstName\": \"Simon\",\n", + " \"lastName\": \"Clark\",\n", + " \"birthdate\": \"1987-04-23\",\n", + " \"institute\": {\n", + " \"@id\": \"https://www.example.com/SINTEF\",\n", + " \"@type\": \"schema:ResearchOrganization\",\n", + " \"name\": \"SINTEF\",\n", + " \"street\": \"Strindvegen 4\",\n", + " \"city\": \"Trondheim\",\n", + " \"zip\": \"7034\"\n", + " }\n", + "}\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "K221MAoHa3Nx" + }, + "source": [ + "In the JSON-LD example, we added an `@context` that maps terms in our JSON data to their semantic meanings, using URIs (typically from established vocabularies, like schema.org). This allows machines to understand the semantics behind the data.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "ZmQfOeFyieo9" + }, + "outputs": [], + "source": [ + "# Regular JSON representation of a person\n", + "person_data = {\n", + " \"@context\": \"https://schema.org/\",\n", + " \"@id\": \"https://orcid.org/0000-0002-8758-6109\",\n", + " \"@type\": \"Person\",\n", + " \"firstName\": \"Simon\",\n", + " \"lastName\": \"Clark\",\n", + " \"gender\": {\"@type\": \"Male\"},\n", + " \"birthDate\": \"1987-04-23\",\n", + " \"affiliation\": {\n", + " \"@id\": \"https://ror.org/01f677e56\",\n", + " \"@type\": \"ResearchOrganization\"\n", + " }\n", + "}\n", + "\n", + "# email to: simon.clark@sintef.no" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "HDHJuV62bTby", + "outputId": "d5537f6e-4325-40ef-dfa4-c7d55159623f" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "JSON data is valid according to the schema.\n" + ] + } + ], + "source": [ + "person_schema = {\n", + " \"type\": \"object\",\n", + " \"properties\": {\n", + " \"firstName\": {\n", + " \"type\": \"string\"\n", + " },\n", + " \"lastName\": {\n", + " \"type\": \"string\",\n", + " \"minLength\": 1\n", + " },\n", + " \"birthDate\": { # Replacing age with birthdate\n", + " \"type\": \"string\",\n", + " \"format\": \"date\",\n", + " \"pattern\": \"^[0-9]{4}-[0-1][0-9]-[0-3][0-9]$\"\n", + " },\n", + " \"gender\": {\n", + " \"type\": \"object\"\n", + " },\n", + " \"affiliation\": {\n", + " \"type\": \"object\"\n", + " }\n", + " },\n", + " \"required\": [\"firstName\", \"lastName\", \"birthDate\", \"affiliation\"] # Updated age to birthdate\n", + "}\n", + "\n", + "# Function to validate JSON data against the schema\n", + "def validate_json(data, schema):\n", + " try:\n", + " validate(instance=data, schema=schema)\n", + " return True, \"JSON data is valid according to the schema.\"\n", + " except jsonschema.exceptions.ValidationError as ve:\n", + " return False, ve.message\n", + "\n", + "# Validate the sample JSON data\n", + "is_valid, message = validate_json(person_data, person_schema)\n", + "print(message)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "R-mO4FGtbr-L", + "outputId": "c0ae5e87-6ade-4ef8-a639-02bf287071a9" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(rdflib.term.URIRef('http://schema.org/Organization'),)\n", + "(rdflib.term.URIRef('http://schema.org/PerformingGroup'),)\n", + "(rdflib.term.URIRef('http://schema.org/TheaterGroup'),)\n", + "(rdflib.term.URIRef('http://schema.org/MusicGroup'),)\n", + "(rdflib.term.URIRef('http://schema.org/DanceGroup'),)\n", + "(rdflib.term.URIRef('http://schema.org/OnlineBusiness'),)\n", + "(rdflib.term.URIRef('http://schema.org/OnlineStore'),)\n", + "(rdflib.term.URIRef('http://schema.org/SportsOrganization'),)\n", + "(rdflib.term.URIRef('http://schema.org/SportsTeam'),)\n", + "(rdflib.term.URIRef('http://schema.org/Airline'),)\n", + "(rdflib.term.URIRef('http://schema.org/SearchRescueOrganization'),)\n", + "(rdflib.term.URIRef('http://schema.org/FundingScheme'),)\n", + "(rdflib.term.URIRef('http://schema.org/NewsMediaOrganization'),)\n", + "(rdflib.term.URIRef('http://schema.org/EducationalOrganization'),)\n", + "(rdflib.term.URIRef('http://schema.org/CollegeOrUniversity'),)\n", + "(rdflib.term.URIRef('http://schema.org/HighSchool'),)\n", + "(rdflib.term.URIRef('http://schema.org/Preschool'),)\n", + "(rdflib.term.URIRef('http://schema.org/ElementarySchool'),)\n", + "(rdflib.term.URIRef('http://schema.org/MiddleSchool'),)\n", + "(rdflib.term.URIRef('http://schema.org/School'),)\n" + ] + } + ], + "source": [ + "# Create a new graph\n", + "g = rdflib.Graph()\n", + "\n", + "# Load schema.org vocabulary into the graph\n", + "g.parse(\"https://schema.org/version/latest/schemaorg-current-http.jsonld\", format=\"json-ld\")\n", + "\n", + "person_data_str = json.dumps(person_data)\n", + "g.parse(data=person_data_str, format=\"json-ld\")\n", + "\n", + "# Define and execute a SPARQL query for all instances of Organization\n", + "sparql_query = \"\"\"\n", + "PREFIX schema: \n", + "SELECT DISTINCT ?type WHERE {\n", + " ?type rdfs:subClassOf* schema:Organization .\n", + "}\n", + "LIMIT 20\n", + "\"\"\"\n", + "\n", + "# Execute the SPARQL query\n", + "results = g.query(sparql_query)\n", + "\n", + "# Print the results\n", + "for row in results:\n", + " print(row)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "h4vvw5hNhih2", + "outputId": "77828fc9-bafe-414b-f6f6-65fb117aabc5" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "https://ror.org/01f677e56\n" + ] + } + ], + "source": [ + "# Define and execute a SPARQL query for all instances of Organization\n", + "sparql_query = \"\"\"\n", + "PREFIX rdf: \n", + "PREFIX rdfs: \n", + "PREFIX schema: \n", + "\n", + "SELECT ?instance WHERE {\n", + " ?subclass rdfs:subClassOf* schema:Organization .\n", + " ?instance rdf:type ?subclass .\n", + "}\n", + "LIMIT 10\n", + "\"\"\"\n", + "\n", + "# Execute the SPARQL query\n", + "results = g.query(sparql_query)\n", + "\n", + "# Print the results\n", + "for row in results:\n", + " print(row[0])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "e_-Qa3Hgh2kg", + "outputId": "2b9fafa4-fca4-426f-e768-6ef561921b14" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n" + ] + } + ], + "source": [ + "# Define and execute a SPARQL query for all instances of Organization\n", + "sparql_query = \"\"\"\n", + "PREFIX rdf: \n", + "PREFIX rdfs: \n", + "PREFIX schema: \n", + "\n", + "SELECT (COUNT(?subject) AS ?numMales) WHERE {\n", + " ?subject rdf:type schema:Person .\n", + " ?subject schema:gender ?gender .\n", + " ?gender rdf:type schema:Male .\n", + "}\n", + "LIMIT 10\n", + "\"\"\"\n", + "\n", + "# Execute the SPARQL query\n", + "results = g.query(sparql_query)\n", + "\n", + "# Print the results\n", + "for row in results:\n", + " print(row.numMales)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "HJfpCj4-sww3", + "outputId": "c4ba6b30-7d7e-45d9-c3e4-b0d311e0fdd0" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1987-04-23\n" + ] + } + ], + "source": [ + "# Define and execute a SPARQL query for all instances of Organization\n", + "sparql_query = \"\"\"\n", + "PREFIX rdf: \n", + "PREFIX rdfs: \n", + "PREFIX schema: \n", + "\n", + "SELECT ?bday WHERE {\n", + " ?subject rdf:type schema:Person .\n", + " ?subject schema:birthDate ?bday .\n", + "}\n", + "LIMIT 10\n", + "\"\"\"\n", + "\n", + "# Execute the SPARQL query\n", + "results = g.query(sparql_query)\n", + "\n", + "# Print the results\n", + "for row in results:\n", + " print(row[0])" + ] + } + ], + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/_static/nbsphinx-broken-thumbnail.svg b/_static/nbsphinx-broken-thumbnail.svg new file mode 100644 index 0000000..4919ca8 --- /dev/null +++ b/_static/nbsphinx-broken-thumbnail.svg @@ -0,0 +1,9 @@ + + + + diff --git a/_static/nbsphinx-code-cells.css b/_static/nbsphinx-code-cells.css new file mode 100644 index 0000000..a3fb27c --- /dev/null +++ b/_static/nbsphinx-code-cells.css @@ -0,0 +1,259 @@ +/* remove conflicting styling from Sphinx themes */ +div.nbinput.container div.prompt *, +div.nboutput.container div.prompt *, +div.nbinput.container div.input_area pre, +div.nboutput.container div.output_area pre, +div.nbinput.container div.input_area .highlight, +div.nboutput.container div.output_area .highlight { + border: none; + padding: 0; + margin: 0; + box-shadow: none; +} + +div.nbinput.container > div[class*=highlight], +div.nboutput.container > div[class*=highlight] { + margin: 0; +} + +div.nbinput.container div.prompt *, +div.nboutput.container div.prompt * { + background: none; +} + +div.nboutput.container div.output_area .highlight, +div.nboutput.container div.output_area pre { + background: unset; +} + +div.nboutput.container div.output_area div.highlight { + color: unset; /* override Pygments text color */ +} + +/* avoid gaps between output lines */ +div.nboutput.container div[class*=highlight] pre { + line-height: normal; +} + +/* input/output containers */ +div.nbinput.container, +div.nboutput.container { + display: -webkit-flex; + display: flex; + align-items: flex-start; + margin: 0; + width: 100%; +} +@media (max-width: 540px) { + div.nbinput.container, + div.nboutput.container { + flex-direction: column; + } +} + +/* input container */ +div.nbinput.container { + padding-top: 5px; +} + +/* last container */ +div.nblast.container { + padding-bottom: 5px; +} + +/* input prompt */ +div.nbinput.container div.prompt pre, +/* for sphinx_immaterial theme: */ +div.nbinput.container div.prompt pre > code { + color: #307FC1; +} + +/* output prompt */ +div.nboutput.container div.prompt pre, +/* for sphinx_immaterial theme: */ +div.nboutput.container div.prompt pre > code { + color: #BF5B3D; +} + +/* all prompts */ +div.nbinput.container div.prompt, +div.nboutput.container div.prompt { + width: 4.5ex; + padding-top: 5px; + position: relative; + user-select: none; +} + +div.nbinput.container div.prompt > div, +div.nboutput.container div.prompt > div { + position: absolute; + right: 0; + margin-right: 0.3ex; +} + +@media (max-width: 540px) { + div.nbinput.container div.prompt, + div.nboutput.container div.prompt { + width: unset; + text-align: left; + padding: 0.4em; + } + div.nboutput.container div.prompt.empty { + padding: 0; + } + + div.nbinput.container div.prompt > div, + div.nboutput.container div.prompt > div { + position: unset; + } +} + +/* disable scrollbars and line breaks on prompts */ +div.nbinput.container div.prompt pre, +div.nboutput.container div.prompt pre { + overflow: hidden; + white-space: pre; +} + +/* input/output area */ +div.nbinput.container div.input_area, +div.nboutput.container div.output_area { + -webkit-flex: 1; + flex: 1; + overflow: auto; +} +@media (max-width: 540px) { + div.nbinput.container div.input_area, + div.nboutput.container div.output_area { + width: 100%; + } +} + +/* input area */ +div.nbinput.container div.input_area { + border: 1px solid #e0e0e0; + border-radius: 2px; + /*background: #f5f5f5;*/ +} + +/* override MathJax center alignment in output cells */ +div.nboutput.container div[class*=MathJax] { + text-align: left !important; +} + +/* override sphinx.ext.imgmath center alignment in output cells */ +div.nboutput.container div.math p { + text-align: left; +} + +/* standard error */ +div.nboutput.container div.output_area.stderr { + background: #fdd; +} + +/* ANSI colors */ +.ansi-black-fg { color: #3E424D; } +.ansi-black-bg { background-color: #3E424D; } +.ansi-black-intense-fg { color: #282C36; } +.ansi-black-intense-bg { background-color: #282C36; } +.ansi-red-fg { color: #E75C58; } +.ansi-red-bg { background-color: #E75C58; } +.ansi-red-intense-fg { color: #B22B31; } +.ansi-red-intense-bg { background-color: #B22B31; } +.ansi-green-fg { color: #00A250; } +.ansi-green-bg { background-color: #00A250; } +.ansi-green-intense-fg { color: #007427; } +.ansi-green-intense-bg { background-color: #007427; } +.ansi-yellow-fg { color: #DDB62B; } +.ansi-yellow-bg { background-color: #DDB62B; } +.ansi-yellow-intense-fg { color: #B27D12; } +.ansi-yellow-intense-bg { background-color: #B27D12; } +.ansi-blue-fg { color: #208FFB; } +.ansi-blue-bg { background-color: #208FFB; } +.ansi-blue-intense-fg { color: #0065CA; } +.ansi-blue-intense-bg { background-color: #0065CA; } +.ansi-magenta-fg { color: #D160C4; } +.ansi-magenta-bg { background-color: #D160C4; } +.ansi-magenta-intense-fg { color: #A03196; } +.ansi-magenta-intense-bg { background-color: #A03196; } +.ansi-cyan-fg { color: #60C6C8; } +.ansi-cyan-bg { background-color: #60C6C8; } +.ansi-cyan-intense-fg { color: #258F8F; } +.ansi-cyan-intense-bg { background-color: #258F8F; } +.ansi-white-fg { color: #C5C1B4; } +.ansi-white-bg { background-color: #C5C1B4; } +.ansi-white-intense-fg { color: #A1A6B2; } +.ansi-white-intense-bg { background-color: #A1A6B2; } + +.ansi-default-inverse-fg { color: #FFFFFF; } +.ansi-default-inverse-bg { background-color: #000000; } + +.ansi-bold { font-weight: bold; } +.ansi-underline { text-decoration: underline; } + + +div.nbinput.container div.input_area div[class*=highlight] > pre, +div.nboutput.container div.output_area div[class*=highlight] > pre, +div.nboutput.container div.output_area div[class*=highlight].math, +div.nboutput.container div.output_area.rendered_html, +div.nboutput.container div.output_area > div.output_javascript, +div.nboutput.container div.output_area:not(.rendered_html) > img{ + padding: 5px; + margin: 0; +} + +/* fix copybtn overflow problem in chromium (needed for 'sphinx_copybutton') */ +div.nbinput.container div.input_area > div[class^='highlight'], +div.nboutput.container div.output_area > div[class^='highlight']{ + overflow-y: hidden; +} + +/* hide copy button on prompts for 'sphinx_copybutton' extension ... */ +.prompt .copybtn, +/* ... and 'sphinx_immaterial' theme */ +.prompt .md-clipboard.md-icon { + display: none; +} + +/* Some additional styling taken form the Jupyter notebook CSS */ +.jp-RenderedHTMLCommon table, +div.rendered_html table { + border: none; + border-collapse: collapse; + border-spacing: 0; + color: black; + font-size: 12px; + table-layout: fixed; +} +.jp-RenderedHTMLCommon thead, +div.rendered_html thead { + border-bottom: 1px solid black; + vertical-align: bottom; +} +.jp-RenderedHTMLCommon tr, +.jp-RenderedHTMLCommon th, +.jp-RenderedHTMLCommon td, +div.rendered_html tr, +div.rendered_html th, +div.rendered_html td { + text-align: right; + vertical-align: middle; + padding: 0.5em 0.5em; + line-height: normal; + white-space: normal; + max-width: none; + border: none; +} +.jp-RenderedHTMLCommon th, +div.rendered_html th { + font-weight: bold; +} +.jp-RenderedHTMLCommon tbody tr:nth-child(odd), +div.rendered_html tbody tr:nth-child(odd) { + background: #f5f5f5; +} +.jp-RenderedHTMLCommon tbody tr:hover, +div.rendered_html tbody tr:hover { + background: rgba(66, 165, 245, 0.2); +} + diff --git a/_static/nbsphinx-gallery.css b/_static/nbsphinx-gallery.css new file mode 100644 index 0000000..365c27a --- /dev/null +++ b/_static/nbsphinx-gallery.css @@ -0,0 +1,31 @@ +.nbsphinx-gallery { + display: grid; + grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); + gap: 5px; + margin-top: 1em; + margin-bottom: 1em; +} + +.nbsphinx-gallery > a { + padding: 5px; + border: 1px dotted currentColor; + border-radius: 2px; + text-align: center; +} + +.nbsphinx-gallery > a:hover { + border-style: solid; +} + +.nbsphinx-gallery img { + max-width: 100%; + max-height: 100%; +} + +.nbsphinx-gallery > a > div:first-child { + display: flex; + align-items: start; + justify-content: center; + height: 120px; + margin-bottom: 5px; +} diff --git a/_static/nbsphinx-no-thumbnail.svg b/_static/nbsphinx-no-thumbnail.svg new file mode 100644 index 0000000..9dca758 --- /dev/null +++ b/_static/nbsphinx-no-thumbnail.svg @@ -0,0 +1,9 @@ + + + + diff --git a/about.html b/about.html index c174391..bfda2a5 100644 --- a/about.html +++ b/about.html @@ -44,12 +44,13 @@ + - + @@ -231,7 +232,7 @@
-
+
@@ -307,6 +308,17 @@
+ + @@ -356,7 +368,9 @@
-
+
+
+

About the Battery Ontology#

The EMMO Battery Domain Ontology is a semantic resource for the terms and relations needed to describe things, processes, and data in the battery domain. It can be used to generate linked data for the Semantic Web, comply with the FAIR data guidelines, support interoperaility of data among different systems, and more!

The Battery Ontology is intended to support researchers, engineers, and developers within the electrochemical @@ -449,11 +463,11 @@

License

next

-

FAQ Page

+

JSON-LD Demonstration

@@ -520,7 +534,7 @@

License diff --git a/battery.html b/battery.html index 4557ff5..f6c9a16 100644 --- a/battery.html +++ b/battery.html @@ -44,6 +44,7 @@ + @@ -3798,7 +3799,7 @@

StateOfCharge diff --git a/contribute.html b/contribute.html index e957e2d..ba393dd 100644 --- a/contribute.html +++ b/contribute.html @@ -44,6 +44,7 @@ + @@ -471,7 +472,7 @@

Propose additions/deletion of elements diff --git a/example_alkaline_electrochemical_cell.html b/example_alkaline_electrochemical_cell.html index e98b2b4..4916f39 100644 --- a/example_alkaline_electrochemical_cell.html +++ b/example_alkaline_electrochemical_cell.html @@ -44,6 +44,7 @@ + @@ -446,7 +447,7 @@

Alkaline Electrochemical Cell diff --git a/example_aqueous_electrolyte_KOH.html b/example_aqueous_electrolyte_KOH.html index 99e8003..70368de 100644 --- a/example_aqueous_electrolyte_KOH.html +++ b/example_aqueous_electrolyte_KOH.html @@ -44,6 +44,7 @@ + @@ -470,7 +471,7 @@

Aqueous KOH Electrolyte diff --git a/example_cyclic_voltammetry.html b/example_cyclic_voltammetry.html index 613013b..d720ec5 100644 --- a/example_cyclic_voltammetry.html +++ b/example_cyclic_voltammetry.html @@ -44,6 +44,7 @@ + @@ -495,7 +496,7 @@

Cyclic Voltammetry Data diff --git a/example_eis_nyquist.html b/example_eis_nyquist.html index 024f9d1..dbea6be 100644 --- a/example_eis_nyquist.html +++ b/example_eis_nyquist.html @@ -44,6 +44,7 @@ + @@ -492,7 +493,7 @@

Cyclic Voltammetry Data diff --git a/example_person_jsonld_nb.html b/example_person_jsonld_nb.html new file mode 100644 index 0000000..e7758d8 --- /dev/null +++ b/example_person_jsonld_nb.html @@ -0,0 +1,791 @@ + + + + + + + + + + + + JSON-LD Demonstration — BattInfo documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+ + + +
+
+ +
+ + + + + + + + + + + + + +
+ +
+ + +
+
+ +
+
+ +
+ +
+ + + + +
+ +
+ + +
+
+ + + + + +
+ +
+

JSON-LD Demonstration#

+

In this notebook, we will explore the principles of JSON-LD using the example of a person. JSON-LD stands for “JSON for Linking Data” and it provides a method to enrich your JSON data with semantics.

+

An operational version of this notebook can be accessed here.

+
+
[ ]:
+
+
+
# Install the required library for JSON schema validation
+!pip install jsonschema
+!pip install rdflib
+
+
+
+
+
+
+
+
+Requirement already satisfied: jsonschema in /usr/local/lib/python3.10/dist-packages (4.19.0)
+Requirement already satisfied: attrs>=22.2.0 in /usr/local/lib/python3.10/dist-packages (from jsonschema) (23.1.0)
+Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /usr/local/lib/python3.10/dist-packages (from jsonschema) (2023.7.1)
+Requirement already satisfied: referencing>=0.28.4 in /usr/local/lib/python3.10/dist-packages (from jsonschema) (0.30.2)
+Requirement already satisfied: rpds-py>=0.7.1 in /usr/local/lib/python3.10/dist-packages (from jsonschema) (0.10.2)
+Collecting rdflib
+  Downloading rdflib-7.0.0-py3-none-any.whl (531 kB)
+     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 531.9/531.9 kB 6.6 MB/s eta 0:00:00
+Collecting isodate<0.7.0,>=0.6.0 (from rdflib)
+  Downloading isodate-0.6.1-py2.py3-none-any.whl (41 kB)
+     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 41.7/41.7 kB 4.3 MB/s eta 0:00:00
+Requirement already satisfied: pyparsing<4,>=2.1.0 in /usr/local/lib/python3.10/dist-packages (from rdflib) (3.1.1)
+Requirement already satisfied: six in /usr/local/lib/python3.10/dist-packages (from isodate<0.7.0,>=0.6.0->rdflib) (1.16.0)
+Installing collected packages: isodate, rdflib
+Successfully installed isodate-0.6.1 rdflib-7.0.0
+
+
+
+
[ ]:
+
+
+
import jsonschema
+from jsonschema import validate
+import json
+import rdflib
+
+# Regular JSON representation of a person
+person_data = {
+    "@context": {
+        "schema": "https://schema.org/",
+        "firstName": "schema:givenName",
+        "lastName": "schema:lastName",
+        "birthdate": "schema:birthDate",
+        "institute": "schema:affiliation",
+        "name": "schema:name",
+        "street": "schema:streetAddress",
+        "city": "schema:locality",
+        "zip": "schema:postalCode"
+    },
+    "@id": "https://www.example.com/SimonClark",
+    "@type": "schema:Person",
+    "firstName": "Simon",
+    "lastName": "Clark",
+    "birthdate": "1987-04-23",
+    "institute": {
+        "@id": "https://www.example.com/SINTEF",
+        "@type": "schema:ResearchOrganization",
+        "name": "SINTEF",
+        "street": "Strindvegen 4",
+        "city": "Trondheim",
+        "zip": "7034"
+    }
+}
+
+
+
+

In the JSON-LD example, we added an @context that maps terms in our JSON data to their semantic meanings, using URIs (typically from established vocabularies, like schema.org). This allows machines to understand the semantics behind the data.

+
+
[ ]:
+
+
+
# Regular JSON representation of a person
+person_data = {
+    "@context": "https://schema.org/",
+    "@id": "https://orcid.org/0000-0002-8758-6109",
+    "@type": "Person",
+    "firstName": "Simon",
+    "lastName": "Clark",
+    "gender": {"@type": "Male"},
+    "birthDate": "1987-04-23",
+    "affiliation": {
+        "@id": "https://ror.org/01f677e56",
+        "@type": "ResearchOrganization"
+    }
+}
+
+# email to: simon.clark@sintef.no
+
+
+
+
+
[ ]:
+
+
+
person_schema = {
+    "type": "object",
+    "properties": {
+        "firstName": {
+            "type": "string"
+        },
+        "lastName": {
+            "type": "string",
+            "minLength": 1
+        },
+        "birthDate": {   # Replacing age with birthdate
+            "type": "string",
+            "format": "date",
+            "pattern": "^[0-9]{4}-[0-1][0-9]-[0-3][0-9]$"
+        },
+        "gender": {
+            "type": "object"
+        },
+        "affiliation": {
+            "type": "object"
+        }
+    },
+    "required": ["firstName", "lastName", "birthDate", "affiliation"]  # Updated age to birthdate
+}
+
+# Function to validate JSON data against the schema
+def validate_json(data, schema):
+    try:
+        validate(instance=data, schema=schema)
+        return True, "JSON data is valid according to the schema."
+    except jsonschema.exceptions.ValidationError as ve:
+        return False, ve.message
+
+# Validate the sample JSON data
+is_valid, message = validate_json(person_data, person_schema)
+print(message)
+
+
+
+
+
+
+
+
+JSON data is valid according to the schema.
+
+
+
+
[ ]:
+
+
+
# Create a new graph
+g = rdflib.Graph()
+
+# Load schema.org vocabulary into the graph
+g.parse("https://schema.org/version/latest/schemaorg-current-http.jsonld", format="json-ld")
+
+person_data_str = json.dumps(person_data)
+g.parse(data=person_data_str, format="json-ld")
+
+# Define and execute a SPARQL query for all instances of Organization
+sparql_query = """
+PREFIX schema: <http://schema.org/>
+SELECT DISTINCT ?type WHERE {
+  ?type rdfs:subClassOf* schema:Organization .
+}
+LIMIT 20
+"""
+
+# Execute the SPARQL query
+results = g.query(sparql_query)
+
+# Print the results
+for row in results:
+    print(row)
+
+
+
+
+
+
+
+
+(rdflib.term.URIRef('http://schema.org/Organization'),)
+(rdflib.term.URIRef('http://schema.org/PerformingGroup'),)
+(rdflib.term.URIRef('http://schema.org/TheaterGroup'),)
+(rdflib.term.URIRef('http://schema.org/MusicGroup'),)
+(rdflib.term.URIRef('http://schema.org/DanceGroup'),)
+(rdflib.term.URIRef('http://schema.org/OnlineBusiness'),)
+(rdflib.term.URIRef('http://schema.org/OnlineStore'),)
+(rdflib.term.URIRef('http://schema.org/SportsOrganization'),)
+(rdflib.term.URIRef('http://schema.org/SportsTeam'),)
+(rdflib.term.URIRef('http://schema.org/Airline'),)
+(rdflib.term.URIRef('http://schema.org/SearchRescueOrganization'),)
+(rdflib.term.URIRef('http://schema.org/FundingScheme'),)
+(rdflib.term.URIRef('http://schema.org/NewsMediaOrganization'),)
+(rdflib.term.URIRef('http://schema.org/EducationalOrganization'),)
+(rdflib.term.URIRef('http://schema.org/CollegeOrUniversity'),)
+(rdflib.term.URIRef('http://schema.org/HighSchool'),)
+(rdflib.term.URIRef('http://schema.org/Preschool'),)
+(rdflib.term.URIRef('http://schema.org/ElementarySchool'),)
+(rdflib.term.URIRef('http://schema.org/MiddleSchool'),)
+(rdflib.term.URIRef('http://schema.org/School'),)
+
+
+
+
[ ]:
+
+
+
# Define and execute a SPARQL query for all instances of Organization
+sparql_query = """
+PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
+PREFIX schema: <http://schema.org/>
+
+SELECT ?instance WHERE {
+    ?subclass rdfs:subClassOf* schema:Organization .
+    ?instance rdf:type ?subclass .
+}
+LIMIT 10
+"""
+
+# Execute the SPARQL query
+results = g.query(sparql_query)
+
+# Print the results
+for row in results:
+    print(row[0])
+
+
+
+
+
+
+
+
+https://ror.org/01f677e56
+
+
+
+
[ ]:
+
+
+
# Define and execute a SPARQL query for all instances of Organization
+sparql_query = """
+PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
+PREFIX schema: <http://schema.org/>
+
+SELECT (COUNT(?subject) AS ?numMales) WHERE {
+    ?subject rdf:type schema:Person .
+    ?subject schema:gender ?gender .
+    ?gender rdf:type schema:Male .
+}
+LIMIT 10
+"""
+
+# Execute the SPARQL query
+results = g.query(sparql_query)
+
+# Print the results
+for row in results:
+    print(row.numMales)
+
+
+
+
+
+
+
+
+1
+
+
+
+
[ ]:
+
+
+
# Define and execute a SPARQL query for all instances of Organization
+sparql_query = """
+PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
+PREFIX schema: <http://schema.org/>
+
+SELECT ?bday WHERE {
+    ?subject rdf:type schema:Person .
+    ?subject schema:birthDate ?bday .
+}
+LIMIT 10
+"""
+
+# Execute the SPARQL query
+results = g.query(sparql_query)
+
+# Print the results
+for row in results:
+    print(row[0])
+
+
+
+
+
+
+
+
+1987-04-23
+
+
+
+ + +
+ + + + + +
+ + + +
+ + +
+
+ +
+ +
+
+
+ + + + + +
+ + +
+ + \ No newline at end of file diff --git a/example_person_jsonld_nb.ipynb b/example_person_jsonld_nb.ipynb new file mode 100644 index 0000000..d4afd14 --- /dev/null +++ b/example_person_jsonld_nb.ipynb @@ -0,0 +1,394 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "aw_lp5wfXRSl" + }, + "source": [ + "# JSON-LD Demonstration\n", + "\n", + "In this notebook, we will explore the principles of JSON-LD using the example of a person. JSON-LD stands for \"JSON for Linking Data\" and it provides a method to enrich your JSON data with semantics.\n", + "\n", + "An operational version of this notebook can be accessed [here](https://colab.research.google.com/drive/14XqRJPWs07RUQgZmDZEu3yb2m1xGvxEQ?usp=sharing)." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "y-aalpcNb223", + "outputId": "565a219c-1d10-4b55-fd75-a1fcb2257022" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Requirement already satisfied: jsonschema in /usr/local/lib/python3.10/dist-packages (4.19.0)\n", + "Requirement already satisfied: attrs>=22.2.0 in /usr/local/lib/python3.10/dist-packages (from jsonschema) (23.1.0)\n", + "Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /usr/local/lib/python3.10/dist-packages (from jsonschema) (2023.7.1)\n", + "Requirement already satisfied: referencing>=0.28.4 in /usr/local/lib/python3.10/dist-packages (from jsonschema) (0.30.2)\n", + "Requirement already satisfied: rpds-py>=0.7.1 in /usr/local/lib/python3.10/dist-packages (from jsonschema) (0.10.2)\n", + "Collecting rdflib\n", + " Downloading rdflib-7.0.0-py3-none-any.whl (531 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m531.9/531.9 kB\u001b[0m \u001b[31m6.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hCollecting isodate<0.7.0,>=0.6.0 (from rdflib)\n", + " Downloading isodate-0.6.1-py2.py3-none-any.whl (41 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m41.7/41.7 kB\u001b[0m \u001b[31m4.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hRequirement already satisfied: pyparsing<4,>=2.1.0 in /usr/local/lib/python3.10/dist-packages (from rdflib) (3.1.1)\n", + "Requirement already satisfied: six in /usr/local/lib/python3.10/dist-packages (from isodate<0.7.0,>=0.6.0->rdflib) (1.16.0)\n", + "Installing collected packages: isodate, rdflib\n", + "Successfully installed isodate-0.6.1 rdflib-7.0.0\n" + ] + } + ], + "source": [ + "# Install the required library for JSON schema validation\n", + "!pip install jsonschema\n", + "!pip install rdflib" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "tNjkjGNEXJXP" + }, + "outputs": [], + "source": [ + "import jsonschema\n", + "from jsonschema import validate\n", + "import json\n", + "import rdflib\n", + "\n", + "# Regular JSON representation of a person\n", + "person_data = {\n", + " \"@context\": {\n", + " \"schema\": \"https://schema.org/\",\n", + " \"firstName\": \"schema:givenName\",\n", + " \"lastName\": \"schema:lastName\",\n", + " \"birthdate\": \"schema:birthDate\",\n", + " \"institute\": \"schema:affiliation\",\n", + " \"name\": \"schema:name\",\n", + " \"street\": \"schema:streetAddress\",\n", + " \"city\": \"schema:locality\",\n", + " \"zip\": \"schema:postalCode\"\n", + " },\n", + " \"@id\": \"https://www.example.com/SimonClark\",\n", + " \"@type\": \"schema:Person\",\n", + " \"firstName\": \"Simon\",\n", + " \"lastName\": \"Clark\",\n", + " \"birthdate\": \"1987-04-23\",\n", + " \"institute\": {\n", + " \"@id\": \"https://www.example.com/SINTEF\",\n", + " \"@type\": \"schema:ResearchOrganization\",\n", + " \"name\": \"SINTEF\",\n", + " \"street\": \"Strindvegen 4\",\n", + " \"city\": \"Trondheim\",\n", + " \"zip\": \"7034\"\n", + " }\n", + "}\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "K221MAoHa3Nx" + }, + "source": [ + "In the JSON-LD example, we added an `@context` that maps terms in our JSON data to their semantic meanings, using URIs (typically from established vocabularies, like schema.org). This allows machines to understand the semantics behind the data.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "ZmQfOeFyieo9" + }, + "outputs": [], + "source": [ + "# Regular JSON representation of a person\n", + "person_data = {\n", + " \"@context\": \"https://schema.org/\",\n", + " \"@id\": \"https://orcid.org/0000-0002-8758-6109\",\n", + " \"@type\": \"Person\",\n", + " \"firstName\": \"Simon\",\n", + " \"lastName\": \"Clark\",\n", + " \"gender\": {\"@type\": \"Male\"},\n", + " \"birthDate\": \"1987-04-23\",\n", + " \"affiliation\": {\n", + " \"@id\": \"https://ror.org/01f677e56\",\n", + " \"@type\": \"ResearchOrganization\"\n", + " }\n", + "}\n", + "\n", + "# email to: simon.clark@sintef.no" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "HDHJuV62bTby", + "outputId": "d5537f6e-4325-40ef-dfa4-c7d55159623f" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "JSON data is valid according to the schema.\n" + ] + } + ], + "source": [ + "person_schema = {\n", + " \"type\": \"object\",\n", + " \"properties\": {\n", + " \"firstName\": {\n", + " \"type\": \"string\"\n", + " },\n", + " \"lastName\": {\n", + " \"type\": \"string\",\n", + " \"minLength\": 1\n", + " },\n", + " \"birthDate\": { # Replacing age with birthdate\n", + " \"type\": \"string\",\n", + " \"format\": \"date\",\n", + " \"pattern\": \"^[0-9]{4}-[0-1][0-9]-[0-3][0-9]$\"\n", + " },\n", + " \"gender\": {\n", + " \"type\": \"object\"\n", + " },\n", + " \"affiliation\": {\n", + " \"type\": \"object\"\n", + " }\n", + " },\n", + " \"required\": [\"firstName\", \"lastName\", \"birthDate\", \"affiliation\"] # Updated age to birthdate\n", + "}\n", + "\n", + "# Function to validate JSON data against the schema\n", + "def validate_json(data, schema):\n", + " try:\n", + " validate(instance=data, schema=schema)\n", + " return True, \"JSON data is valid according to the schema.\"\n", + " except jsonschema.exceptions.ValidationError as ve:\n", + " return False, ve.message\n", + "\n", + "# Validate the sample JSON data\n", + "is_valid, message = validate_json(person_data, person_schema)\n", + "print(message)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "R-mO4FGtbr-L", + "outputId": "c0ae5e87-6ade-4ef8-a639-02bf287071a9" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(rdflib.term.URIRef('http://schema.org/Organization'),)\n", + "(rdflib.term.URIRef('http://schema.org/PerformingGroup'),)\n", + "(rdflib.term.URIRef('http://schema.org/TheaterGroup'),)\n", + "(rdflib.term.URIRef('http://schema.org/MusicGroup'),)\n", + "(rdflib.term.URIRef('http://schema.org/DanceGroup'),)\n", + "(rdflib.term.URIRef('http://schema.org/OnlineBusiness'),)\n", + "(rdflib.term.URIRef('http://schema.org/OnlineStore'),)\n", + "(rdflib.term.URIRef('http://schema.org/SportsOrganization'),)\n", + "(rdflib.term.URIRef('http://schema.org/SportsTeam'),)\n", + "(rdflib.term.URIRef('http://schema.org/Airline'),)\n", + "(rdflib.term.URIRef('http://schema.org/SearchRescueOrganization'),)\n", + "(rdflib.term.URIRef('http://schema.org/FundingScheme'),)\n", + "(rdflib.term.URIRef('http://schema.org/NewsMediaOrganization'),)\n", + "(rdflib.term.URIRef('http://schema.org/EducationalOrganization'),)\n", + "(rdflib.term.URIRef('http://schema.org/CollegeOrUniversity'),)\n", + "(rdflib.term.URIRef('http://schema.org/HighSchool'),)\n", + "(rdflib.term.URIRef('http://schema.org/Preschool'),)\n", + "(rdflib.term.URIRef('http://schema.org/ElementarySchool'),)\n", + "(rdflib.term.URIRef('http://schema.org/MiddleSchool'),)\n", + "(rdflib.term.URIRef('http://schema.org/School'),)\n" + ] + } + ], + "source": [ + "# Create a new graph\n", + "g = rdflib.Graph()\n", + "\n", + "# Load schema.org vocabulary into the graph\n", + "g.parse(\"https://schema.org/version/latest/schemaorg-current-http.jsonld\", format=\"json-ld\")\n", + "\n", + "person_data_str = json.dumps(person_data)\n", + "g.parse(data=person_data_str, format=\"json-ld\")\n", + "\n", + "# Define and execute a SPARQL query for all instances of Organization\n", + "sparql_query = \"\"\"\n", + "PREFIX schema: \n", + "SELECT DISTINCT ?type WHERE {\n", + " ?type rdfs:subClassOf* schema:Organization .\n", + "}\n", + "LIMIT 20\n", + "\"\"\"\n", + "\n", + "# Execute the SPARQL query\n", + "results = g.query(sparql_query)\n", + "\n", + "# Print the results\n", + "for row in results:\n", + " print(row)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "h4vvw5hNhih2", + "outputId": "77828fc9-bafe-414b-f6f6-65fb117aabc5" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "https://ror.org/01f677e56\n" + ] + } + ], + "source": [ + "# Define and execute a SPARQL query for all instances of Organization\n", + "sparql_query = \"\"\"\n", + "PREFIX rdf: \n", + "PREFIX rdfs: \n", + "PREFIX schema: \n", + "\n", + "SELECT ?instance WHERE {\n", + " ?subclass rdfs:subClassOf* schema:Organization .\n", + " ?instance rdf:type ?subclass .\n", + "}\n", + "LIMIT 10\n", + "\"\"\"\n", + "\n", + "# Execute the SPARQL query\n", + "results = g.query(sparql_query)\n", + "\n", + "# Print the results\n", + "for row in results:\n", + " print(row[0])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "e_-Qa3Hgh2kg", + "outputId": "2b9fafa4-fca4-426f-e768-6ef561921b14" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n" + ] + } + ], + "source": [ + "# Define and execute a SPARQL query for all instances of Organization\n", + "sparql_query = \"\"\"\n", + "PREFIX rdf: \n", + "PREFIX rdfs: \n", + "PREFIX schema: \n", + "\n", + "SELECT (COUNT(?subject) AS ?numMales) WHERE {\n", + " ?subject rdf:type schema:Person .\n", + " ?subject schema:gender ?gender .\n", + " ?gender rdf:type schema:Male .\n", + "}\n", + "LIMIT 10\n", + "\"\"\"\n", + "\n", + "# Execute the SPARQL query\n", + "results = g.query(sparql_query)\n", + "\n", + "# Print the results\n", + "for row in results:\n", + " print(row.numMales)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "HJfpCj4-sww3", + "outputId": "c4ba6b30-7d7e-45d9-c3e4-b0d311e0fdd0" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1987-04-23\n" + ] + } + ], + "source": [ + "# Define and execute a SPARQL query for all instances of Organization\n", + "sparql_query = \"\"\"\n", + "PREFIX rdf: \n", + "PREFIX rdfs: \n", + "PREFIX schema: \n", + "\n", + "SELECT ?bday WHERE {\n", + " ?subject rdf:type schema:Person .\n", + " ?subject schema:birthDate ?bday .\n", + "}\n", + "LIMIT 10\n", + "\"\"\"\n", + "\n", + "# Execute the SPARQL query\n", + "results = g.query(sparql_query)\n", + "\n", + "# Print the results\n", + "for row in results:\n", + " print(row[0])" + ] + } + ], + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/example_zinc_electrode.html b/example_zinc_electrode.html index afe7b5f..f25d9a7 100644 --- a/example_zinc_electrode.html +++ b/example_zinc_electrode.html @@ -44,6 +44,7 @@ + @@ -483,7 +484,7 @@

Zinc Electrode diff --git a/example_zinc_powder.html b/example_zinc_powder.html index 4823d3d..b648375 100644 --- a/example_zinc_powder.html +++ b/example_zinc_powder.html @@ -44,6 +44,7 @@ + @@ -455,7 +456,7 @@

Zinc Powder diff --git a/examples.html b/examples.html index 23566c8..702f9b4 100644 --- a/examples.html +++ b/examples.html @@ -44,6 +44,7 @@ + @@ -506,7 +507,7 @@

Examples diff --git a/faq.html b/faq.html index cfb115a..704305a 100644 --- a/faq.html +++ b/faq.html @@ -44,12 +44,13 @@ + - + @@ -406,12 +407,12 @@

FAQ Page

@@ -458,7 +459,7 @@

FAQ Page diff --git a/genindex.html b/genindex.html index f4c4c48..432ee4d 100644 --- a/genindex.html +++ b/genindex.html @@ -43,6 +43,7 @@ + @@ -373,7 +374,7 @@

Index