linkML's slot concept will allow to share slot names between classes as IMHO is typical for the ontological approach to modeling. In most of my SiDIF based models i am using object oriented approaches where there are separate properties/attributes/slots per class. Therefore there needs to be a fully qualifying name for each slot that is globaly unique and locally unique per class
In my first attempt to assign slots to classes i didn't use fully qualifying names and ended up with the error message:
ValueError: No such slot {'name': 'name', 'description': 'Name of the context'} as an attribute of Context ancestors or as a slot definition in the schema
which does not explain how to solve the problem. I am assuming a fully qualified slot name would solve this problem.
What would solve the problem? If my assumption fully qualifying slot name solve the problem - what are allowed / recommended ways to assign fully qualified names - how are namespaces syntactically separated or is there no such official linkML way ot doing this.
Should i e.g. specify context.name or context::name or the like?
my current code is:
'''
Created on 2023-02-20
@author: wf
'''
from meta.metamodel import Context
from linkml_runtime.utils.schemaview import SchemaView
from linkml_runtime.linkml_model import SchemaDefinition, ClassDefinition, SlotDefinition
from linkml.generators.linkmlgen import LinkmlGenerator
class SiDIF2LinkML:
"""
converter between SiDIF and LINKML
"""
def __init__(self,context:Context):
self.context=context
def asYaml(self)->str:
"""
convert my context
"""
# https://linkml.io/linkml-model/docs/SchemaDefinition/
sd=SchemaDefinition(id=self.context.name,name=self.context.name)
sv=SchemaView(sd)
for topic in self.context.topics.values():
cd=ClassDefinition(name=topic.name)
cd.description=topic.documentation
sv.add_class(cd)
for prop in topic.properties.values():
slot=SlotDefinition(name=prop.name)
if hasattr(prop,"documentation"):
slot.description=prop.documentation
sv.add_slot(slot)
cd.slots.append(slot)
pass
pass
lml_gen=LinkmlGenerator(schema=sd,format='yaml')
yaml_text=lml_gen.serialize()
return yaml_text
see also How do i add a class to a SchemaDefinition in LinkML?
Currently my workaround is to combine the descriptions and try to use the slots in the "ontological way" which means each slot might have different meanings in different classes /contexts and the qualified name problem would be consider a "followup-issue"
Tried with the Family Context of the Royal Family Example Wiki
see e.g.
LinkML yaml
ER Diagram
Which would be automatically rendered in github see https://github.com/WolfgangFahl/pyMetaModel/issues/15