{ "cells": [ { "cell_type": "markdown", "id": "4fb8173d-b02d-4665-942c-0d70d9a94042", "metadata": {}, "source": [ "# GenDifS Hello World\n", "\n", "GenDifS is a language for generating one or more taxonomies from a single mind map.\n", "The taxonomies are exported into various knowlede models, in particular a lightweight OWL T-Box and SKOS A-Box.\n", "We present a minimal example here.\n", "\n", "![](../../images/hello-world.mm.png)\n", "\n", "We can read the following from this mind map.\n", "* There is a taxonomy with the name *hello*.\n", "* We have six (!) categories.\n", " * On the one hand, we have first-order classes that we want to describe. These are printed in bold in the mindmap, but they don't have to be: *Greting*, *Hello* and *Приве́т!!*\n", " * In addition, we have some second-order classes. They help us to classify the first-order classes: *Language*, *en* and *ru*.\n", "* The tree of the mind map rightly suggests a subclass relationship: *Hello* and *Приве́т!* are subcategories of *Greeting*.\n", "* In addition there is a second subclass relationship somehow \"woven in\": *en* and *ru* are subcategories of *Language*.\n", "* The property *has_language* can accept values from the Language category, among others. (And no, interpreting this information as a *rdfs:range* would be wrong. It is correct to construct an OWL restriction here. )\n", "\n", "The question arises as to how this information can be formalized in the various semantic web language like RDFS, SKOS or OWL.\n", "\n", "There are at least three possibilities here.\n", "* Firstly, we create a pure RDFS class tree. As a result, we get classes and subclasses. \n", "* Secondly, we create a SKOS thesaurus. As a result we get a network of instances of the class `skos:Concept`. (2024-09-25: The SKOS export is a laborious task and is not yet fully implemented.)\n", "* Thirdly, we create a lighweight OWL ontology. As a result, we can enrich the RDFS class tree with so called *restrictions*.\n", "\n", "GenDifS generates all three dialects. The namespaces are chosen so that we can use all three dialects at the same time. In particular, setting up the OWL restrictions manually is time-consuming and error-prone. One of the strengths of GenDifS is its ability to construct complex OWL axioms from a simple notation." ] }, { "cell_type": "code", "execution_count": 1, "id": "9fbfe4d9-b3cf-4c03-aaf6-6f69889b3e93", "metadata": {}, "outputs": [], "source": [ "from gd07 import GenDifS" ] }, { "cell_type": "code", "execution_count": 2, "id": "65228901-708b-4c06-91fa-67e1983fbaa7", "metadata": {}, "outputs": [], "source": [ "m = GenDifS(\"../mm/hello-world.mm\")\n", "m.compile()" ] }, { "cell_type": "code", "execution_count": 3, "id": "b0f4342c", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ID_319523876 TAXONOMY hello: #7 GenDifS nodes;\n", "self.languages={'OWLtest', 'OWL', 'SKOS', 'RDFS', 'DE', 'RDFStest'};\n", "self.rdf_graphs.keys()=dict_keys(['OWLtest', 'OWL', 'SKOS', 'RDFS', 'DE', 'RDFStest'])\n" ] } ], "source": [ "m.taxonomies_by_name[\"hello\"].describe()" ] }, { "cell_type": "code", "execution_count": 4, "id": "1d251554", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "@prefix : .\n", "@prefix owl: .\n", "@prefix rdfs: .\n", "\n", ":Hello a owl:Class ;\n", " rdfs:subClassOf :Greeting .\n", "\n", ":en rdfs:subClassOf :Language .\n", "\n", ":ru rdfs:subClassOf :Language .\n", "\n", ":Приве_т_ a owl:Class ;\n", " rdfs:subClassOf :Greeting .\n", "\n", ":Greeting a owl:Class .\n", "\n", "\n" ] } ], "source": [ "print(m.taxonomies_by_name[\"hello\"].rdf_graphs_ttl[\"RDFS\"])" ] }, { "cell_type": "code", "execution_count": 5, "id": "2f30c8b8", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "@prefix cpt: .\n", "@prefix skos: .\n", "\n", "cpt:Greeting a skos:Concept ;\n", " skos:inScheme cpt:hello .\n", "\n", "cpt:hello a skos:ConceptScheme .\n", "\n", "\n" ] } ], "source": [ "print(m.taxonomies_by_name[\"hello\"].rdf_graphs_ttl[\"SKOS\"])" ] }, { "cell_type": "code", "execution_count": 6, "id": "1c0a9572-4064-4dca-ad1d-1db83c3a43a4", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "@prefix : .\n", "@prefix owl: .\n", "@prefix rdf: .\n", "@prefix rdfs: .\n", "\n", ":BY_ID_1952656871_intersection a owl:class ;\n", " rdfs:label \"BY_ex:has_language_FROM_ex:Language_INTERSECT_ex:Greeting\" ;\n", " rdfs:subClassOf :Greeting ;\n", " owl:intersectionOf ( :BY_ID_1952656871_restriction :Greeting ) .\n", "\n", ":BY_SOME_ID_1543072838_intersection a owl:class ;\n", " rdfs:label \"(BY_ex:has_language_FROM_ex:Language_SOME_ex:ru)_INTERSECT_ex:Greeting\" ;\n", " rdfs:subClassOf :Приве_т_ ;\n", " owl:intersectionOf ( :BY_SOME_ID_1543072838_restriction :Greeting ) .\n", "\n", ":BY_SOME_ID_988527468_intersection a owl:class ;\n", " rdfs:label \"(BY_ex:has_language_FROM_ex:Language_SOME_ex:en)_INTERSECT_ex:Greeting\" ;\n", " rdfs:subClassOf :Hello ;\n", " owl:intersectionOf ( :BY_SOME_ID_988527468_restriction :Greeting ) .\n", "\n", ":BY_ID_1952656871_restriction a owl:Restriction,\n", " owl:class ;\n", " rdfs:label \"BY_ex:has_language_FROM_ex:Language\" ;\n", " owl:onProperty :has_language ;\n", " owl:someValuesFrom :Language .\n", "\n", ":BY_SOME_ID_1543072838_restriction a owl:Restriction,\n", " owl:class ;\n", " rdfs:label \"BY_ex:has_language_FROM_ex:Language_SOME_ex:ru\" ;\n", " owl:onProperty :has_language ;\n", " owl:someValuesFrom :ru .\n", "\n", ":BY_SOME_ID_988527468_restriction a owl:Restriction,\n", " owl:class ;\n", " rdfs:label \"BY_ex:has_language_FROM_ex:Language_SOME_ex:en\" ;\n", " owl:onProperty :has_language ;\n", " owl:someValuesFrom :en .\n", "\n", ":has_language a owl:ObjectProperty .\n", "\n", "\n" ] } ], "source": [ "print(m.taxonomies_by_name[\"hello\"].rdf_graphs_ttl[\"OWL\"])" ] }, { "cell_type": "code", "execution_count": null, "id": "b0dea428-22ff-461c-bd9a-b4566c2e0bd8", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "jupytext": { "formats": "ipynb,md:myst" }, "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.12.4" } }, "nbformat": 4, "nbformat_minor": 5 }