Skip to content

Commit

Permalink
Merge pull request #29 from linkml/expr-opt-b
Browse files Browse the repository at this point in the history
Only calculate bindings (ctxt_obj and ctxt_dict) once for expr slots
  • Loading branch information
cmungall authored May 3, 2024
2 parents f01127a + 24f6870 commit bd6cea2
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/linkml_map/transformer/object_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,28 +112,30 @@ def map_object(
return source_obj
class_deriv = self._get_class_derivation(source_type)
tgt_attrs = {}
ctxt_obj = ctxt_dict = None
# map each slot assignment in source_obj, if there is a slot_derivation
for slot_derivation in class_deriv.slot_derivations.values():
v = None
source_class_slot = None
if slot_derivation.unit_conversion:
v = self._perform_unit_conversion(slot_derivation, source_obj, sv, source_type)
elif slot_derivation.expr:
if self.object_index:
if not source_obj_typed:
source_obj_dyn = dynamic_object(source_obj, sv, source_type)
if ctxt_obj is None:
if self.object_index:
if not source_obj_typed:
source_obj_dyn = dynamic_object(source_obj, sv, source_type)
else:
source_obj_dyn = source_obj_typed
ctxt_obj = self.object_index.bless(source_obj_dyn)
ctxt_dict = {
k: getattr(ctxt_obj, k)
for k in ctxt_obj._attributes()
if not k.startswith("_")
}
else:
source_obj_dyn = source_obj_typed
ctxt_obj = self.object_index.bless(source_obj_dyn)
ctxt_dict = {
k: getattr(ctxt_obj, k)
for k in ctxt_obj._attributes()
if not k.startswith("_")
}
else:
do = dynamic_object(source_obj, sv, source_type)
ctxt_obj = do
ctxt_dict = vars(do)
do = dynamic_object(source_obj, sv, source_type)
ctxt_obj = do
ctxt_dict = vars(do)

try:
v = eval_expr(slot_derivation.expr, **ctxt_dict, NULL=None)
Expand Down

0 comments on commit bd6cea2

Please sign in to comment.