Skip to content

Commit c2b9c4f

Browse files
author
Michael Fritzsche
committed
cleaned up __init__.py
1 parent 6f039e8 commit c2b9c4f

File tree

3 files changed

+9
-69
lines changed

3 files changed

+9
-69
lines changed

src/hermes/model/types/__init__.py

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,19 @@
55
# SPDX-FileContributor: Michael Meinel
66
# SPDX-FileContributor: Michael Fritzsche
77

8-
from datetime import date, time, datetime
9-
108
from .ld_container import ld_container
11-
from .ld_list import ld_list
129
from .ld_dict import ld_dict
13-
from .ld_context import iri_map
10+
from .ld_list import ld_list
1411
from .pyld_util import JsonLdProcessor
1512

1613

1714
_TYPEMAP = [
18-
# Conversion routines for ld_container
19-
(
20-
lambda c: isinstance(c, ld_container),
21-
{
22-
"ld_container": lambda c, **_: c,
23-
"json": lambda c, **_: c.compact(),
24-
"expanded_json": lambda c, **_: c.ld_value,
25-
},
26-
),
15+
# Conversion routine for ld_container
16+
(lambda c: isinstance(c, ld_container), {"ld_container": lambda c, **_: c}),
2717

2818
# Wrap item from ld_dict in ld_list
2919
(ld_list.is_ld_list, {"ld_container": ld_list}),
30-
(lambda c: isinstance(c, list), {"ld_container": lambda c, **kw: ld_list(c, **kw)}),
20+
(lambda c: isinstance(c, list), {"ld_container": ld_list}),
3121

3222
# pythonize items from lists (expanded set is already handled above)
3323
(ld_container.is_json_id, {"python": lambda c, **_: c["@id"]}),
@@ -36,35 +26,6 @@
3626
(ld_list.is_container, {"ld_container": lambda c, **kw: ld_list([c], **kw)}),
3727
(ld_dict.is_json_dict, {"ld_container": lambda c, **kw: ld_dict([c], **kw)}),
3828
(lambda v: isinstance(v, str), {"python": lambda v, parent, **_: parent.ld_proc.compact_iri(parent.active_ctx, v)}),
39-
40-
# Convert internal data types to expanded_json
41-
(ld_container.is_json_id, {"expanded_json": lambda c, **_: [c]}),
42-
(ld_container.is_ld_id, {"expanded_json": lambda c, **_: c}),
43-
(ld_container.is_json_value, {"expanded_json": lambda c, **_: [c]}),
44-
(ld_container.is_ld_value, {"expanded_json": lambda c, **_: c}),
45-
(ld_dict.is_json_dict, {"expanded_json": lambda c, **kw: ld_dict.from_dict(c, **kw).ld_value}),
46-
(
47-
ld_list.is_container,
48-
{"expanded_json": lambda c, **kw: ld_list.from_list(ld_list.get_item_list_from_container(c), **kw).ld_value}
49-
),
50-
(
51-
ld_list.is_ld_list,
52-
{"expanded_json": lambda c, **kw: ld_list.from_list(ld_list.get_item_list_from_container(c[0]), **kw).ld_value}
53-
),
54-
(lambda c: isinstance(c, list), {"expanded_json": lambda c, **kw: ld_list.from_list(c, **kw).ld_value}),
55-
(lambda v: isinstance(v, (int, float, str, bool)), {"expanded_json": lambda v, **_: [{"@value": v}]}),
56-
(
57-
lambda v: isinstance(v, datetime),
58-
{"expanded_json": lambda v, **_: [{"@value": v.isoformat(), "@type": iri_map["schema:DateTime"]}]}
59-
),
60-
(
61-
lambda v: isinstance(v, date),
62-
{"expanded_json": lambda v, **_: [{"@value": v.isoformat(), "@type": iri_map["schema:Date"]}]}
63-
),
64-
(
65-
lambda v: isinstance(v, time),
66-
{"expanded_json": lambda v, **_: [{"@value": v.isoformat(), "@type": iri_map["schema:Time"]}]}
67-
),
6829
]
6930

7031

src/hermes/model/types/ld_dict.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,7 @@ def __eq__(self, other):
6565
if unique_keys and unique_keys != {"@id"}:
6666
return False
6767
for key in keys_self.intersection(keys_other):
68-
item = self[key]
69-
other_item = other[key]
70-
res = item.__eq__(other_item)
71-
if res == NotImplemented:
72-
res = other_item.__eq__(item)
73-
if res is False or res == NotImplemented: # res is not True
68+
if self[key] != other[key]:
7469
return False
7570
return True
7671

src/hermes/model/types/ld_list.py

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -312,16 +312,8 @@ def __eq__(
312312
if item["@id"] != other_item["@id"]:
313313
return False
314314
continue
315-
# get the 'real' items (i.e. can also be ld_dicts or ld_lists)
316-
item = self[index]
317-
other_item = other[index]
318-
# compare using the correct equals method
319-
res = item.__eq__(other_item)
320-
if res == NotImplemented:
321-
# swap order if first try returned NotImplemented
322-
res = other_item.__eq__(item)
323-
# return false if the second comparison also fails or one of them returned false
324-
if res is False or res == NotImplemented:
315+
# compare the 'real' items (i.e. can also be ld_dicts or ld_lists)
316+
if self[index] != other[index]:
325317
return False
326318
# return true because no unequal elements where found
327319
return True
@@ -341,16 +333,8 @@ def __eq__(
341333
if item["@id"] == other_item["@id"]:
342334
equality_pairs[index] += [other_index]
343335
continue
344-
# get the 'real' items (i.e. can also be ld_dicts or ld_lists)
345-
item = self[index]
346-
other_item = other[index]
347-
# compare using the correct equals method
348-
res = item.__eq__(other_item)
349-
if res == NotImplemented:
350-
# swap order if first try returned NotImplemented
351-
res = other_item.__eq__(item)
352-
# if one of both comparisons returned true the elements are equal
353-
if res is not NotImplemented and res:
336+
# compare the 'real' items (i.e. can also be ld_dicts or ld_lists)
337+
if self[index] == other[other_index]:
354338
equality_pairs[index] += [other_index]
355339
if len(equality_pairs[index]) == 0:
356340
# there exists no element in other that is equal to item

0 commit comments

Comments
 (0)