Skip to content

Resolve ambiguity on how to handle attributes - #259

Open
Silvanoc wants to merge 2 commits into
mainfrom
resolve-attribute-ambiguity
Open

Resolve ambiguity on how to handle attributes#259
Silvanoc wants to merge 2 commits into
mainfrom
resolve-attribute-ambiguity

Conversation

@Silvanoc

Copy link
Copy Markdown

This patch fixes the attributes specification for more clarity on how to handle attributes converting to other formats.

Before this patch the attributes specification had a comment that gave the impression that attributes are only syntactic sugar for class-scoped slots (slots that are only available to be used by a class and its descendants) and specifying the conversion of attributes into slots renaming them to <class-name>__<attribute-name>.

This patch modifies that comment so that attributes are kept as 1st-class-citizens even on conversions.

Fixes: linkml/linkml#3669

This patch fixes the `attributes` specification for more clarity on how
to handle `attributes` converting to other formats.

Before this patch the `attributes` specification had a comment that gave
the impression that `attributes` are only syntactic sugar for
class-scoped slots (slots that are only available to be used by a class
and its descendants) and specifying the conversion of `attributes` into
`slots` renaming them to `<class-name>__<attribute-name>`.

This patch modifies that comment so that `attributes` are kept as
1st-class-citizens even on conversions.

Signed-off-by: Silvano Cirujano Cuesta <silvano.cirujano-cuesta@siemens.com>
gouttegd
gouttegd previously approved these changes Sep 4, 2026

@gouttegd gouttegd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am (obviously) not an authority on the meta-model, but FWIW, I agree with this.

The <class_name>__<slot_name> bit is nothing but an implementation detail. This is how some parts of LinkML-Py deal with attributes, but this is not required and there are other ways to deal with them.

Comment thread linkml_model/model/schema/meta.yaml Outdated
comments:
- >-
attributes are an alternative way of defining new slots. An attribute adds a slot to the global space in the
form <class_name>__<slot_name> (lower case, double underscores). Attributes can be specialized via slot_usage.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it necessary to remove this phrase "Attributes can be specialized via slot_usage."? Seems correct to me..

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Isn’t that implied by the fact that attributes are “equivalent to slots” – since slots can be specialised via slot_usage?

Though on second thought, at least one generator falsely believes that slot_usage should not be used to refine attributes (linkml/linkml#3438), so maybe keeping that explicit statement would in fact be helpful…

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I don't remember if I removed it for a specific reason or it was just an erroneous "delete until end of line". I'll double check.

@Silvanoc Silvanoc Sep 4, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Perhaps a rewording like

Attributes are slots and such can be also modified via slot_usage.

might be helpful here. Assuming that it's true, what I still have to double check.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Assuming that it's true, what I still have to double check.

But the question is, where do you check that? AFAIK, the only place in the meta-model where anything is said about slot_usage applying to attributes is here. The definition of slot_usage only says that it is “the refinement of a slot in the context of the containing class definition” – which may be interpreted as being applicable to attributes given that an attribute is nothing more than a type of slot, but who knows?

The “reference implementation” (LinkML-Py) is not helpful here since its different components cannot agree with each other. SchemaView is of the position that slot_usage does apply to attributes. But the Python generator (which is not based on SchemaView) disagrees.

range: slot_definition
inlined: true
description: Inline definition of slots
description: Inline definition of class-scoped slots

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does it make sense to change that here as well?

| [attributes](../attributes.md) | 0..* <br/> [SlotDefinition](../SlotDefinition.md) | Inline definition of slots |

Comment thread linkml_model/model/schema/meta.yaml Outdated
attributes are an alternative way of defining new slots. An attribute adds a slot to the global space in the
form <class_name>__<slot_name> (lower case, double underscores). Attributes can be specialized via slot_usage.
Attributes are an alternative way of defining class-specific slots.
They are equivalent to slots that are only available within the scope of class and its descendants.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What would you expect child_via_attr to come out as here?

slots:
  parent_slot: {abstract: true, required: true, pattern: "^x.*", multivalued: true}
  child_via_slot: {is_a: parent_slot}
classes:
  ViaSlots:
    slots: [child_via_slot]
  ViaAttrs:
    attributes:
      child_via_attr: {is_a: parent_slot}

Same parent, same is_a. child_via_slot comes out required, patterned and multivalued; child_via_attr comes out with none of them — and per the spec that's correct, not a bug. Still "equivalent"?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I would expect child_via_slot and child_via_attr to have exactly the same attributes.

I don't know if this comes from the descendants part. If that's the case, it refers to the class declaring the attribute and its subclasses. It has nothing to do with a slot's is_a relationship.

@matentzn
matentzn requested review from matentzn and removed request for amc-corey-cox September 4, 2026 13:30
Co-authored-by: Nico Matentzoglu <nicolas.matentzoglu@gmail.com>
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.

gen-jsonld - class attribute gets duplicated into attribute and class-specific-slot

3 participants