Added generic parser - #215
Conversation
| str: decode_bnode, | ||
| jelly.RdfLiteral: decode_literal, | ||
| jelly.RdfDefaultGraph: decode_default_graph, | ||
| jelly.RdfTriple: decode_triple, |
There was a problem hiding this comment.
this is a preparation for RDF-star
There was a problem hiding this comment.
by default doesn't seem to work right with RDF-star :(
| self._store.append(tuple(statement)) | ||
|
|
||
| def bind(self, prefix: str, namespace: str) -> None: | ||
| self._namespaces.update({prefix: namespace}) |
There was a problem hiding this comment.
currently not used anywhere, can potentially remove from here and from adapters, or just raise exception here
There was a problem hiding this comment.
Isn't that needed to pass conformance tests? We will have cases where you need to preserve namespaces.
There was a problem hiding this comment.
current conformance tests rely solely on .nt/.nq format, so no namespaces are there
from the spec, there is only one place that can issue a couple conformance tests:
value (2) – the IRI of the namespace as an RdfIri message. This field is REQUIRED.
| self._store.append(tuple(statement)) | ||
|
|
||
| def bind(self, prefix: str, namespace: str) -> None: | ||
| self._namespaces.update({prefix: namespace}) |
There was a problem hiding this comment.
Isn't that needed to pass conformance tests? We will have cases where you need to preserve namespaces.
| class Triple(tuple[Node, Node, Node]): | ||
| """ | ||
| Class for RDF triples. | ||
|
|
||
| Args: | ||
| tuple (Node): tuple of three elements (s/p/o), | ||
| being of one of the types of Node. | ||
|
|
||
| """ | ||
|
|
||
| __slots__ = () | ||
|
|
||
| def __new__(cls, s: Node, p: Node, o: Node) -> Self: | ||
| return tuple.__new__(cls, (s, p, o)) | ||
|
|
||
| @property | ||
| def s(self) -> Node: | ||
| return self[0] | ||
|
|
||
| @property | ||
| def p(self) -> Node: | ||
| return self[1] | ||
|
|
||
| @property | ||
| def o(self) -> Node: | ||
| return self[2] | ||
|
|
||
|
|
||
| class Quad(tuple[Node, Node, Node, Node]): | ||
| """ | ||
| Class for RDF quads. | ||
|
|
||
| Args: | ||
| tuple (Node): tuple of four elements (s/p/o/g), | ||
| being of one of the types of Node. | ||
|
|
||
| """ | ||
|
|
||
| __slots__ = () | ||
|
|
||
| def __new__(cls, s: Node, p: Node, o: Node, g: Node) -> Self: | ||
| return tuple.__new__(cls, (s, p, o, g)) | ||
|
|
||
| @property | ||
| def s(self) -> Node: | ||
| return self[0] | ||
|
|
||
| @property | ||
| def p(self) -> Node: | ||
| return self[1] | ||
|
|
||
| @property | ||
| def o(self) -> Node: | ||
| return self[2] | ||
|
|
||
| @property | ||
| def g(self) -> Node: | ||
| return self[3] | ||
|
|
||
|
|
||
| class Prefix(tuple[str, IRI]): | ||
| """ | ||
| Class for generic namespace declaration. | ||
|
|
||
| Args: | ||
| tuple (str, IRI): namespace prefix and URI. | ||
|
|
||
| """ | ||
|
|
||
| __slots__ = () | ||
|
|
||
| def __new__(cls, prefix: str, iri: IRI) -> Self: | ||
| return tuple.__new__(cls, (prefix, iri)) | ||
|
|
||
| @property | ||
| def prefix(self) -> str: | ||
| return self[0] | ||
|
|
||
| @property | ||
| def iri(self) -> IRI: | ||
| return self[1] |
There was a problem hiding this comment.
You may want to use typing.NamedTuple here as the base for Triple, Quad and Prefix:
class Triple(NamedTuple):
"""
Class for RDF triples.
"""
s: Node
p: Node
o: Node
class Quad(NamedTuple):
"""
Class for RDF quads.
"""
s: Node
p: Node
o: Node
g: Node
class Prefix(NamedTuple):
"""
Class for generic namespace declaration.
"""
prefix: str
iri: IRIThis offers identical benefits (named tuple read-only members, built-in constructor, structural unpacking & fast slot access)
The docstrings were incorrect, as one might have thought a single argument with tuple with values is expected, not multiple positional arguments to fill tuple members.
There was a problem hiding this comment.
great comment, thank you, Bartosz! :)
Ja-Gk-00
left a comment
There was a problem hiding this comment.
It's good enough for now, let's merge, then make a quick patch.
af3b121 to
929379e
Compare
Relates to #213
Changes: