-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update example_person_jsonld_nb.ipynb
- Loading branch information
1 parent
fe5b026
commit fe1bee0
Showing
1 changed file
with
116 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,32 @@ | ||
{ | ||
"nbformat": 4, | ||
"nbformat_minor": 0, | ||
"metadata": { | ||
"colab": { | ||
"provenance": [] | ||
}, | ||
"kernelspec": { | ||
"name": "python3", | ||
"display_name": "Python 3" | ||
}, | ||
"language_info": { | ||
"name": "python" | ||
} | ||
}, | ||
"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." | ||
], | ||
"metadata": { | ||
"id": "aw_lp5wfXRSl" | ||
} | ||
"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", | ||
"source": [ | ||
"# Install the required library for JSON schema validation\n", | ||
"!pip install jsonschema\n", | ||
"!pip install rdflib" | ||
], | ||
"execution_count": null, | ||
"metadata": { | ||
"colab": { | ||
"base_uri": "https://localhost:8080/" | ||
}, | ||
"id": "y-aalpcNb223", | ||
"outputId": "565a219c-1d10-4b55-fd75-a1fcb2257022" | ||
}, | ||
"execution_count": null, | ||
"outputs": [ | ||
{ | ||
"output_type": "stream", | ||
"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", | ||
|
@@ -62,6 +45,11 @@ | |
"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" | ||
] | ||
}, | ||
{ | ||
|
@@ -108,15 +96,20 @@ | |
}, | ||
{ | ||
"cell_type": "markdown", | ||
"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" | ||
], | ||
"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", | ||
|
@@ -134,15 +127,27 @@ | |
"}\n", | ||
"\n", | ||
"# email to: [email protected]" | ||
], | ||
"metadata": { | ||
"id": "ZmQfOeFyieo9" | ||
}, | ||
"execution_count": null, | ||
"outputs": [] | ||
] | ||
}, | ||
{ | ||
"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", | ||
|
@@ -180,27 +185,46 @@ | |
"# 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": "HDHJuV62bTby", | ||
"outputId": "d5537f6e-4325-40ef-dfa4-c7d55159623f" | ||
"id": "R-mO4FGtbr-L", | ||
"outputId": "c0ae5e87-6ade-4ef8-a639-02bf287071a9" | ||
}, | ||
"execution_count": null, | ||
"outputs": [ | ||
{ | ||
"output_type": "stream", | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"JSON data is valid according to the schema.\n" | ||
"(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" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
], | ||
"source": [ | ||
"# Create a new graph\n", | ||
"g = rdflib.Graph()\n", | ||
|
@@ -226,46 +250,27 @@ | |
"# 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": "R-mO4FGtbr-L", | ||
"outputId": "c0ae5e87-6ade-4ef8-a639-02bf287071a9" | ||
"id": "h4vvw5hNhih2", | ||
"outputId": "77828fc9-bafe-414b-f6f6-65fb117aabc5" | ||
}, | ||
"execution_count": null, | ||
"outputs": [ | ||
{ | ||
"output_type": "stream", | ||
"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" | ||
"https://ror.org/01f677e56\n" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
], | ||
"source": [ | ||
"# Define and execute a SPARQL query for all instances of Organization\n", | ||
"sparql_query = \"\"\"\n", | ||
|
@@ -286,27 +291,27 @@ | |
"# 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": "h4vvw5hNhih2", | ||
"outputId": "77828fc9-bafe-414b-f6f6-65fb117aabc5" | ||
"id": "e_-Qa3Hgh2kg", | ||
"outputId": "2b9fafa4-fca4-426f-e768-6ef561921b14" | ||
}, | ||
"execution_count": null, | ||
"outputs": [ | ||
{ | ||
"output_type": "stream", | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"https://ror.org/01f677e56\n" | ||
"1\n" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
], | ||
"source": [ | ||
"# Define and execute a SPARQL query for all instances of Organization\n", | ||
"sparql_query = \"\"\"\n", | ||
|
@@ -328,27 +333,27 @@ | |
"# 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": "e_-Qa3Hgh2kg", | ||
"outputId": "2b9fafa4-fca4-426f-e768-6ef561921b14" | ||
"id": "HJfpCj4-sww3", | ||
"outputId": "c4ba6b30-7d7e-45d9-c3e4-b0d311e0fdd0" | ||
}, | ||
"execution_count": null, | ||
"outputs": [ | ||
{ | ||
"output_type": "stream", | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"1\n" | ||
"1987-04-23\n" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
], | ||
"source": [ | ||
"# Define and execute a SPARQL query for all instances of Organization\n", | ||
"sparql_query = \"\"\"\n", | ||
|
@@ -369,24 +374,21 @@ | |
"# Print the results\n", | ||
"for row in results:\n", | ||
" print(row[0])" | ||
], | ||
"metadata": { | ||
"colab": { | ||
"base_uri": "https://localhost:8080/" | ||
}, | ||
"id": "HJfpCj4-sww3", | ||
"outputId": "c4ba6b30-7d7e-45d9-c3e4-b0d311e0fdd0" | ||
}, | ||
"execution_count": null, | ||
"outputs": [ | ||
{ | ||
"output_type": "stream", | ||
"name": "stdout", | ||
"text": [ | ||
"1987-04-23\n" | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"colab": { | ||
"provenance": [] | ||
}, | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"name": "python" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 0 | ||
} |