Skip to content

Ld_list issues #439

@notactuallyfinn

Description

@notactuallyfinn

While testing ld_list in #418 we found some potential issues:

  • Sets and graphs are not dictionaries with "@set" or "@graph" as keys for their list of items in their expanded JSON-LD form. But the constructor of and is_ld_list from ld_list assume it otherwise (is_container of ld_list has the same flaws) and the conversion from a ld_list with container = "@set" to expanded json gives the wrong form:
    • {"https://schema.org/name": {"@set": ["a", "b"]}}'s expanded version is [{"https://schema.org/name": [{"@value": "a"}, {"@value": "b}]}].
    • is_ld_list([{"@set": ["a", "b"]}]) and is_ld_list([{"@set": [{"@value": "a"}, {"@value": "b}]}]) return True but is_ld_list([{"@value": "a"}, {"@value": "b}]) returns False
    • ld_list([{"@set": [{"@value": "a"}, {"@value": "b}]}]) returns the correct object but ld_list([{"@set": ["a", "b"]}]) creates a non expanded ld_list and ld_list([{"@value": "a"}, {"@value": "b}]) raises a ValueError
    • ld_list.from_list(["a", "b"], container="@set", key="https://schema.org/name", context={"schema": "https://schema.org/"}).ld_value is [{"@set": [{"@value": "a"}, {"@value": "b}]}] instead of [{"@value": "a"}, {"@value": "b}]}]
  • Should a list containing a single value (a dictionary) be considered an expanded set/ graph or just as a expanded JSON-LD dict if it isn't a value or id? This is relevant for e.g. setting or appending such an object (for example [{"schema:name": "foo"}]) but also for ld_dict.
  • JSON-LD supports nested containers. But the type of those makes a difference which is not considered in __setitem__ and append of ld_list. For example:
    • A set inside a set gets unpacked but a set inside a list gets turned into a list when expanded.
    • [{"https://schema.org/name": [{"@set": [{"@value": "a"}, {"@set": ["b", "c"]}, {"@list": ["d", "e"]}]}]}]'s expanded from is [{"https://schema.org/name": [{"@value": "a"}, {"@value": "b"}, {"@value": "c"}, {"@list": [{"@value": "d"}, {"@value": "e"}]}]}]
    • [{"https://schema.org/name": [{"@list": [{"@value": "a"}, {"@set": ["b", "c"]}, {"@list": ["d", "e"]}]}]}]'s expanded from is [{"https://schema.org/name": [{"@list": [{"@value": "a"}, {"@list": [{"@value": "b"}, {"@value": "c"}]}, {"@list": [{ "@value": "d"}, {"@value": "e"}]}]}]}].
  • Should parent, key, index and context be also compared when comparing two ld_lists with == through __eq__ or with != through __ne__? At the moment only the itemlist and the container type are is compared. And should the order be ignored for ld_lists with container type "@set"?
  • __init__ documents a parameter that does not exist.

Metadata

Metadata

Assignees

No one assigned

    Labels

    data modelRelated to the hermes data modelhelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions