diff options
author | Matthias Baumgartner <dev@igsor.net> | 2022-12-08 16:36:19 +0100 |
---|---|---|
committer | Matthias Baumgartner <dev@igsor.net> | 2022-12-08 16:36:19 +0100 |
commit | e8492489098ef5f8566214e083cd2c2d1d449f5a (patch) | |
tree | af2f31c9fd1e13502ef36b9a5db845b29a92c250 /bsfs/graph/graph.py | |
parent | 547aa08b1f05ec0cdf725c34a7b1d1512b694063 (diff) | |
download | bsfs-e8492489098ef5f8566214e083cd2c2d1d449f5a.tar.gz bsfs-e8492489098ef5f8566214e083cd2c2d1d449f5a.tar.bz2 bsfs-e8492489098ef5f8566214e083cd2c2d1d449f5a.zip |
sparql triple store and graph (nodes, mostly)
Diffstat (limited to 'bsfs/graph/graph.py')
-rw-r--r-- | bsfs/graph/graph.py | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/bsfs/graph/graph.py b/bsfs/graph/graph.py new file mode 100644 index 0000000..06271f6 --- /dev/null +++ b/bsfs/graph/graph.py @@ -0,0 +1,65 @@ +""" + +Part of the BlackStar filesystem (bsfs) module. +A copy of the license is provided with the project. +Author: Matthias Baumgartner, 2022 +""" +# imports +import typing + +# bsfs imports +from bsfs.schema import Schema +from bsfs.triple_store import TripleStoreBase +from bsfs.utils import URI, typename + +# inner-module imports +from . import nodes + +# exports +__all__: typing.Sequence[str] = ( + 'Graph', + ) + + +## code ## + +class Graph(): + """ + """ + # link to the triple storage backend. + __backend: TripleStoreBase + + # user uri. + __user: URI + + def __init__(self, backend: TripleStoreBase, user: URI): + self.__backend = backend + self.__user = user + + def __hash__(self) -> int: + return hash((type(self), self.__backend, self.__user)) + + def __eq__(self, other) -> bool: + return isinstance(other, type(self)) \ + and self.__backend == other.__backend \ + and self.__user == other.__user + + def __repr__(self) -> str: + return f'{typename(self)}(backend={repr(self.__backend)}, user={self.__user})' + + def __str__(self) -> str: + return f'{typename(self)}({str(self.__backend)}, {self.__user})' + + @property + def schema(self) -> Schema: + """Return the store's local schema.""" + return self.__backend.schema + + def nodes(self, node_type: URI, guids: typing.Iterable[URI]) -> nodes.Nodes: + """ + """ + node_type = self.schema.node(node_type) + # NOTE: Nodes constructor materializes guids. + return nodes.Nodes(self.__backend, self.__user, node_type, guids) + +## EOF ## |