Skip to content

Commit

Permalink
Merge pull request #1 from ialarmedalien/test_transformer_examples_tidy
Browse files Browse the repository at this point in the history
Flesh out transformation tests
  • Loading branch information
cmungall authored Apr 23, 2023
2 parents 46dfd87 + 610a90a commit 3c101eb
Show file tree
Hide file tree
Showing 10 changed files with 222 additions and 117 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
id: P:2
height:
value: 1.72
unit: m
13 changes: 12 additions & 1 deletion tests/input/examples/personinfo_basic/data/Container-001.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ persons:
has_familial_relationships:
- type: SIBLING_OF
related_to: P:002
- type: CHILD_OF
related_to: P:003
current_address:
street: 1 oak street
aliases:
Expand All @@ -23,10 +25,19 @@ persons:
has_familial_relationships:
- type: SIBLING_OF
related_to: P:001
- type: CHILD_OF
related_to: P:003
has_medical_history:
- diagnosis:
id: C:001
name: c1 (renamed)
- id: P:003
name: Mr. Blobby
has_familial_relationships:
- type: PARENT_OF
related_to: P:001
- type: PARENT_OF
related_to: P:002
organizations:
- id: ROR:1
name: Acme
name: Acme
4 changes: 3 additions & 1 deletion tests/input/examples/personinfo_basic/data/Person-001.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ gender: nonbinary man
has_familial_relationships:
- type: SIBLING_OF
related_to: P:002
- type: CHILD_OF
related_to: P:003
current_address:
street: 1 oak street
city: oaktown
city: oaktown
71 changes: 41 additions & 30 deletions tests/input/examples/personinfo_basic/model/agent_model.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,40 @@
# Auto generated from personinfo_s2.yaml by pythongen.py version: 0.9.0
# Generation date: 2023-02-04T18:11:52
# Auto generated from agent.yaml by pythongen.py version: 0.9.0
# Generation date: 2023-04-14T14:30:22
# Schema: personinfo
#
# id: https://w3id.org/linkml/examples/personinfo
# description: Information about people, based on [schema.org](http://schema.org)
# license: https://creativecommons.org/publicdomain/zero/1.0/

import dataclasses
import re
import sys
import re
from jsonasobj2 import JsonObj, as_dict
from typing import Optional, List, Union, Dict, ClassVar, Any
from dataclasses import dataclass
from typing import Any, ClassVar, Dict, List, Optional, Union
from linkml_runtime.linkml_model.meta import (
EnumDefinition,
PermissibleValue,
PvFormulaOptions,
)

from jsonasobj2 import JsonObj, as_dict
from linkml_runtime.linkml_model.meta import (EnumDefinition, PermissibleValue,
PvFormulaOptions)
from linkml_runtime.linkml_model.types import Boolean, Date, Float, String
from linkml_runtime.utils.curienamespace import CurieNamespace
from linkml_runtime.utils.dataclass_extensions_376 import \
dataclasses_init_fn_with_kwargs
from linkml_runtime.utils.enumerations import EnumDefinitionImpl
from linkml_runtime.utils.formatutils import camelcase, sfx, underscore
from linkml_runtime.utils.metamodelcore import (Bool, XSDDate, bnode,
empty_dict, empty_list)
from linkml_runtime.utils.slot import Slot
from linkml_runtime.utils.yamlutils import (YAMLRoot, extended_float,
extended_int, extended_str)
from linkml_runtime.utils.metamodelcore import empty_list, empty_dict, bnode
from linkml_runtime.utils.yamlutils import (
YAMLRoot,
extended_str,
extended_float,
extended_int,
)
from linkml_runtime.utils.dataclass_extensions_376 import (
dataclasses_init_fn_with_kwargs,
)
from linkml_runtime.utils.formatutils import camelcase, underscore, sfx
from linkml_runtime.utils.enumerations import EnumDefinitionImpl
from rdflib import Namespace, URIRef
from linkml_runtime.utils.curienamespace import CurieNamespace
from linkml_runtime.linkml_model.types import Boolean, Date, Float, String
from linkml_runtime.utils.metamodelcore import Bool, XSDDate

metamodel_version = "1.7.0"
version = None
Expand Down Expand Up @@ -153,6 +161,7 @@ class Agent(NamedThing):
has_medical_history: Optional[
Union[Union[dict, "MedicalEvent"], List[Union[dict, "MedicalEvent"]]]
] = empty_list()
parents: Optional[Union[str, List[str]]] = empty_list()
aliases: Optional[Union[str, List[str]]] = empty_list()

def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]):
Expand Down Expand Up @@ -213,6 +222,10 @@ def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]):
for v in self.has_medical_history
]

if not isinstance(self.parents, list):
self.parents = [self.parents] if self.parents is not None else []
self.parents = [v if isinstance(v, str) else str(v) for v in self.parents]

if not isinstance(self.aliases, list):
self.aliases = [self.aliases] if self.aliases is not None else []
self.aliases = [v if isinstance(v, str) else str(v) for v in self.aliases]
Expand Down Expand Up @@ -603,6 +616,7 @@ def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]):
# Enumerations
class FamilialRelationshipType(EnumDefinitionImpl):
SIBLING_OF = PermissibleValue(text="SIBLING_OF", meaning=FAMREL["01"])
CHILD_OF = PermissibleValue(text="CHILD_OF", meaning=FAMREL["05"])

_defn = EnumDefinition(
name="FamilialRelationshipType",
Expand All @@ -613,9 +627,6 @@ def _addvals(cls):
setattr(
cls, "parent of", PermissibleValue(text="parent of", meaning=FAMREL["02"])
)
setattr(
cls, "child of", PermissibleValue(text="child of", meaning=FAMREL["01"])
)


class GenderType(EnumDefinitionImpl):
Expand Down Expand Up @@ -782,6 +793,15 @@ class slots:
],
)

slots.parents = Slot(
uri=PERSONINFO.parents,
name="parents",
curie=PERSONINFO.curie("parents"),
model_uri=PERSONINFO.parents,
domain=None,
range=Optional[Union[str, List[str]]],
)

slots.in_location = Slot(
uri=PERSONINFO.in_location,
name="in_location",
Expand Down Expand Up @@ -970,15 +990,6 @@ class slots:
range=Optional[Union[str, List[str]]],
)

slots.related_to = Slot(
uri=PERSONINFO.related_to,
name="related to",
curie=PERSONINFO.curie("related_to"),
model_uri=PERSONINFO.related_to,
domain=None,
range=Union[str, AgentId],
)

slots.Agent_primary_email = Slot(
uri=SCHEMA.email,
name="Agent_primary_email",
Expand All @@ -1000,7 +1011,7 @@ class slots:

slots.FamilialRelationship_related_to = Slot(
uri=PERSONINFO.related_to,
name="FamilialRelationship_related to",
name="FamilialRelationship_related_to",
curie=PERSONINFO.curie("related_to"),
model_uri=PERSONINFO.FamilialRelationship_related_to,
domain=FamilialRelationship,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ class RelationshipType(EnumDefinitionImpl):
class FamilialRelationshipType(EnumDefinitionImpl):
SIBLING_OF = PermissibleValue(text="SIBLING_OF", meaning=FAMREL["01"])
PARENT_OF = PermissibleValue(text="PARENT_OF", meaning=FAMREL["02"])
CHILD_OF = PermissibleValue(text="CHILD_OF", meaning=FAMREL["01"])
CHILD_OF = PermissibleValue(text="CHILD_OF", meaning=FAMREL["05"])
FATHER_OF = PermissibleValue(text="FATHER_OF", meaning=FAMREL["11"])

_defn = EnumDefinition(
Expand Down
3 changes: 1 addition & 2 deletions tests/input/examples/personinfo_basic/source/personinfo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ classes:
ProcedureConcept:
is_a: Concept


Relationship:
slots:
- started_at_time
Expand Down Expand Up @@ -254,7 +253,7 @@ enums:
PARENT_OF:
meaning: famrel:02
CHILD_OF:
meaning: famrel:01
meaning: famrel:05
FATHER_OF:
meaning: famrel:11
GenderType:
Expand Down
12 changes: 8 additions & 4 deletions tests/input/examples/personinfo_basic/target/agent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ classes:
- has_employment_history
- has_familial_relationships
- has_medical_history
- parents
slot_usage:
primary_email:
pattern: "^\\S+@[\\S+\\.]+\\S+"
Expand Down Expand Up @@ -120,7 +121,6 @@ classes:
ProcedureConcept:
is_a: Concept


Relationship:
slots:
- started_at_time
Expand All @@ -134,7 +134,7 @@ classes:
type:
range: FamilialRelationshipType
required: true
related to:
related_to:
range: Agent
required: true

Expand Down Expand Up @@ -195,6 +195,10 @@ slots:
range: FamilialRelationship
multivalued: true
inlined_as_list: true
parents:
range: string
multivalued: true
inlined_as_list: true
in_location:
range: Place
current_address:
Expand Down Expand Up @@ -250,8 +254,8 @@ enums:
meaning: famrel:01
parent of:
meaning: famrel:02
child of:
meaning: famrel:01
CHILD_OF:
meaning: famrel:05
GenderType:
permissible_values:
nonbinary man:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class_derivations:
is_a: Entity
populated_from: Person
slot_derivations:

## implicitly same name in Agent
id:

Expand All @@ -42,21 +41,22 @@ class_derivations:
## unit conversion
#age_in_years:
# expr: "units.convert(age.value, age.unit, units.YEARS)"

## nested to flat
#friends:
# expr: "[x.id for x in {friends}]"

## copy recursively, flat to nested
#jobs:
# populated_from: jobs

## copy recursively
#diagnoses:
# populated_from: diagnoses

has_familial_relationships:
populated_from: has_familial_relationships

Job:
#primitive: uriorcurie
slot_derivations:
Expand Down Expand Up @@ -94,7 +94,7 @@ class_derivations:
type_designator: true
hide: true
populated_from: feature_type

DenormMapping:
populated_from: Mapping
#joins:
Expand Down Expand Up @@ -123,4 +123,6 @@ enum_derivations:
populated_from: FamilialRelationshipType
permissible_value_derivations:
sibling of:
populated_from: SIBLING_OF
populated_from: SIBLING_OF
CHILD_OF:
populated_from: CHILD_OF
Loading

0 comments on commit 3c101eb

Please sign in to comment.