Skip to content

Commit

Permalink
is_a vs mixins
Browse files Browse the repository at this point in the history
  • Loading branch information
turbomam committed Sep 9, 2024
1 parent 038bd4e commit b657701
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ classes:
is_a: Checklist
mixin: true
slots:
- conflicting
- adapters
- alt
- annot
Expand Down Expand Up @@ -127,6 +128,8 @@ classes:
- tax_class
- temp
slot_usage:
conflicting:
pattern: ^[a-zA-Z]+$
adapters:
recommended: true
alt:
Expand Down Expand Up @@ -193,6 +196,7 @@ classes:
title: soil
is_a: Extension
slots:
- conflicting
- agrochem_addition
- al_sat
- al_sat_meth
Expand Down Expand Up @@ -251,6 +255,8 @@ classes:
- water_cont_soil_meth
- water_content
slot_usage:
conflicting:
pattern: ^[0-9]+$
crop_rotation:
string_serialization: '{boolean};{Rn/start_time/end_time/duration}'
depth:
Expand Down Expand Up @@ -306,6 +312,9 @@ slots:
inlined: true
inlined_as_list: true

conflicting:
description: intentionally set to incompatible states between a Checklist and an Extension

adapters:
annotations:
Expected_value: adapter A and B sequence
Expand Down
8 changes: 8 additions & 0 deletions src/scripts/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from pathlib import Path

# from ..mixs_missing_value_sandbox import *

THIS_PATH = Path(__file__).parent

SCHEMA_DIRECTORY = THIS_PATH.parent / "mixs_missing_value_sandbox" / "schema"
MAIN_SCHEMA_PATH = SCHEMA_DIRECTORY / "mixs_missing_value_sandbox.yaml"
50 changes: 50 additions & 0 deletions src/scripts/mims_and_soil_slots.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import pprint
from pathlib import Path

from linkml_runtime import SchemaView
from linkml_runtime.dumpers import yaml_dumper

# from ..mixs_missing_value_sandbox import *

THIS_PATH = Path(__file__).parent

SCHEMA_DIRECTORY = THIS_PATH.parent / "mixs_missing_value_sandbox" / "schema"
MAIN_SCHEMA_PATH = SCHEMA_DIRECTORY / "mixs_missing_value_sandbox.yaml"

schema_view = SchemaView(MAIN_SCHEMA_PATH)

current_checklist = "Mims"
current_extension = "Soil"

checklist_slots = schema_view.get_class(current_checklist).slots

extension_slots = schema_view.get_class(current_extension).slots

checklist_extension_slots = set(checklist_slots).intersection(set(extension_slots))
checklist_extension_slots = list(checklist_extension_slots)
checklist_extension_slots.sort()

checklist_usages = schema_view.get_class(current_checklist).slot_usage
extension_usages = schema_view.get_class(current_extension).slot_usage
for slot in checklist_extension_slots:
global_definition = schema_view.get_slot(slot)
checklist_modifies = slot in checklist_usages
extension_modifies = slot in extension_usages
if checklist_modifies or extension_modifies:
if checklist_modifies:
print(f"{slot} slot's usage in {current_checklist}:")
print(yaml_dumper.dumps(checklist_usages[slot]))
else:
print(f"{current_checklist} uses the global definition for {slot}")
# print(yaml_dumper.dumps(global_definition))
if extension_modifies:
print(f"{slot} slot's usage in {current_extension}:")
print(yaml_dumper.dumps(extension_usages[slot]))
else:
print(f"{current_extension} uses the global definition for {slot}")
# print(yaml_dumper.dumps(global_definition))
print(f"Induced slot {slot} in {current_checklist}{current_extension}\n")
print(yaml_dumper.dumps(schema_view.induced_slot(slot, f"{current_checklist}{current_extension}")))
else:
print(f"{slot} not modified by {current_checklist} or {current_extension}\n")
print("----")

0 comments on commit b657701

Please sign in to comment.