gd07 Overview#
Docu for Users#
from gd07 import GenDifS
load mindmap file:
m = GenDifS("../mm/gd07-overview.mm", verb=2)
We can now have a look at the XML file.
m.describe_mindmap()
self.mindmap_topnode.get('TEXT')='test'
len(self.mindmap_xml.getroot().xpath('.//node'))=70 nodes
We now compile the mindmap:
m.compile()
Into which languages did we compile the mindmap by default?
m.languages
{'DE', 'OWL', 'OWLtest', 'RDFS', 'RDFStest', 'SKOS'}
By default we generate one RDF Graph per taxonomy and language. However, we can tell the compiler to collect several languages into one single graph. In the following examples we assume that we want to have a SKOS graph and a graph comprising RDFS and RDFS test instances.
m.compile(language_list_list= ['SKOS', ['RDFS', 'RDFStest'], 'DE' ])
On single mindmap may contain several taxonomies. List them by ID:
m.taxonomies_by_ID
{'ID_1063896536': <gd07.GenDifS_taxonomy at 0x7d084dfebec0>,
'ID_169383865': <gd07.GenDifS_taxonomy at 0x7d084c0bd220>,
'ID_1362702576': <gd07.GenDifS_taxonomy at 0x7d0846b6bb60>,
'ID_1860444087': <gd07.GenDifS_taxonomy at 0x7d08475e09b0>,
'ID_43103660': <gd07.GenDifS_taxonomy at 0x7d0846b9a810>,
'ID_159324499': <gd07.GenDifS_taxonomy at 0x7d0846b9bef0>}
List them by name:
m.taxonomies_by_name
{'test_ISA': <gd07.GenDifS_taxonomy at 0x7d084dfebec0>,
'test_SUP': <gd07.GenDifS_taxonomy at 0x7d084c0bd220>,
'test_SOME': <gd07.GenDifS_taxonomy at 0x7d0846b6bb60>,
'test_BY': <gd07.GenDifS_taxonomy at 0x7d08475e09b0>,
'test_BY_SOME': <gd07.GenDifS_taxonomy at 0x7d0846b9a810>,
'test_natural_language_de': <gd07.GenDifS_taxonomy at 0x7d0846b9bef0>}
Describe the taxonomies from a bird’s eye view:
#m.describe_taxonomies()
You may access a taxonomy either by ID or by name.
m.taxonomies_by_name["test_ISA"].describe()
ID_1063896536 TAXONOMY test_ISA: #5 GenDifS nodes;
self.languages={'RDFStest', 'SKOS', 'RDFS'};
self.rdf_graphs.keys()=dict_keys(['SKOS', 'RDFS_RDFStest', 'DE'])
The language sets of a taxonomy:
m.taxonomies_by_name["test_ISA"].rdf_graphs.keys()
dict_keys(['SKOS', 'RDFS_RDFStest', 'DE'])
Each taxonomy has for each language set an own graph:
m.taxonomies_by_name["test_ISA"].rdf_graphs
{'SKOS': <Graph identifier=N8c073a08007f4d1584a22bde5947c288 (<class 'rdflib.graph.Graph'>)>,
'RDFS_RDFStest': <Graph identifier=N86b99522e33745918eb9def1348cd3bd (<class 'rdflib.graph.Graph'>)>,
'DE': <Graph identifier=Nc991902041ce4f7c99d9eea9a2c7030c (<class 'rdflib.graph.Graph'>)>}
Access e.g. the SKOS graph of taxonomy test_ISA
:
print(m.taxonomies_by_name["test_ISA"].rdf_graphs_ttl["SKOS"])
@prefix cpt: <http://example.net/namespace/cpt#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
cpt:Mare a skos:Concept ;
skos:broader cpt:Horse .
cpt:Stallion a skos:Concept ;
skos:broader cpt:Horse .
cpt:test_ISA a skos:ConceptScheme .
cpt:Horse a skos:Concept ;
skos:inScheme cpt:test_ISA .
[] owl:imports <http://www.w3.org/TR/skos-reference/skos-owl1-dl.rdf> .
Access the graph comprising the RDFS and RDFS test instances as generated by GenDifS / TBD: rather generated by RDFlib?
print(m.taxonomies_by_name["test_ISA"].rdf_graphs_ttl["RDFS_RDFStest"])
@prefix : <http://example.net/namespace/default#> .
@prefix ex: <http://example.net/namespace/ex#> .
@prefix gendifs: <http://jbusse.de/gendifs#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
ex:Horse_ID_256160314 a :Horse .
ex:Mare_ID_1847046641 a :Mare ;
gendifs:classify_similar ex:Horse_ID_1847046641 .
ex:Mare_ID_889051662 a :Mare .
ex:Stallion_ID_1083557091 a :Stallion .
ex:Stallion_ID_1847046641 a :Stallion ;
gendifs:classify_similar ex:Horse_ID_1847046641 .
:Mare a owl:Class ;
rdfs:subClassOf :Horse .
:Stallion a owl:Class ;
rdfs:subClassOf :Horse .
ex:Horse_ID_1847046641 a :Horse .
:Horse a owl:Class .
Access the same graph as generated by rdflib:
# print(m.taxonomies_by_name["test_ISA"].rdf_graphs["RDFS_RDFStest"].serialize())
Normal Language Explanations#
We have added a natural language description to the individual class descriptions (experimental, for the time being only for DE), see explanation-demo.
Technical Stuff#
Dictionaries
m.taxonomies_by_name
is a dictionary of taxonomies:
m_one = m.taxonomies_by_name["test_ISA"]
type(m_one)
gd07.GenDifS_taxonomy
Each single taxonomy can be accessed via a dict of GenDifsNodes, short: gdn
:
m_one.dict_of_all_gdn
{'ID_1063896536': <gd07.gdn_differentia at 0x7d084dfbe1e0>,
'ID_256160314': <gd07.gdn_taxon at 0x7d0846b6a690>,
'ID_1847046641': <gd07.gdn_differentia at 0x7d0846b6b320>,
'ID_889051662': <gd07.gdn_taxon at 0x7d0846b6b440>,
'ID_1083557091': <gd07.gdn_taxon at 0x7d0846b6b410>}
gdn have a (more or less pretty) __str__
method:
for id, gdn_node in m_one.dict_of_all_gdn.items():
print(gdn_node)
ID_1063896536 (gdn_differentia) TAXONOMY test_ISA
{'SKOS': '# ID_1063896536 SKOS\n[ owl:imports <http://www.w3.org/TR/skos-reference/skos-owl1-dl.rdf> ] .\ncpt:test_ISA a skos:ConceptScheme .\ncpt:Horse a skos:Concept ;\n skos:inScheme cpt:test_ISA .'}
ID_256160314 (gdn_taxon) Horse
{'RDFS': '# ID_256160314 RDFS\n:Horse a owl:Class . ', 'RDFStest': '# ID_256160314 RDFStest\nex:Horse_ID_256160314 a :Horse . '}
ID_1847046641 (gdn_differentia) ISA
{'RDFS': '# ID_1847046641 RDFS\n:Horse a owl:Class .\n:Mare a owl:Class;\n rdfs:subClassOf :Horse .\n:Stallion a owl:Class;\n rdfs:subClassOf :Horse .', 'RDFStest': '# ID_1847046641 RDFStest\nex:Horse_ID_1847046641 a :Horse .\nex:Mare_ID_1847046641 a :Mare .\nex:Stallion_ID_1847046641 a :Stallion .\nex:Mare_ID_1847046641 gendifs:classify_similar ex:Horse_ID_1847046641 .\nex:Stallion_ID_1847046641 gendifs:classify_similar ex:Horse_ID_1847046641 .', 'SKOS': '# ID_1847046641 SKOS\ncpt:Horse a skos:Concept .\ncpt:Mare a skos:Concept ;\n skos:broader cpt:Horse .\ncpt:Stallion a skos:Concept ;\n skos:broader cpt:Horse .'}
ID_889051662 (gdn_taxon) Mare
{'RDFS': '# ID_889051662 RDFS\n:Mare a owl:Class . ', 'RDFStest': '# ID_889051662 RDFStest\nex:Mare_ID_889051662 a :Mare . '}
ID_1083557091 (gdn_taxon) Stallion
{'RDFS': '# ID_1083557091 RDFS\n:Stallion a owl:Class . ', 'RDFStest': '# ID_1083557091 RDFStest\nex:Stallion_ID_1083557091 a :Stallion . '}
Describe all GenDifS nodes of m_one
with the describe()
method:
for node in m_one.dict_of_all_gdn.values():
node.describe()
differentia TAXONOMY: {'TAXONOMY': 'test_ISA'}
self.context={'id': 'ID_1063896536', 'codeclass': 'TAXONOMY', 'taxonomy_name': 'test_ISA', 'graph': 'graph_ID_1063896536', 'species_list': ['Horse']}
self.molecule_per_language=<gd07.GenDifS_molecule_per_language object at 0x7d0846b6b2f0>
--------------------
Horse
self.context={'id': 'ID_256160314', 'codeclass': 'taxon', 'species': 'Horse'}
====================
differentia ISA: {'ISA': ''}
self.context={'id': 'ID_1847046641', 'codeclass': 'ISA', 'genus': 'Horse', 'species_list': ['Mare', 'Stallion']}
self.molecule_per_language=<gd07.GenDifS_molecule_per_language object at 0x7d0846b6b800>
--------------------
Mare
self.context={'id': 'ID_889051662', 'codeclass': 'taxon', 'species': 'Mare'}
====================
Stallion
self.context={'id': 'ID_1083557091', 'codeclass': 'taxon', 'species': 'Stallion'}
====================
Retrieve all ids (there might be more than one) of all nodes with a specific species, say Horse
:
TBD provide methods (a) for taxon nodes, (b) for differentia nodes
Pferd_id_set = { node.context['id'] for node in m_one.dict_of_all_gdn.values() if node.context.get("species") == "Horse" }
Pferd_id_set
{'ID_256160314'}
As expected we only got one id.
Link Pferd_gdn
to the identified gdn:
Pferd_id = Pferd_id_set.pop()
Pferd_gdn = m_one.dict_of_all_gdn[Pferd_id]
Inspect the dict context
of this gdn. The context comprises all information which is relevant for code generation
Lets have a look at a differentia node
Pferd_gdn.context
{'id': 'ID_256160314', 'codeclass': 'taxon', 'species': 'Horse'}
isa_gdn = m_one.dict_of_all_gdn["ID_1847046641"]
isa_gdn.context
{'id': 'ID_1847046641',
'codeclass': 'ISA',
'genus': 'Horse',
'species_list': ['Mare', 'Stallion']}
The code of a gdn is maintained in the class molecule_per_language
:
type(isa_gdn.molecule_per_language)
gd07.GenDifS_molecule_per_language
isa_gdn.molecule_per_language.compile()
generates a ttl molecule for each language. The generated code is kept in sa_gdn.molecule_dict
:
isa_gdn.molecule_dict.keys()
dict_keys(['RDFS', 'RDFStest', 'SKOS'])
get SKOS:
print(isa_gdn.molecule_dict["SKOS"])
# ID_1847046641 SKOS
cpt:Horse a skos:Concept .
cpt:Mare a skos:Concept ;
skos:broader cpt:Horse .
cpt:Stallion a skos:Concept ;
skos:broader cpt:Horse .
get RDFS:
print(isa_gdn.molecule_dict["RDFS"])
# ID_1847046641 RDFS
:Horse a owl:Class .
:Mare a owl:Class;
rdfs:subClassOf :Horse .
:Stallion a owl:Class;
rdfs:subClassOf :Horse .
RDFSTest provides example instances plus a gendifs:classify_similar
property:
print(isa_gdn.molecule_dict["RDFStest"])
# ID_1847046641 RDFStest
ex:Horse_ID_1847046641 a :Horse .
ex:Mare_ID_1847046641 a :Mare .
ex:Stallion_ID_1847046641 a :Stallion .
ex:Mare_ID_1847046641 gendifs:classify_similar ex:Horse_ID_1847046641 .
ex:Stallion_ID_1847046641 gendifs:classify_similar ex:Horse_ID_1847046641 .