Skip to content

Commit

Permalink
Merge pull request #37 from linkml/add-target_definition-to-data-model
Browse files Browse the repository at this point in the history
Adding target_definition to model.
  • Loading branch information
cmungall authored Aug 24, 2024
2 parents 54e761a + 6a9c683 commit 1ed75a2
Show file tree
Hide file tree
Showing 8 changed files with 1,740 additions and 439 deletions.
1,881 changes: 1,485 additions & 396 deletions src/linkml_map/datamodel/transformer_model.py

Large diffs are not rendered by default.

113 changes: 111 additions & 2 deletions src/linkml_map/datamodel/transformer_model.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ description: |-
- translation into another specification language, such as R2RML
prefixes:
linkml: https://w3id.org/linkml/
linkmltr: https://w3id.org/linkml/transformer/
linkmlmap: https://w3id.org/linkml/transformer/
dcterms: http://purl.org/dc/terms/
schema: http://schema.org/
rdfs: http://www.w3.org/2000/01/rdf-schema#
sh: http://www.w3.org/ns/shacl#
default_prefix: linkmltr
STATO: http://purl.obolibrary.org/obo/STATO_
default_prefix: linkmlmap

imports:
- linkml:types
Expand Down Expand Up @@ -178,6 +179,12 @@ classes:
range: SlotDerivation
multivalued: true
inlined: true
target_definition:
range: Any
description: >-
LinkML class definition object for this slot.
comments:
- currently defined as Any to avoid coupling with metamodel

AliasedClass:
description: alias-class key value pairs for classes
Expand Down Expand Up @@ -228,12 +235,20 @@ classes:
description: True if this is suppressed
type_designator:
range: boolean
target_definition:
range: Any
description: >-
LinkML definition object for this slot.
comments:
- currently defined as Any to avoid coupling with metamodel
cast_collection_as:
range: CollectionType
dictionary_key:
range: string
stringification:
range: StringificationConfiguration
aggregation_operation:
range: AggregationOperation

EnumDerivation:
is_a: ElementDerivation
Expand Down Expand Up @@ -330,6 +345,57 @@ classes:
slot_name:
class_name:

TransformationOperation:
abstract: true

AggregationOperation:
is_a: TransformationOperation
attributes:
operator:
range: AggregationType
required: true
null_handling:
range: InvalidValueHandlingStrategy
invalid_value_handling:
range: InvalidValueHandlingStrategy

GroupingOperation:
is_a: TransformationOperation
attributes:
null_handling:
range: InvalidValueHandlingStrategy

PivotOperation:
aliases:
- melt/unmelt
- reification/dereification
is_a: TransformationOperation
attributes:
direction:
range: PivotDirectionType
required: true
variable_slot:
aliases:
- var_name
range: SlotReference
ifabsent: string(variable)
description: Slot to use for the variable column in the melted/long representation.
In EAV this is the name of the 'A' variable
value_slot:
aliases:
- value_name
range: SlotReference
ifabsent: string(value)
description: Slot to use for the value column in the melted/long representation.
In EAV this is the name of the 'V' variable
unmelt_to_class:
description: In an unmelt operation, attributes (which are values in the long/melted/EAV
representation) must conform to valid attributes in this class
range: ClassReference
unmelt_to_slots:
range: SlotReference
multivalued: true

KeyVal:
attributes:
key:
Expand Down Expand Up @@ -394,3 +460,46 @@ enums:
JSON:
YAML:
TURTLE:
AggregationType:
permissible_values:
SUM:
AVERAGE:
aliases:
- mean
- avg
exact_mappings:
- STATO:0000230
COUNT:
exact_mappings:
- STATO:0000047
MIN:
MAX:
STD_DEV:
exact_mappings:
- STATO:0000237
VARIANCE:
MEDIAN:
exact_mappings:
- STATO:0000674
MODE:
exact_mappings:
- STATO:0000033
CUSTOM:
SET:
LIST:
ARRAY:
InvalidValueHandlingStrategy:
permissible_values:
IGNORE:
TREAT_AS_ZERO:
ERROR_OUT:
PivotDirectionType:
permissible_values:
MELT:
aliases:
- unpivot
- wide to long
UNMELT:
aliases:
- pivot
- long to wide
18 changes: 18 additions & 0 deletions src/linkml_map/inference/schema_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@ def _derive_class(self, class_derivation: ClassDerivation) -> ClassDefinition:
for slot_derivation in class_derivation.slot_derivations.values():
slot_definition = self._derive_slot(slot_derivation)
target_class.attributes[slot_definition.name] = slot_definition
if class_derivation.is_a:
target_class.is_a = class_derivation.is_a
if class_derivation.mixins:
target_class.mixins = class_derivation.mixins
if class_derivation.target_definition:
spec_defn = ClassDefinition(
**{"name": target_class.name}, **class_derivation.target_definition
)
for k, v in vars(spec_defn).items():
curr_v = getattr(target_class, k, None)
if curr_v is None or curr_v == [] or curr_v == {}:
setattr(target_class, k, v)
self.source_to_target_class_mappings[populated_from].append(target_class.name)
if class_derivation.overrides:
curr = json_dumper.to_dict(target_class)
Expand Down Expand Up @@ -178,6 +190,12 @@ def _derive_slot(self, slot_derivation) -> SlotDefinition:
target_slot.name = slot_derivation.name
if slot_derivation.range:
target_slot.range = slot_derivation.range
if slot_derivation.target_definition:
spec_defn = SlotDefinition(
**{"name": target_slot.name}, **slot_derivation.target_definition
)
for k, v in vars(spec_defn).items():
setattr(target_slot, k, v)
if slot_derivation.unit_conversion:
target_slot.unit = UnitOfMeasure(ucum_code=slot_derivation.unit_conversion.target_unit)
if slot_derivation.stringification:
Expand Down
4 changes: 1 addition & 3 deletions tests/input/examples/flattening/model/denormalized_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
)
from linkml_runtime.utils.metamodelcore import empty_list
from linkml_runtime.utils.slot import Slot
from linkml_runtime.utils.yamlutils import (
YAMLRoot,
)
from linkml_runtime.utils.yamlutils import YAMLRoot
from rdflib import URIRef

metamodel_version = "1.7.0"
Expand Down
5 changes: 1 addition & 4 deletions tests/input/examples/flattening/model/normalized_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
)
from linkml_runtime.utils.metamodelcore import empty_dict, empty_list
from linkml_runtime.utils.slot import Slot
from linkml_runtime.utils.yamlutils import (
YAMLRoot,
extended_str,
)
from linkml_runtime.utils.yamlutils import YAMLRoot, extended_str
from rdflib import URIRef

metamodel_version = "1.7.0"
Expand Down
17 changes: 3 additions & 14 deletions tests/input/examples/personinfo_basic/model/agent_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,15 @@
from typing import Any, ClassVar, Dict, List, Optional, Union

from jsonasobj2 import as_dict
from linkml_runtime.linkml_model.meta import (
EnumDefinition,
PermissibleValue,
)
from linkml_runtime.linkml_model.meta import EnumDefinition, PermissibleValue
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.metamodelcore import (
Bool,
XSDDate,
empty_dict,
empty_list,
)
from linkml_runtime.utils.metamodelcore import Bool, XSDDate, empty_dict, empty_list
from linkml_runtime.utils.slot import Slot
from linkml_runtime.utils.yamlutils import (
YAMLRoot,
extended_str,
)
from linkml_runtime.utils.yamlutils import YAMLRoot, extended_str
from rdflib import URIRef

metamodel_version = "1.7.0"
Expand Down
17 changes: 3 additions & 14 deletions tests/input/examples/personinfo_basic/model/personinfo_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,15 @@
from typing import Any, ClassVar, Dict, List, Optional, Union

from jsonasobj2 import as_dict
from linkml_runtime.linkml_model.meta import (
EnumDefinition,
PermissibleValue,
)
from linkml_runtime.linkml_model.meta import EnumDefinition, PermissibleValue
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.metamodelcore import (
Bool,
XSDDate,
empty_dict,
empty_list,
)
from linkml_runtime.utils.metamodelcore import Bool, XSDDate, empty_dict, empty_list
from linkml_runtime.utils.slot import Slot
from linkml_runtime.utils.yamlutils import (
YAMLRoot,
extended_str,
)
from linkml_runtime.utils.yamlutils import YAMLRoot, extended_str
from rdflib import URIRef

metamodel_version = "1.7.0"
Expand Down
Loading

0 comments on commit 1ed75a2

Please sign in to comment.