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

Slot usage of attributes in abstract class #2042

Open
mszulcz-mitre opened this issue Apr 1, 2024 · 2 comments
Open

Slot usage of attributes in abstract class #2042

mszulcz-mitre opened this issue Apr 1, 2024 · 2 comments
Labels
bug Something that should work but isn't, with an example and a test case. community-generated

Comments

@mszulcz-mitre
Copy link

I have an abstract class (Abstract) in which an attribute (custom) has the type of a custom class (Custom). In a child class of the abstract class (Implementation), I want to define the type of an attribute (attr3) in the custom class. However, I get an error when I try to validate. Here's the code (InheritanceTest.yaml):

id: https://example.org/InheritanceTest
name: InheritanceTest 
description: |-
  A test for how inheritance works in LinkML.
prefixes:
  linkml: https://w3id.org/linkml/
imports:
  - linkml:types
default_range: string

classes:
  
  Custom:
    abstract: true
    attributes:
      attr3:

  Abstract:
    abstract: true
    attributes:
      attr1:
      attr2:
      custom:
        range: Custom

  CustomImpl:
    is_a: Custom
    slot_usage:
      attr3: float

  Implementation:
    tree_root: true
    is_a: Abstract
    slot_usage:
      attr1:
        range: integer 
      custom:
          range: CustomImpl

Here's the instance I try to validate (InheritanceInstance.yaml):

attr1: 1
attr2: world
custom:
  attr3: 3.14

I validate with linkml-validate -s InheritanceTest.yaml InheritanceInstance.yaml. I get the error [ERROR] [InheritanceInstance.yaml/0] 3.14 is not of type 'string' in /custom/att3. Is what I'm trying to do possible in LinkML?

A related question. Is there a way to identify objects with prefixes in their names? For example, the file above imports linkml:types. Can I identify the types using a C++-like notation such as linkml::integer. Here's my use case: I'd like to be able to use the same class name in 2 different schema files and import 1 to use in the other. To distinguish them, it'd be useful to attach a prefix or a namespace to the imported class.

@mszulcz-mitre mszulcz-mitre added the bug Something that should work but isn't, with an example and a test case. label Apr 1, 2024
@sneakers-the-rat
Copy link
Collaborator

looks like just a syntax problem:

this:

  CustomImpl:
    is_a: Custom
    slot_usage:
      attr3: float

should be

  CustomImpl:
    is_a: Custom
    slot_usage:
      attr3: 
        range: float

That validates correctly with the above data, and other generated models seem to be right too.

You'll also see a warning that says slot_usage for undefined slot: attr3

Another way you could write the schema is like this:

id: https://example.org/InheritanceTest
name: InheritanceTest 
description: |-
  A test for how inheritance works in LinkML.
prefixes:
  linkml: https://w3id.org/linkml/
imports:
  - linkml:types
default_range: string

classes:
  
  Custom:
    abstract: true
    slots:
    - attr3

  Abstract:
    abstract: true
    slots:
    - attr1
    - attr2
    - custom

  CustomImpl:
    is_a: Custom
    slot_usage:
      attr3: 
        range: float

  Implementation:
    tree_root: true
    is_a: Abstract
    slot_usage:
      attr1:
        range: integer 
      custom:
        range: CustomImpl

slots:
  attr1:
  attr2:
  attr3:
  custom:
    range: Custom

which validates without warning :)

@sneakers-the-rat
Copy link
Collaborator

re: namespaced imports, it's an ongoing conversation! https://github.com/orgs/linkml/discussions/1739

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that should work but isn't, with an example and a test case. community-generated
Projects
None yet
Development

No branches or pull requests

3 participants