Skip to content

Commit e4a2387

Browse files
committed
updating json-ldcontext-semic nested / flat / default
1 parent f3ff466 commit e4a2387

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

packages/linkml/src/linkml/generators/semic/jsonldcontextgen_semic.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ class ContextGenerator(Generator):
3535
generatorversion = "0.1.1"
3636
valid_formats = ["context", "json"]
3737

38-
#
39-
visit_all_class_slots = True
40-
nested_class_context: bool = False
38+
visit_all_class_slots = False
39+
nested_class_context: Optional[bool] = None
4140

4241
uses_schemaloader = True
4342
requires_metamodel = True
@@ -67,6 +66,11 @@ class ContextGenerator(Generator):
6766

6867
def __post_init__(self) -> None:
6968
super().__post_init__()
69+
# None = no flag passed → plain flat output, no class slot visiting
70+
# True = --nested-class-context → hierarchical per-class @context
71+
# False = --flat-class-context → flat Class.property keys
72+
if self.nested_class_context is not None:
73+
self.visit_all_class_slots = True
7074
if self.namespaces is None:
7175
raise TypeError("Schema text must be supplied to context generator. Preparsed schema will not work")
7276

@@ -189,8 +193,8 @@ def visit_class(self, cls: ClassDefinition) -> bool:
189193
if getattr(cls, "tree_root", False):
190194
self.frame_root = cls.name
191195

192-
# We don't bother to visit class slots - just all slots
193-
return True
196+
# Only walk class slots when --nested-class-context or --flat-class-context is passed
197+
return self.nested_class_context is not None
194198

195199
def visit_slot(self, aliased_slot_name: str, slot: SlotDefinition) -> None:
196200
if slot.identifier:
@@ -342,7 +346,7 @@ def serialize(self, base: Optional[Union[str, Namespace]] = None, **kwargs) -> s
342346

343347
@click.option(
344348
"--nested-class-context/--flat-class-context",
345-
default=False,
349+
default=None,
346350
show_default=True,
347351
help="Use nested @context per class vs flat Class.property keys",
348352
)

0 commit comments

Comments
 (0)