|
1 | 1 | { |
2 | 2 | "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "id": "ed01a0cd-1fdc-4c34-a88f-0f190e0299ed", |
| 6 | + "metadata": {}, |
| 7 | + "source": [ |
| 8 | + "# Creation of Bioschemas property pages\n", |
| 9 | + "\n", |
| 10 | + "Based on the JSON-LD from DDE, corresponding to Bioschemas released types, we create a page for each Bioschemas property declared in that file. This script needs to be re-run and pages committed and merged whenever there is a change in the releases types. It uses the modified Bioschemas types file that already uses the canonical Bioschemas URL https://bioschemas.org/terms/" |
| 11 | + ] |
| 12 | + }, |
| 13 | + { |
| 14 | + "cell_type": "markdown", |
| 15 | + "id": "08b59295-7fad-4278-8c94-0d42819f60ba", |
| 16 | + "metadata": {}, |
| 17 | + "source": [ |
| 18 | + "## Installation of packages" |
| 19 | + ] |
| 20 | + }, |
3 | 21 | { |
4 | 22 | "cell_type": "code", |
5 | | - "execution_count": null, |
| 23 | + "execution_count": 1, |
6 | 24 | "id": "239dffc4-6f7c-4b93-be8f-f2be4243b205", |
7 | 25 | "metadata": {}, |
8 | | - "outputs": [], |
| 26 | + "outputs": [ |
| 27 | + { |
| 28 | + "name": "stdout", |
| 29 | + "output_type": "stream", |
| 30 | + "text": [ |
| 31 | + "Requirement already satisfied: rdflib in c:\\software\\iniforge3\\lib\\site-packages (7.1.3)\n", |
| 32 | + "Requirement already satisfied: pyparsing<4,>=2.1.0 in c:\\software\\iniforge3\\lib\\site-packages (from rdflib) (3.2.1)\n" |
| 33 | + ] |
| 34 | + } |
| 35 | + ], |
9 | 36 | "source": [ |
10 | 37 | "import sys\n", |
11 | 38 | "!{sys.executable} -m pip install rdflib" |
12 | 39 | ] |
13 | 40 | }, |
14 | 41 | { |
15 | 42 | "cell_type": "code", |
16 | | - "execution_count": 7, |
| 43 | + "execution_count": 2, |
17 | 44 | "id": "6bae07c0-76c4-4941-97c3-5cd99f67fb1b", |
18 | 45 | "metadata": {}, |
19 | 46 | "outputs": [ |
|
32 | 59 | }, |
33 | 60 | { |
34 | 61 | "cell_type": "code", |
35 | | - "execution_count": 9, |
| 62 | + "execution_count": 3, |
36 | 63 | "id": "5641415a-538d-4d19-9739-c8f47712cceb", |
37 | 64 | "metadata": {}, |
38 | 65 | "outputs": [], |
|
43 | 70 | "from rdflib.namespace import RDFS" |
44 | 71 | ] |
45 | 72 | }, |
| 73 | + { |
| 74 | + "cell_type": "markdown", |
| 75 | + "id": "22bf06fe-ba13-4546-a6ae-a3f2e25aace9", |
| 76 | + "metadata": {}, |
| 77 | + "source": [ |
| 78 | + "## Load the Bioschemas released types JSON-LD as RDF" |
| 79 | + ] |
| 80 | + }, |
46 | 81 | { |
47 | 82 | "cell_type": "code", |
48 | | - "execution_count": 21, |
| 83 | + "execution_count": 6, |
49 | 84 | "id": "c3b5ac2d-0086-48bb-8a74-a4c0c7f43a7b", |
50 | 85 | "metadata": {}, |
51 | 86 | "outputs": [], |
|
56 | 91 | "\n", |
57 | 92 | "schema_domain = URIRef(\"https://schema.org/domainIncludes\")\n", |
58 | 93 | "schema_range = URIRef(\"https://schema.org/rangeIncludes\")\n", |
59 | | - "bs_ns = \"https://bioschemas.org/terms/\"\n", |
60 | | - "\n", |
| 94 | + "bs_ns = \"https://bioschemas.org/terms/\"" |
| 95 | + ] |
| 96 | + }, |
| 97 | + { |
| 98 | + "cell_type": "markdown", |
| 99 | + "id": "a3ca2232-1e5f-4148-8089-19cb4cfa5c56", |
| 100 | + "metadata": {}, |
| 101 | + "source": [ |
| 102 | + "## For each property, get the domain and name, and create the corresponding page" |
| 103 | + ] |
| 104 | + }, |
| 105 | + { |
| 106 | + "cell_type": "code", |
| 107 | + "execution_count": 11, |
| 108 | + "id": "b420daf4-8580-4ebf-98f3-dcfee0485d18", |
| 109 | + "metadata": {}, |
| 110 | + "outputs": [], |
| 111 | + "source": [ |
61 | 112 | "for s in g.subjects(predicate=schema_domain, unique=True) :\n", |
62 | 113 | " prop_name = str(s).split('/')[-1]\n", |
63 | 114 | " \n", |
|
74 | 125 | " all_range = 'expected_values_as_type: \\n' \n", |
75 | 126 | " for prop_range in g.objects(subject=s, predicate=schema_range) :\n", |
76 | 127 | " range_name = str(prop_range).split('/')[-1]\n", |
77 | | - " all_range += '- ' + range_name + '\\n'\n", |
| 128 | + " all_range += '- [\"' + range_name + '\", \"' + str(prop_range) + '\"]\\n'\n", |
78 | 129 | "\n", |
79 | 130 | " prop_yaml_str += all_domain\n", |
80 | 131 | " prop_yaml_str += all_range\n", |
81 | | - " with open(prop_name + '.html', 'w') as file:\n", |
| 132 | + " with open('../pages/_properties/' + prop_name + '.html', 'w') as file:\n", |
82 | 133 | " file.write(\"---\\n\")\n", |
83 | 134 | " file.write(prop_yaml_str)\n", |
84 | 135 | " file.write(\"\\n---\\n\\n\")\n", |
85 | | - " file.write(\"{% include properties.html %}\\n\")\n" |
| 136 | + " file.write(\"{% include properties.html %}\\n\")" |
| 137 | + ] |
| 138 | + }, |
| 139 | + { |
| 140 | + "cell_type": "markdown", |
| 141 | + "id": "b4619d41-26ef-4c7d-a610-bd5b0c2eb503", |
| 142 | + "metadata": {}, |
| 143 | + "source": [ |
| 144 | + "### ToDo - Improvements \n", |
| 145 | + "- Move the code to a script that can be integrated into GitHub actions\n", |
| 146 | + "- Do something similar for draft properties (requires a modification of the landing page for properties as right now is only a list, supporting released and draft types would require tabs similar to types page)\n" |
86 | 147 | ] |
87 | 148 | }, |
88 | 149 | { |
89 | 150 | "cell_type": "code", |
90 | 151 | "execution_count": null, |
91 | | - "id": "b420daf4-8580-4ebf-98f3-dcfee0485d18", |
| 152 | + "id": "027029bf-d750-4ff5-9dd2-c3fe68cd9d16", |
92 | 153 | "metadata": {}, |
93 | 154 | "outputs": [], |
94 | 155 | "source": [] |
|
0 commit comments