Skip to content

Improve the user friendliness of the SoftwareMetadata object #423

@notactuallyfinn

Description

@notactuallyfinn

In issue #376 the SoftwareMetadata class (subclass of ld_dict) is introduced.
It is supposed to provide an abstracted API for data access by clients for example when harvesting.
Data is added by accessing the SoftwareMetadata object like a dictionary for example:

from hermes.model import SoftwareMetadata
data = SoftwareMetadata()
data["schema:field"] = "foo"

This is fine for single strings. When writing a harvest plugin one might not consider that this can lead to problems:

from hermes.model import SoftwareMetadata
data = SoftwareMetadata()
data["schema:field"] = "foo"
# something else might get done here
data["schema:field"] = "bar"

In this case "schema:field" only contains "bar" by accident instead of ["foo", "bar"].
I therefor suggest adding an "add" method to the SoftwareMetadata or ld_dict class as SoftwareMetadata is a subclass of ld_dict. It should work like this:

from hermes.model import SoftwareMetadata
data = SoftwareMetadata()
data.add(key="schema:field", value="foo")
data.add(key="schema:field", value="bar")
data.add(key="schema:field", value="foobar")
# equivalent to data["schema:field"] = ["foo", "bar", "foobar"]

Not yet specified is how lists or dicts should be added. I suggest that this should be done like this for user convenience:

from hermes.model import SoftwareMetadata
from hermes.model.types.ld_list import ld_list
from hermes.model.types.ld_dict import ld_dict
data = SoftwareMetadata()
data["schema:field"] = ["foo", "bar", "foobar"]
# instead of data["schema:field"] = ld_list.from_list(["foo", "bar", "foobar"])
data["schema:other_field"] = {"@type": "schema:Person", "name": "ABC"}
# instead of data["schema:other_field"] = ld_dict.from_dict({"@type": "schema:Person", "name": "ABC"})

Metadata

Metadata

Assignees

No one assigned

    Labels

    data modelRelated to the hermes data model

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions