2021-10-06 18:13:21 +02:00
|
|
|
{
|
|
|
|
"cells": [
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2021-10-28 09:04:51 +02:00
|
|
|
"execution_count": 1,
|
2021-10-06 18:13:21 +02:00
|
|
|
"id": "solid-grove",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"from rdflib import Graph\n",
|
|
|
|
"from rdflib.namespace import OWL, DC, DCTERMS, RDF, RDFS, SKOS, XSD\n",
|
|
|
|
"from rdflib import URIRef, BNode, Literal\n",
|
|
|
|
"import json\n",
|
|
|
|
"import os\n",
|
|
|
|
"import pandas as pd\n",
|
|
|
|
"import pylode"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2021-10-28 09:04:51 +02:00
|
|
|
"execution_count": 2,
|
2021-10-06 18:13:21 +02:00
|
|
|
"id": "spiritual-geography",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"g = Graph()\n",
|
|
|
|
"\n",
|
|
|
|
"##namespace\n",
|
|
|
|
"NS = \"http://idss.org/terms/\"\n",
|
|
|
|
"## create ontology\n",
|
|
|
|
"iseal = URIRef(NS)\n",
|
|
|
|
"g.add((iseal, RDF.type, OWL.Ontology)) "
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2021-10-28 09:04:51 +02:00
|
|
|
"execution_count": 4,
|
2021-10-06 18:13:21 +02:00
|
|
|
"id": "competitive-turkish",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
2021-10-28 09:04:51 +02:00
|
|
|
"df = pd.read_excel('/Users/marie-angeliquelaporte/Documents/jupyter/ISEAL/idss_schema_fields.xlsx')\n",
|
2021-10-06 18:13:21 +02:00
|
|
|
"df.dropna(how='all', axis=1)\n",
|
|
|
|
"df.fillna('', inplace=True)\n",
|
|
|
|
"\n",
|
|
|
|
"\n",
|
|
|
|
"for index, row in df.iterrows() :\n",
|
|
|
|
" element_name = row['element name']\n",
|
|
|
|
" element_description = row['element description']\n",
|
|
|
|
" comment = row['element guidance']\n",
|
|
|
|
" example = row['element link for more information']\n",
|
|
|
|
" cardinality = row['element options']\n",
|
|
|
|
" prop_type = row['element type']\n",
|
|
|
|
" controlled_vocab = row['element controlled values or terms']\n",
|
|
|
|
" module = row['idss module']\n",
|
|
|
|
" module_cat = row['idss module category']\n",
|
|
|
|
" \n",
|
|
|
|
" ##module\n",
|
|
|
|
" moduleUri = URIRef(NS+module)\n",
|
|
|
|
" if not (None, SKOS.prefLabel, Literal(module)) in g:\n",
|
|
|
|
" ##create module as skos concept\n",
|
|
|
|
" g.add((moduleUri, RDF.type, OWL.Class)) ## SKOS.Concept\n",
|
|
|
|
" g.add((moduleUri, SKOS.prefLabel, Literal(module)))\n",
|
|
|
|
" ##element\n",
|
|
|
|
" if '-' in element_name:\n",
|
|
|
|
" concept = element_name.split(' - ')[0]\n",
|
|
|
|
" element = element_name.split(' - ')[1]\n",
|
|
|
|
" \n",
|
|
|
|
" conceptUri = URIRef(NS+concept.replace(\" \", \"_\"))\n",
|
|
|
|
" if not (None, SKOS.prefLabel, Literal(concept)) in g:\n",
|
|
|
|
" ##create concept as skos concept\n",
|
|
|
|
" g.add((conceptUri, RDF.type, OWL.Class)) ## SKOS.Concept\n",
|
|
|
|
" g.add((conceptUri, SKOS.prefLabel, Literal(concept)))\n",
|
|
|
|
" g.add((conceptUri, RDFS.subClassOf, moduleUri))\n",
|
|
|
|
" \n",
|
|
|
|
" ## create properties\n",
|
|
|
|
" elementURI = URIRef(NS+element.replace(\" \", \"_\"))\n",
|
|
|
|
" if prop_type == 'CONTROLLED VALUE': ## object property\n",
|
|
|
|
" g.add((elementURI, SKOS.prefLabel, Literal(element)))\n",
|
|
|
|
" g.add((elementURI, RDF.type, OWL.ObjectProperty))\n",
|
2021-10-28 09:04:51 +02:00
|
|
|
" g.add((elementURI, RDFS.domain, conceptUri))\n",
|
2021-10-06 18:13:21 +02:00
|
|
|
" \n",
|
|
|
|
" ## create controlled vocab\n",
|
|
|
|
" cvURI = URIRef(NS+\"VOCAB_\"+element.replace(\" \", \"_\"))\n",
|
|
|
|
" g.add((cvURI, RDF.type, OWL.Class)) ## SKOS.Concept ## SKOS.Collection??\n",
|
|
|
|
" g.add((cvURI, SKOS.prefLabel, Literal(\"VOCAB \"+element)))\n",
|
|
|
|
" for term in controlled_vocab.split(\"||\"):\n",
|
|
|
|
" termURI = URIRef(NS+term.replace(\" \", \"_\").replace(\"|\", \"\"))\n",
|
|
|
|
" g.add((termURI, RDF.type, OWL.Class)) ## SKOS.Concept\n",
|
|
|
|
" g.add((termURI, SKOS.prefLabel, Literal(term)))\n",
|
|
|
|
" g.add((termURI, RDFS.subClassOf, cvURI)) ## SKOS.member???\n",
|
|
|
|
" g.add((elementURI, OWL.range, cvURI))\n",
|
|
|
|
" \n",
|
|
|
|
" ## cardinality\n",
|
|
|
|
" if cardinality == 'MULTI SELECT FROM CONTROL LIST':\n",
|
|
|
|
" br = BNode()\n",
|
|
|
|
" g.add((br, RDF.type, OWL.Restriction))\n",
|
|
|
|
" g.add((br, OWL.onProperty, elementURI))\n",
|
|
|
|
" g.add((br, OWL.someValuesFrom, cvURI))\n",
|
|
|
|
" g.add((conceptUri, RDFS.subClassOf, br))\n",
|
|
|
|
" else:\n",
|
|
|
|
" br = BNode()\n",
|
|
|
|
" g.add((br, RDF.type, OWL.Restriction))\n",
|
|
|
|
" g.add((br, OWL.onProperty, elementURI))\n",
|
|
|
|
" g.add((br, OWL.maxQualifiedCardinality, Literal(1)))\n",
|
|
|
|
" g.add((br, OWL.onClass, cvURI))\n",
|
|
|
|
" g.add((conceptUri, RDFS.subClassOf, br))\n",
|
|
|
|
" \n",
|
|
|
|
" #elif prop_type == 'URL': ## object property\n",
|
|
|
|
" # g.add((elementURI, RDF.type, OWL.ObjectProperty))\n",
|
|
|
|
" # g.add((elementURI, OWL.domain, conceptUri))\n",
|
|
|
|
" # g.add((elementURI, OWL.range, URIRef(\"\") ))\n",
|
|
|
|
" # g.add((elementURI, SKOS.prefLabel, Literal(element)))\n",
|
|
|
|
" else: ## datatype properties\n",
|
|
|
|
" g.add((elementURI, SKOS.prefLabel, Literal(element)))\n",
|
|
|
|
" g.add((elementURI, RDF.type, OWL.DatatypeProperty))\n",
|
2021-10-28 09:04:51 +02:00
|
|
|
" g.add((elementURI, RDFS.domain, conceptUri))\n",
|
2021-10-06 18:13:21 +02:00
|
|
|
" range = None\n",
|
|
|
|
" if prop_type == 'DATE':\n",
|
2021-10-28 09:04:51 +02:00
|
|
|
" g.add((elementURI, RDFS.range, XSD.date ))\n",
|
2021-10-06 18:13:21 +02:00
|
|
|
" range = XSD.date\n",
|
|
|
|
" elif prop_type == 'NUMERIC VALUE':\n",
|
2021-10-28 09:04:51 +02:00
|
|
|
" g.add((elementURI, RDFS.range, XSD.float))\n",
|
2021-10-06 18:13:21 +02:00
|
|
|
" range = XSD.float\n",
|
|
|
|
" else:\n",
|
2021-10-28 09:04:51 +02:00
|
|
|
" g.add((elementURI, RDFS.range, XSD.string))\n",
|
2021-10-06 18:13:21 +02:00
|
|
|
" range = XSD.string\n",
|
|
|
|
" ##cardinality\n",
|
|
|
|
" if cardinality == 'REPEAT VALUES':\n",
|
|
|
|
" br = BNode()\n",
|
|
|
|
" g.add((br, RDF.type, OWL.Restriction))\n",
|
|
|
|
" g.add((br, OWL.onProperty, elementURI))\n",
|
|
|
|
" g.add((br, OWL.someValuesFrom, range))\n",
|
|
|
|
" g.add((conceptUri, RDFS.subClassOf, br))\n",
|
|
|
|
" else:\n",
|
|
|
|
" br = BNode()\n",
|
|
|
|
" g.add((br, RDF.type, OWL.Restriction))\n",
|
|
|
|
" g.add((br, OWL.onProperty, elementURI))\n",
|
|
|
|
" g.add((br, OWL.maxQualifiedCardinality, Literal(1)))\n",
|
|
|
|
" g.add((br, OWL.onDataRange, range))\n",
|
|
|
|
" g.add((conceptUri, RDFS.subClassOf, br))\n",
|
|
|
|
" \n",
|
|
|
|
" \n",
|
|
|
|
" if comment:\n",
|
|
|
|
" g.add((elementURI, SKOS.scopeNote, Literal(comment)))\n",
|
|
|
|
" if example:\n",
|
|
|
|
" g.add((elementURI, RDFS.comment, Literal(example)))\n",
|
|
|
|
" if element_description:\n",
|
|
|
|
" g.add((elementURI, SKOS.definition, Literal(element_description)))\n",
|
|
|
|
" else:\n",
|
|
|
|
" print(element_name)\n",
|
|
|
|
" \n",
|
|
|
|
" \n",
|
|
|
|
" \n",
|
|
|
|
" "
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": null,
|
|
|
|
"id": "subject-asian",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": []
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2021-10-28 09:04:51 +02:00
|
|
|
"execution_count": 5,
|
2021-10-06 18:13:21 +02:00
|
|
|
"id": "sudden-elite",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"## save graph\n",
|
|
|
|
"g.serialize(destination='idds.ttl', format='turtle')"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2021-10-28 09:04:51 +02:00
|
|
|
"execution_count": null,
|
2021-10-06 18:13:21 +02:00
|
|
|
"id": "subsequent-zealand",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"html = pylode.MakeDocco(\n",
|
|
|
|
" input_data_file=\"idds.ttl\",\n",
|
|
|
|
" outputformat=\"html\",\n",
|
|
|
|
" profile=\"ontdoc\"\n",
|
|
|
|
").document()"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2021-10-28 09:04:51 +02:00
|
|
|
"execution_count": null,
|
2021-10-06 18:13:21 +02:00
|
|
|
"id": "occupied-caribbean",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"f = open('documentation.html', 'w' )\n",
|
|
|
|
"f.write( html )\n",
|
|
|
|
"f.close()"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": null,
|
|
|
|
"id": "abstract-consortium",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": []
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"metadata": {
|
|
|
|
"kernelspec": {
|
|
|
|
"display_name": "Python 3",
|
|
|
|
"language": "python",
|
|
|
|
"name": "python3"
|
|
|
|
},
|
|
|
|
"language_info": {
|
|
|
|
"codemirror_mode": {
|
|
|
|
"name": "ipython",
|
|
|
|
"version": 3
|
|
|
|
},
|
|
|
|
"file_extension": ".py",
|
|
|
|
"mimetype": "text/x-python",
|
|
|
|
"name": "python",
|
|
|
|
"nbconvert_exporter": "python",
|
|
|
|
"pygments_lexer": "ipython3",
|
|
|
|
"version": "3.9.2"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"nbformat": 4,
|
|
|
|
"nbformat_minor": 5
|
|
|
|
}
|