Skip to content

Commit

Permalink
Change implementation to be based on matching
Browse files Browse the repository at this point in the history
  • Loading branch information
bgyori committed Sep 20, 2024
1 parent 3593f4b commit d24064d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
16 changes: 12 additions & 4 deletions mira/metamodel/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,12 +768,20 @@ def add_observable_pattern(
:
A template model with the observable added.
"""
if refinement_func is None:
refinement_func = get_dkg_refinement_closure().is_ontological_child
observable_concepts = []
identifiers = set(concept_pattern.identifiers.items())
contexts = set(concept_pattern.context.items())
name_only = (not identifiers) and (not contexts)
for key, concept in template_model.get_concepts_map().items():
if concept.refinement_of(concept_pattern, refinement_func):
observable_concepts.append(concept)
if name_only:
if concept.name == concept_pattern.name:
observable_concepts.append(concept)
else:
if (not identifiers) or identifiers.issubset(
set(concept.identifiers.items())):
if (not contexts) or contexts.issubset(
set(concept.context.items())):
observable_concepts.append(concept)
obs = get_observable_for_concepts(observable_concepts, name)
template_model.observables[name] = obs
return template_model
Expand Down
5 changes: 5 additions & 0 deletions tests/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,3 +611,8 @@ def test_add_observable_pattern():
assert 'obs' in tm.observables
obs = tm.observables['obs']
assert obs.expression.args[0] == sympy.Symbol('A_old') + sympy.Symbol('A_young')

add_observable_pattern(tm, Concept(name='young', context={'age': 'young'}), 'obs2')
assert 'obs2' in tm.observables
obs = tm.observables['obs2']
assert obs.expression.args[0] == sympy.Symbol('A_young') + sympy.Symbol('B_young')

0 comments on commit d24064d

Please sign in to comment.