Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
c1a0448
Fix KeyError and first Tests for ld_list
Aug 7, 2025
f3133e8
added tests for ld_list
Sep 5, 2025
71a5f87
fixed bug in __getitem__
Sep 5, 2025
23eda6c
added support for slices and fixed bug in __setitem__
Sep 5, 2025
562f3bf
linted ld_list.py and test_ld_list.py
Sep 5, 2025
2679a0a
added more tests
Sep 5, 2025
1da06c3
fixed small bug in __iter__ of ld_list
Sep 5, 2025
8975cf9
added FIXME and linted test_ld_list.py
Sep 5, 2025
e709d6f
added fixme comments and two test cases and removed unused pytest marker
Sep 10, 2025
88fd409
adjusted tests and ld_list as ld_list.itemlist should be expanded jso…
Sep 10, 2025
63de367
added more fixme comments and test cases
Sep 10, 2025
29f0a8a
removed false/ unnecessary fixme
Sep 12, 2025
f38b662
changed type conversions as discussed in #423 and #433 and tweaked th…
Sep 26, 2025
5fde82a
added contains and equals check for ld_list with tests and added issu…
Oct 6, 2025
da136c3
changed ld_list according to issue #439
Oct 17, 2025
03ebd32
implemented tests for problem 2 of the issue and more tests
Oct 20, 2025
d1eb612
added a few missing conversions and formatted the file a little bit d…
Oct 20, 2025
d28dc10
removed one conversion, added one and changed _to_python to fix conve…
Oct 20, 2025
fb5aa64
fixed formatting errors
Oct 20, 2025
5248853
fixed ld_container tests, a type conversion and equals of ld_list
Oct 24, 2025
e2c1bba
added detailed comparison for ld_list, ld_dict and json_values and ad…
Nov 7, 2025
aeb88fb
added support for graph and set again and improved expansion of json-ld
Nov 21, 2025
007e3a3
removed unnecessary lambda
Nov 21, 2025
3c9ea61
fixed set and from_list and added del
Nov 21, 2025
66e03df
updated tests of ld_container and fixed found bugs
Nov 21, 2025
c4aea65
pacified flake8
Nov 21, 2025
7d30b16
improved ld_list.__contains__ and added tests for it
Nov 24, 2025
f8d259f
added one TODO item to ld_list
Nov 24, 2025
2b98627
began adding doc strings, type hints and comments for ld_container
Nov 24, 2025
1958518
improved _to_expanded_json
Nov 28, 2025
4acf8de
added doc-strings and comments and pacified flake8
Nov 28, 2025
b751130
began commenting and adding doc-strings to ld_list
Nov 28, 2025
3c243f2
fixed bug in _to_expanded_json
Dec 5, 2025
e0f0fc9
added a few test cases to delete of ld_list
Dec 5, 2025
1b5656e
added more comments to ld_list
Dec 5, 2025
071630c
added more doc strings
Dec 5, 2025
d4b34b4
corrected type hints
Dec 8, 2025
f0f1818
documented the rest of the methods in ld_container
Dec 8, 2025
bcc233d
implemented list comparison and added tests for it
Dec 12, 2025
287d37a
added tests and fixed small bug and fixed typos
Dec 15, 2025
5f2214e
Merge pull request #445 from softwarepub/refactor/439-restrict-ld_list
SKernchen Dec 19, 2025
14868ad
Merge branch 'refactor/data-model' into refactor/385-test-ld_list
notactuallyfinn Dec 19, 2025
20fbefc
fixed ld_dict tests
Dec 19, 2025
504a345
removed unnecessary fixme
Dec 19, 2025
0999f44
Delete deprecated function
SKernchen Dec 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 41 additions & 46 deletions src/hermes/model/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# SPDX-License-Identifier: Apache-2.0

# SPDX-FileContributor: Michael Meinel
# SPDX-FileContributor: Michael Fritzsche

from datetime import date, time, datetime

Expand All @@ -19,57 +20,51 @@
lambda c: isinstance(c, ld_container),
{
"ld_container": lambda c, **_: c,

"json": lambda c, **_: c.compact(),
"expanded_json": lambda c, **_: c.ld_value,
}
),

# Wrap expanded_json to ld_container
(ld_container.is_ld_id, dict(python=lambda c, **_: c[0]['@id'])),
(ld_container.is_typed_ld_value, dict(python=ld_container.typed_ld_to_py)),
(ld_container.is_ld_value, dict(python=lambda c, **_: c[0]['@value'])),
(ld_list.is_ld_list, dict(ld_container=ld_list)),
(ld_dict.is_ld_dict, dict(ld_container=ld_dict)),

# Expand and access JSON data
(ld_container.is_json_id, dict(python=lambda c, **_: c["@id"], expanded_json=lambda c, **_: [c])),
(ld_container.is_typed_json_value, dict(python=ld_container.typed_ld_to_py)),
(ld_container.is_json_value, dict(python=lambda c, **_: c["@value"], expanded_json=lambda c, **_: [c])),
(ld_list.is_container, dict(ld_container=lambda c, **kw: ld_list([c], **kw))),

# FIXME: add conversion from list and json dict to expanded_json
# to parse nested dicts and lists when using for example __setitem__(key, value) from ld_dict
# where value is converted to expanded_json bevor adding it to data_dict
# Suggested:
# (
# ld_dict.is_json_dict,
# {
# "ld_container": ld_dict.from_dict,
# "expanded_json": lambda c, **kw: kw["parent"]._to_expanded_json(kw["key"], ld_dict.from_dict(c, **kw))
# }
# ),
#
# (
# lambda c: isinstance(c, list),
# {
# "ld_container": ld_list.from_list,
# "expanded_json": lambda c, **kw: kw["parent"]._to_expanded_json(kw["key"], ld_list.from_list(c, **kw))
# }
# ),
(ld_dict.is_json_dict, dict(ld_container=ld_dict.from_dict)),

(lambda c: isinstance(c, list), dict(ld_container=ld_list.from_list)),

# Wrap internal data types
(lambda v: isinstance(v, (int, float, str, bool)), dict(expanded_json=lambda v, **_: [{"@value": v}])),

(lambda v: isinstance(v, datetime),
dict(expanded_json=lambda v, **_: [{"@value": v.isoformat(), "@type": iri_map["schema:DateTime"]}])),
(lambda v: isinstance(v, date),
dict(expanded_json=lambda v, **_: [{"@value": v.isoformat(), "@type": iri_map["schema:Date"]}])),
(lambda v: isinstance(v, time),
dict(expanded_json=lambda v, **_: [{"@value": v.isoformat(), "@type": iri_map["schema:Time"]}])),
# Wrap item from ld_dict in ld_list
(ld_list.is_ld_list, {"ld_container": ld_list}),
(lambda c: isinstance(c, list), {"ld_container": lambda c, **kw: ld_list(c, **kw)}),

# pythonize items from lists (expanded set is already handled above)
(ld_container.is_json_id, {"python": lambda c, **_: c["@id"]}),
(ld_container.is_typed_json_value, {"python": lambda c, **kw: ld_container.typed_ld_to_py([c], **kw)}),
(ld_container.is_json_value, {"python": lambda c, **_: c["@value"]}),
(ld_list.is_container, {"ld_container": lambda c, **kw: ld_list([c], **kw)}),
(ld_dict.is_json_dict, {"ld_container": lambda c, **kw: ld_dict([c], **kw)}),
(lambda v: isinstance(v, str), {"python": lambda v, parent, **_: parent.ld_proc.compact_iri(parent.active_ctx, v)}),

# Convert internal data types to expanded_json
(ld_container.is_json_id, {"expanded_json": lambda c, **_: [c]}),
(ld_container.is_ld_id, {"expanded_json": lambda c, **_: c}),
(ld_container.is_json_value, {"expanded_json": lambda c, **_: [c]}),
(ld_container.is_ld_value, {"expanded_json": lambda c, **_: c}),
(ld_dict.is_json_dict, {"expanded_json": lambda c, **kw: ld_dict.from_dict(c, **kw).ld_value}),
(
ld_list.is_container,
{"expanded_json": lambda c, **kw: ld_list.from_list(ld_list.get_item_list_from_container(c), **kw).ld_value}
),
(
ld_list.is_ld_list,
{"expanded_json": lambda c, **kw: ld_list.from_list(ld_list.get_item_list_from_container(c[0]), **kw).ld_value}
),
(lambda c: isinstance(c, list), {"expanded_json": lambda c, **kw: ld_list.from_list(c, **kw).ld_value}),
(lambda v: isinstance(v, (int, float, str, bool)), {"expanded_json": lambda v, **_: [{"@value": v}]}),
(
lambda v: isinstance(v, datetime),
{"expanded_json": lambda v, **_: [{"@value": v.isoformat(), "@type": iri_map["schema:DateTime"]}]}
),
(
lambda v: isinstance(v, date),
{"expanded_json": lambda v, **_: [{"@value": v.isoformat(), "@type": iri_map["schema:Date"]}]}
),
(
lambda v: isinstance(v, time),
{"expanded_json": lambda v, **_: [{"@value": v.isoformat(), "@type": iri_map["schema:Time"]}]}
),
]


Expand Down
Loading
Loading