Skip to content

Commit 45459fc

Browse files
author
notactuallyfinn
committed
improved comments for ld_dict
1 parent 4f3372c commit 45459fc

4 files changed

Lines changed: 167 additions & 194 deletions

File tree

src/hermes/model/types/ld_container.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@
4747

4848
class ld_container:
4949
"""
50-
Base class for Linked Data containers.
51-
50+
Base class for Linked Data containers.\n
5251
A linked data container impelements a view on the expanded form of an JSON-LD document.
5352
It allows to easily interacts them by hinding all the nesting and automatically mapping
5453
between different forms.
@@ -178,15 +177,13 @@ def _to_expanded_json(
178177
self: Self, value: JSON_LD_VALUE
179178
) -> Union[EXPANDED_JSON_LD_VALUE, dict[str, EXPANDED_JSON_LD_VALUE]]:
180179
"""
181-
Returns an expanded version of the given value.
182-
180+
Returns an expanded version of the given value.\n
183181
The item_list/ data_dict of self will be substituted with value.
184182
Value can be an ld_container or contain zero or more.
185183
Then the _data of the inner most ld_dict that contains or is self will be expanded
186184
using the JSON_LD-Processor.
187185
If self and none of self's parents is an ld_dict, use the key from outer most ld_list
188-
to generate a minimal dict.
189-
186+
to generate a minimal dict.\n
190187
The result of this function is what value has turned into.
191188
192189
Args:
@@ -199,7 +196,7 @@ def _to_expanded_json(
199196
value will be expanded as if it was the data_dict/ the item_list of self.
200197
201198
Returns:
202-
EXPANDED_JSON_LD_VALUE | dict[str, EXPANDED_JSON_LD_VALUE]:
199+
EXPANDED_JSON_LD_VALUE | dict[str, EXPANDED_JSON_LD_VALUE]:
203200
The expanded version of value i.e. the data_dict/ item_list of self if it had been value.
204201
The return type is based on the type of self:
205202
@@ -349,7 +346,7 @@ def merge_to_list(cls: type[Self], *args: tuple[Any]) -> list[Any]:
349346
@classmethod
350347
def is_ld_node(cls: type[Self], ld_value: Any) -> bool:
351348
"""
352-
Returns wheter the given value is considered to be possible of representing an expanded JSON-LD node.
349+
Returns wheter the given value is considered to be possible of representing an expanded JSON-LD node.\n
353350
I.e. if ld_value is of the form [{a: b, ..., y: z}].
354351
355352
Args:
@@ -364,7 +361,7 @@ def is_ld_node(cls: type[Self], ld_value: Any) -> bool:
364361
def is_ld_id(cls: type[Self], ld_value: Any) -> bool:
365362
"""
366363
Returns wheter the given value is considered to be possible of representing an expanded JSON-LD node
367-
containing only an @id value.
364+
containing only an @id value.\n
368365
I.e. if ld_value is of the form [{"@id": ...}].
369366
370367
Args:
@@ -378,7 +375,7 @@ def is_ld_id(cls: type[Self], ld_value: Any) -> bool:
378375
@classmethod
379376
def is_ld_value(cls: type[Self], ld_value: Any) -> bool:
380377
"""
381-
Returns wheter the given value is considered to be possible of representing an expanded JSON-LD value.
378+
Returns wheter the given value is considered to be possible of representing an expanded JSON-LD value.\n
382379
I.e. if ld_value is of the form [{"@value": a, ..., x: z}].
383380
384381
Args:
@@ -393,7 +390,7 @@ def is_ld_value(cls: type[Self], ld_value: Any) -> bool:
393390
def is_typed_ld_value(cls: type[Self], ld_value: Any) -> bool:
394391
"""
395392
Returns wheter the given value is considered to be possible of representing an expanded JSON-LD value
396-
containing a value type.
393+
containing a value type.\n
397394
I.e. if ld_value is of the form [{"@value": a, "@type": b, ..., x: z}].
398395
399396
Args:
@@ -408,7 +405,7 @@ def is_typed_ld_value(cls: type[Self], ld_value: Any) -> bool:
408405
def is_json_id(cls: type[Self], ld_value: Any) -> bool:
409406
"""
410407
Returns wheter the given value is considered to be possible of representing a non-expanded JSON-LD node
411-
containing only an @id value.
408+
containing only an @id value.\n
412409
I.e. if ld_value is of the form {"@id": ...}.
413410
414411
Args:
@@ -422,7 +419,7 @@ def is_json_id(cls: type[Self], ld_value: Any) -> bool:
422419
@classmethod
423420
def is_json_value(cls: type[Self], ld_value: Any) -> bool:
424421
"""
425-
Returns wheter the given value is considered to be possible of representing a non-expanded JSON-LD value.
422+
Returns wheter the given value is considered to be possible of representing a non-expanded JSON-LD value.\n
426423
I.e. if ld_value is of the form {"@value": b, ..., x: z}.
427424
428425
Args:
@@ -437,7 +434,7 @@ def is_json_value(cls: type[Self], ld_value: Any) -> bool:
437434
def is_typed_json_value(cls: type[Self], ld_value: Any) -> bool:
438435
"""
439436
Returns wheter the given value is considered to be possible of representing a non-expanded JSON-LD value
440-
containing a value type.
437+
containing a value type.\n
441438
I.e. if ld_value is of the form {"@value": a, "@type": b, ..., x: z}.
442439
443440
Args:
@@ -472,8 +469,7 @@ def are_values_equal(
472469
) -> bool:
473470
"""
474471
Returns whether or not the given expanded JSON-LD values are considered equal.
475-
The comparison compares the "@id" values first and returns the result if it is conclusive.
476-
472+
The comparison compares the "@id" values first and returns the result if it is conclusive.\n
477473
If the comparison is inconclusive i.e. exactly one or zero of both values have an "@id" value:
478474
Return whether or not all other keys exist in both values and all values of the keys are the same.
479475

src/hermes/model/types/ld_context.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ class ContextPrefix:
4747
- as a list of linked data vocabularies, where items can be vocabulary base IRI strings and/or dictionaries mapping
4848
arbitrary strings used to prefix terms from a specific vocabulary to their respective vocabulary IRI strings.;
4949
- as a dict mapping prefixes to vocabulary IRIs, where the default vocabulary has a prefix of None.
50+
51+
Attributes:
52+
vocabularies (list[str | dict]): TODO
53+
context: TODO
5054
"""
5155

5256
def __init__(self, vocabularies: list[str | dict]):
@@ -55,9 +59,13 @@ def __init__(self, vocabularies: list[str | dict]):
5559
string is used more than once across all dictionaries in the list, the last item with this key will be included
5660
in the context.
5761
58-
:param vocabularies: A list of linked data vocabularies. Items can be vocabulary base IRI strings and/or
59-
dictionaries mapping arbitrary strings used to prefix terms from a specific vocabulary to their respective
60-
vocabulary IRI strings.
62+
Args:
63+
vocabularies (list[str | dict]): A list of linked data vocabularies. Items can be vocabulary base IRI
64+
strings and/or dictionaries mapping arbitrary strings used to prefix terms from a specific vocabulary to
65+
their respective vocabulary IRI strings.
66+
67+
Returns:
68+
None:
6169
"""
6270
self.vocabularies = vocabularies
6371
self.context = {}
@@ -81,20 +89,22 @@ def __getitem__(self, compressed_term: str | tuple) -> str:
8189
8290
Example uses:
8391
84-
context = <self>(["iri_default", {"prefix1": "iri1"}])
85-
# access qualified term via str
86-
term = context["term_in_default_vocabulary"]
87-
term = context["prefix1:term"]
88-
# access qualified term via tuple
89-
term = context["prefix1", "term"]
92+
context = <self>(["iri_default", {"prefix1": "iri1"}])\n
93+
# access qualified term via str\n
94+
term = context["term_in_default_vocabulary"]\n
95+
term = context["prefix1:term"]\n
96+
# access qualified term via tuple\n
97+
term = context["prefix1", "term"]\n
9098
term = context[None, "term_in_default_vocabulary"]
9199
92-
:param compressed_term: A term from a vocabulary in the context; terms from the default vocabulary are passed
93-
with a prefix of None, or as an unprefixed string, terms from non-default vocabularies are prefixed with the
94-
defined prefix for the vocabulary. The term can either be passed in as string <term> if prefix is None, or
95-
"<prefix>:<term>", or as a tuple.
100+
Args:
101+
compressed_term (str | tuple): A term from a vocabulary in the context; terms from the default vocabulary
102+
are passed with a prefix of None, or as an unprefixed string, terms from non-default vocabularies are
103+
prefixed with the defined prefix for the vocabulary. The term can either be passed in as string <term>
104+
if prefix is None, or "<prefix>:<term>", or as a tuple.
96105
97-
:return: The fully qualified IRI for the passed term
106+
Returns:
107+
str: The fully qualified IRI for the passed term
98108
"""
99109
if not isinstance(compressed_term, str):
100110
prefix, term = compressed_term

0 commit comments

Comments
 (0)