Repository navigation
Ld_list issues #439
Copy link
Copy link
Closed
Labels
data modelRelated to the hermes data modelRelated to the hermes data modelhelp wantedExtra attention is neededExtra attention is needed
Description
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 andis_ld_listfromld_listassume it otherwise (is_containerofld_listhas the same flaws) and the conversion from a ld_list withcontainer = "@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"]}])andis_ld_list([{"@set": [{"@value": "a"}, {"@value": "b}]}])returnTruebutis_ld_list([{"@value": "a"}, {"@value": "b}])returnsFalseld_list([{"@set": [{"@value": "a"}, {"@value": "b}]}])returns the correct object butld_list([{"@set": ["a", "b"]}])creates a non expanded ld_list andld_list([{"@value": "a"}, {"@value": "b}])raises aValueErrorld_list.from_list(["a", "b"], container="@set", key="https://schema.org/name", context={"schema": "https://schema.org/"}).ld_valueis[{"@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 forld_dict. - JSON-LD supports nested containers. But the type of those makes a difference which is not considered in
__setitem__andappendofld_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 itemlistand the container type areis 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
Labels
data modelRelated to the hermes data modelRelated to the hermes data modelhelp wantedExtra attention is neededExtra attention is needed
Activity
ld_dict#384ld_dict#384ld_list#385notactuallyfinn commentedon Oct 17, 2025
We discussed today that
ld_listshould no longer be explicitly representing"@set"and"@graph". Instead its content should be treated as if it was an"@list"(ordered list).Explicitly representing
"@set"is not necessary because the only difference to"@list"is that"@set"is explicitly unorded and treating it as if it was ordered changes nothing.Explicitly representing
"@graph"does not seem necessary because our default graph only contains one item and is represented by aSoftwareMetadataobject and we do not see a need for any other graph in our context.This also solves the first and third problem mentioned in this issue.
changed ld_list according to issue #439
notactuallyfinn commentedon Oct 20, 2025
As for the second problem, I would say that we should treat it like a list.
We probably always return a list anyway (decision not finalized yet) when we get an object from an ld_dict. Therefore, it makes no difference how we insert the object in question into an ld_dict.
If you insert/append the object to a list, I think it's more likely to be a list (e.g. if the iteration yielded only one element) than an expanded dict (because for the user it's easier to create a non-expanded dict).
led02 commentedon Nov 7, 2025
Voice from the off...
First, I want to emphasize that the
ld_containerclass hierarchy is was initially meant as a helper to better cope with expanded JSON-LD. The idea behind the data model is, that we have valid expanded JSON-LD and these classes are a small utility to help handling them. The guts of HERMES processing should not rely on these classes to follow the JSON-LD specs.However, small helper classes grow and get almighty and now I would really see a high potential of refactoring them out into some general purpose untility library. Until then, we should look at them with more pragmatic eyes:
self.dataattribute is always a refernce to the actual data set...Having clearified that, her are my 2ct regarding the actual contents of this ticket:
@setneeds to ensure that there are no duplicates, hence the items need to be comparable (i.e., having and@id). But the@graphcan be treated as an unordered list. I aggre, there is a confusion between the class name and the JSON-LD terms here. Yet, I'd propose to rename the Python class instead of introducing additional fuzz by adding other classes that add no semantics. (I would also stay away from adding semantics here before these classes are its own project... KISS)I.e., given the expanded JSON-LD
[{"foo": [{"@list": [{"@set": [{"a": "b"}]}]}]as ld_lista, thena["foo"]is a ld_list with a.["foo"].data being[{"@list": [{"@set": [{"a": "b"}]}]}]. Accessing a["foo"][0] again returns a ld_list which is created just when the access operation is done.PS: I'll leave my comments in the MR, too ;)
notactuallyfinn commentedon Nov 10, 2025
{"@context": "http://schema.org/", "@type": "Person", "name": [{"@set": [{"@id": "A"}, {"@id": "A"}]}]}is expanded to[{"@type": ["http://schema.org/Person"], "http://schema.org/name": [{"@id": "A"}, {"@id": "A"}]}](proof). This means@setdoes not require it contents to be unique, i.e. it can contain duplicates. The reason for removing@setand@graphand always replacing it with@listwasn't the name of the classld_list. (And it wasn't planned to add other classes likeld_set.)@setand the dict and only storing the actual value: I think that is a must because otherwise it is not valid JSON-LD. Anyhow it is neccessary to convert from that state to our python versions asld_dict.from_dictuses the JSON-LD-Processor to expand the given dict that may contain any valid JSON-LD like a non-expanded set.[{"http://schema.org/foo": [{"@list": [{"@list": {"http://schema.org/a": [{"@value": "b"}]}]}]}]}]instead (proof). But anyhow you are right.Merge pull request #445 from softwarepub/refactor/439-restrict-ld_list