{ "cells": [ { "cell_type": "markdown", "id": "73215f75", "metadata": {}, "source": [ "# SUP (White Horse)\n", "\n", "> A *white horse* (DE: *Schimmel*) is the intersection of a White Color and a Horse.\n", "\n", "Knoten im Focus: `SUP` mit der id `ID_999`." ] }, { "cell_type": "markdown", "id": "6e6ef45c", "metadata": {}, "source": [ "Ausgangspunkt ist eine freemind oder freeplane-Mindmap, die so aussieht:\n", "\n", "![](../../images/white-horse-SUP.png)\n", "\n", "Wir erzeugen diese Mindmap programmatisch, mit kurzen IDs.\n", "\n", "In dem vorliegenden Beispiel interessiert uns vor allem der Knoten `SUP` mit der id `ID_003`." ] }, { "cell_type": "code", "execution_count": 1, "id": "6f68ea51", "metadata": {}, "outputs": [], "source": [ "xml_white_horse_sup = \"\"\"\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\"\"\"" ] }, { "cell_type": "code", "execution_count": 6, "id": "0b06eebb", "metadata": {}, "outputs": [], "source": [ "with open(\"white-horse-SUP.mm\", \"w\") as white_horse_sup:\n", " white_horse_sup.write(xml_white_horse_sup)" ] }, { "cell_type": "code", "execution_count": 3, "id": "d6a551b1", "metadata": {}, "outputs": [], "source": [ "from gd07 import GenDifS" ] }, { "cell_type": "markdown", "id": "53bb4455", "metadata": {}, "source": [ "Mindmap einlesen:" ] }, { "cell_type": "code", "execution_count": 7, "id": "61f04962", "metadata": {}, "outputs": [], "source": [ "m = GenDifS(\"white-horse-SUP.mm\", verb=1)" ] }, { "cell_type": "markdown", "id": "e4bb1128", "metadata": {}, "source": [ "Sichtbar machen, was wir eingelesen haben:" ] }, { "cell_type": "code", "execution_count": 8, "id": "1c5349f4", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "self.mindmap_topnode.get('TEXT')='white-horse-SUP'\n", "len(self.mindmap_xml.getroot().xpath('.//node'))=6 nodes\n" ] } ], "source": [ "m.describe_mindmap()" ] }, { "cell_type": "markdown", "id": "bafa38a7", "metadata": {}, "source": [ "Übersetzen der Mindmap in verschiedene Sprachen:" ] }, { "cell_type": "code", "execution_count": null, "id": "21b93743", "metadata": { "scrolled": true }, "outputs": [], "source": [ "m.compile(language_list_list=['RDFStest', 'OWLtest', 'OWL', 'RDFS']) # alles außer SKOS" ] }, { "cell_type": "markdown", "id": "c48f6f91", "metadata": {}, "source": [ "Welche Taxonomien haben wir unserer Mindmap?" ] }, { "cell_type": "code", "execution_count": null, "id": "e2103025", "metadata": {}, "outputs": [], "source": [ "m.taxonomies_by_name.keys()" ] }, { "cell_type": "markdown", "id": "c0e08868", "metadata": {}, "source": [ "## Taxonomy *white_horse*" ] }, { "cell_type": "markdown", "id": "14e6234d", "metadata": {}, "source": [ "Wir haben in unserer Mindmap nur eine einzige Taxonomie, hier mit dem Namen `white_horse`. Wir weisen diese der gleichnamigen Variablen zu." ] }, { "cell_type": "code", "execution_count": null, "id": "6d82138b", "metadata": {}, "outputs": [], "source": [ "white_horse = m.taxonomies_by_name[\"white_horse\"]" ] }, { "cell_type": "markdown", "id": "e92141fd", "metadata": {}, "source": [ "Uns interessiert der Knoten `ID_999`" ] }, { "cell_type": "code", "execution_count": null, "id": "55cf115e", "metadata": {}, "outputs": [], "source": [ "ID_999 = white_horse.dict_of_all_gdn['ID_999']\n", "type(ID_999)" ] }, { "cell_type": "markdown", "id": "8b27d083", "metadata": {}, "source": [ "Ein Knoten vom Typ `gd07.gdn_differentia` hat ein Dictionary `molecule_dict`, das für jede Sprache den erzeugten ttl-Code als String enthält:" ] }, { "cell_type": "code", "execution_count": null, "id": "aa6d4aa8", "metadata": {}, "outputs": [], "source": [ "for k,v in ID_999.molecule_dict.items():\n", " print(f\"-- {k} --\\n{v}\\n\")" ] }, { "cell_type": "markdown", "id": "3ad919ed", "metadata": {}, "source": [ "Diese Code-Snippets werden erzeugt in der Klasse `ID_999.molecule_per_language`:" ] }, { "cell_type": "code", "execution_count": null, "id": "a1022a79", "metadata": {}, "outputs": [], "source": [ "type(ID_999.molecule_per_language)" ] }, { "cell_type": "markdown", "id": "0801edb5", "metadata": {}, "source": [ "Die Klasse `molecule_per_language` enthält alle Detailinformationen aus der Code-Generierung.\n", "\n", "`entity_context` repräsentiert alle Informationen, die zur Codegenerierung verwendet wurden:" ] }, { "cell_type": "code", "execution_count": null, "id": "dd759497", "metadata": {}, "outputs": [], "source": [ "ID_999.molecule_per_language.entity_context" ] }, { "cell_type": "markdown", "id": "e58e34b4", "metadata": {}, "source": [ "Die Klasse `inspect_inferencing` gibt Zugriff auf die Ergebnisse des Selbsttests, insbesondere `test_results`:" ] }, { "cell_type": "code", "execution_count": null, "id": "f170160f", "metadata": {}, "outputs": [], "source": [ "ID_999.molecule_per_language.inspect_inferencing.test_results" ] }, { "cell_type": "markdown", "id": "bdf27406", "metadata": {}, "source": [ "In dieser Klasse sind 2 Graphen enthalten:\n", "* `g1`: Der aus der Node `ID_999` lokale Graph vor dem Inferencing\n", "* `g2`: Dieser Graph nach dem Inferencing, also nach der vollständigen Ausmaterialisierung durch `owlrl`." ] }, { "cell_type": "markdown", "id": "0f1b2412-b20e-4f43-a4e9-9b808523ca4a", "metadata": {}, "source": [ "`print(g1_ttl)` oder `print(g2_ttl)` würde sehr viel uninteressanten Code zeigen:" ] }, { "cell_type": "code", "execution_count": null, "id": "aa84cd90-50f9-4459-9d54-aca0b8d4aee8", "metadata": {}, "outputs": [], "source": [ "# print(g1_ttl)" ] }, { "cell_type": "code", "execution_count": null, "id": "c460a234-857c-4fcf-908f-333bc2e70abe", "metadata": { "scrolled": true }, "outputs": [], "source": [ "# print(g2_ttl)" ] }, { "cell_type": "markdown", "id": "c0bb3c74", "metadata": {}, "source": [ "Praktischerweise gruppiert die Serialisierungsfnktion von rdflib die Tripel zu sinnvollen Records (Molekülen, im ttl-Text: Absätzen). Wir definieren uns eine kleine Hilfsfunktion `focus()`." ] }, { "cell_type": "code", "execution_count": null, "id": "c70e3e4e", "metadata": {}, "outputs": [], "source": [ "def focus(focus_curie_list, ttl):\n", " return \"\\n\\n\".join( [ paragraph for paragraph in ttl.split(\"\\n\\n\") \\\n", " if any( [ focus_curie in paragraph for focus_curie in focus_curie_list ] ) ] )" ] }, { "cell_type": "markdown", "id": "7efe384e", "metadata": {}, "source": [ "Vor dem Inferencing: Alle Absätze aus `g1`, in denen der String `ID_999` vorkommt:" ] }, { "cell_type": "code", "execution_count": null, "id": "93ad8f31", "metadata": {}, "outputs": [], "source": [ "g1_ttl = ID_999.molecule_per_language.inspect_inferencing.g1.serialize()\n", "print( focus( [\"ID_999\"], g1_ttl) )" ] }, { "cell_type": "markdown", "id": "affc8d53", "metadata": {}, "source": [ "Nach dem Inferencing: Alle Absätze aus `g2`, in denen der String `ID_999` vorkommt:" ] }, { "cell_type": "code", "execution_count": null, "id": "fd1a8e23", "metadata": {}, "outputs": [], "source": [ "g2_ttl = ID_999.molecule_per_language.inspect_inferencing.g2.serialize()\n", "print( focus( [\"ID_999\"], g2_ttl) )" ] }, { "cell_type": "markdown", "id": "47dd5c1b", "metadata": {}, "source": [ "Wir sehen, dass `ex:White_Horse_ID_999` nach dem Inferencing nun eine Instanz (u.A. auch von `ex:SUP_ID_999` und deshalb) auch von `White_Horse` ist." ] }, { "cell_type": "markdown", "id": "98f0a76a", "metadata": {}, "source": [ "QED" ] } ], "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.2" } }, "nbformat": 4, "nbformat_minor": 5 }