Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use grounded names when renaming in stratification #252

Merged
merged 35 commits into from
Nov 3, 2023
Merged

Conversation

kkaris
Copy link
Contributor

@kkaris kkaris commented Oct 30, 2023

This PR allows the automatically generated stratification names to be more human friendly by passing through a mapping from calling the stratify function down to where the renaming happens: in the the concept.with_context method.

Tests are added for both the stratify module and for the model api.

When calling the stratify endpoint, a user can provide the name mapping or if no mapping is provided a lazy attempt to map from curies to entity names is done. If the curie mapping also fails, the behavior prior to this PR is expected.

Example

from mira.metamodel.ops import stratify
from mira.examples.sir import sir_parameterized
cities = [
    "geonames:5128581",  # NYC
    "geonames:4930956",  # boston
]
stratified_model = stratify(sir_parameterized, key="city", strata=cities, cartesian_control=False, directed=False)
print(stratified_model.templates[0].controller)
# > name='infected_population_geonames_4930956' display_name=None description=None identifiers={'ido': '0000511'} context={'city': 'geonames:4930956'} units=None

@kkaris kkaris requested review from bgyori and cthoyt October 30, 2023 20:33
[str(v.replace(':', '_')) for _, v in sorted(context.items())])
name_list = [self._base_name]
for k, v in sorted(context.items()):
nv = name_map.get(v, v) if name_map else v
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should add a is_curie function somewhere that can be used in here to make this code more obvious what it's doing

@bgyori bgyori force-pushed the stratify-grounding branch from c71fc4a to 8635d3a Compare November 3, 2023 16:13
Copy link
Member

@bgyori bgyori left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@bgyori bgyori merged commit c3208a7 into main Nov 3, 2023
@bgyori bgyori deleted the stratify-grounding branch November 3, 2023 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants