I created a linkml model named PersonModel:
id: PersonModel
name: Person Model
prefixes:
- prefix: person
uri: http://example.org/person/
default_prefix: person
types:
- name: Person
description: A person entity
slots:
- name: name
range: string
- name: weight
range: decimal
- name: height
range: decimal
- name: BMI
range: decimal
formula: "weight / (height * height)"
There is now an instance object file as bobInstance.yaml:
id: bob
type: Person
name: Bob
weight: 67
height: 1.7
Is my expression of BMI in PersonModel correct? Now how to use python to validate the compliance of bobInstance and calculate the value of bob.BMI? Someone told me to use BMI = eval(BMI_formula),But I haven't gotten the correct result. How should I write this python file?
Here is a modified version of your schema:
Note the correct slot is equals_expression
I also modified
decimaltofloatfor simplicityAssuming you have converted the above to dataclasses using the Python generator, into a path
datamodel/person.yamlyou can then do the following:You will get:
Note that by default, the inference methods won't use expressions, you need to pass in a config option with
Config(use_expressions=True)See: