Hello World#

Install GenDifS: Until further notice, there is no installation via pip. Installation by hand is simple:

  • Download the module gd06.py into any directory, e.g. the directory ../py/.

  • Include this directory in the Python import path.

import sys
from gd06 import GenDifS_Map

We recommend to create mindmaps in a separate directory, e.g. ../mm/.

mindmap = "hello_world" # filename without .mm extension
o = GenDifS_Map(f"../mm/{mindmap}.mm", verbose = 1)
__init__: GenDifS 0.63 (2023-08-01, 2023-09-08)

If you plan to write back the current mindmap it might be wise to create a backup?

backup_mindmap = True

import time
if backup_mindmap:
    mindmap_backup_filename = f"../mm/{mindmap}_backup_{time.strftime('%Y-%m-%dT%H-%M-%S')}" 
    o.mindmap.write(mindmap_backup_filename, pretty_print=True)
    print(f"wrote  backup to {mindmap_backup_filename}")
wrote  backup to ../mm/hello_world_backup_2024-06-20T11-54-39

Compile the mindmap into a ttl representation:#

lexer: Lexer: found #1 start nodes: ['TAXONOMY skos_milk_example']
codegen: codegen: generated 4 entries in `ttl_records`
get_code: Collected 35 code lines, pattern: ['ALL' 'owl-test' 'skos' 'docu' 'owl' 'owl-classify']
rdflib_parse: rdflib: 80 triples.
# The compiled code is put into a pandas data frame
# o.code_df.head(6)

o.compile() generates all necessary class attributes, but does not perform inferencing. To get all instances which can be inferred use o.owlrl():

owlrl: owlrl: 396 triples.


Feel free to query the graph with SPARQL. Some useful default namespaces are contained in the attribute o.sparql_namespaces.

Q = o.sparql_namespaces + """
SELECT ?sub ?super
WHERE { ?sub skos:broader ?super }

qres = o.rdflib_graph.query(Q)

for row in qres:
(rdflib.term.URIRef('http://example.net/namespace/cpt#milk'), rdflib.term.URIRef('http://example.net/namespace/cpt#topConcept'))
(rdflib.term.URIRef('http://example.net/namespace/cpt#milk_of_a_cow'), rdflib.term.URIRef('http://example.net/namespace/cpt#milk'))
(rdflib.term.URIRef('http://example.net/namespace/cpt#goat_milk'), rdflib.term.URIRef('http://example.net/namespace/cpt#milk'))

Save the ontologies#

We recommend saving the generated taxonomy in Turtle format in a separate directory, e.g. ../ttl/.

This is what the ttl code looks like, generated directly by GenDifS:

with open(f"../ttl/{mindmap}_mm.ttl", "w") as file:

Export of all triples through rdflib, without inferencing:


Export of all triples through rdflib, after inferencing:


Save back the mindmap#

update_mindmap = True

if update_mindmap:
    update_mindmap_filename = f"../mm/{mindmap}.mm"
    print(f"updated mindmap {update_mindmap_filename}")
updated mindmap ../mm/hello_world.mm