aboutsummaryrefslogtreecommitdiffstats
path: root/bsfs/graph/graph.py
blob: 71973c26cd196968fd3ae75ebc3da67b19370840 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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 as _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, type_, guids)

## EOF ##