biolink / biolinkml

DEPRECATED: replaced by linkml
https://github.com/linkml/linkml
Creative Commons Zero v1.0 Universal
23 stars 12 forks source link

biolinkml optional slots populated in object #296

Closed wdduncan closed 3 years ago

wdduncan commented 3 years ago

When I create an object according to the specifications in the yaml file, the optional slots (i.e., required: false) still show up as part of the object.

For example, in the nmdc schema, the class named thing is specified like so:

named thing:
    description: "a databased entity or concept/class"
    abstract: true
    slots:
      - id
      - name
      - description
      - alternate identifiers

The alternative identifiers slots is specified like this:

alternate identifiers:
    aliases: ['mappings', 'alt ids', 'xrefs']
    description: >-
      Non-primary identifiers
    multivalued: true
    range: string
    required: false

Suppose, I create an instance of named thing using this code:

In [3]: import nmdc
In [5]: n1 = nmdc.NamedThing(id='id:1',  name='object 1', description='test for named thing')
In [6]: n1
Out[6]: NamedThing(id='id:1', name='object 1', description='test for named thing', alternate_identifiers=[])

When I view the object, the alternative identifiers slot still shows up:

alternate_identifiers=[]

Do we want this slot to still be included in the instantiated object? I'm having to filter out the empty alternative identifier list when converting to a dict. E.g.:

In [4]: import jsonasobj
In [8]: jsonasobj.as_dict(n1)
Out[8]: 
{'id': 'id:1',
 'name': 'object 1',
 'description': 'test for named thing',
 'alternate_identifiers': []}
hsolbrig commented 3 years ago

See response to #297

hsolbrig commented 3 years ago

OK to close?

wdduncan commented 3 years ago

Yes :) You may want to update the documentation though ...