diff options
author | Matthias Baumgartner <dev@igsor.net> | 2023-02-08 19:25:19 +0100 |
---|---|---|
committer | Matthias Baumgartner <dev@igsor.net> | 2023-02-08 19:25:19 +0100 |
commit | 7bf6b33fa6d6b901e4933bfe0b2a9939d7b3f3f3 (patch) | |
tree | d280d9d1e19e4f7a9d0d4b5405603c729e1fdcce /bsie/utils | |
parent | 05a841215c82ef40d4679dfc4d2c26572bd4d349 (diff) | |
parent | 0d0144466919cfb168e75c2af26d5cb74e10bfa0 (diff) | |
download | bsie-7bf6b33fa6d6b901e4933bfe0b2a9939d7b3f3f3.tar.gz bsie-7bf6b33fa6d6b901e4933bfe0b2a9939d7b3f3f3.tar.bz2 bsie-7bf6b33fa6d6b901e4933bfe0b2a9939d7b3f3f3.zip |
Merge branch 'previews' into develop
Diffstat (limited to 'bsie/utils')
-rw-r--r-- | bsie/utils/namespaces.py | 4 | ||||
-rw-r--r-- | bsie/utils/node.py | 29 |
2 files changed, 26 insertions, 7 deletions
diff --git a/bsie/utils/namespaces.py b/bsie/utils/namespaces.py index 393b436..0af8ece 100644 --- a/bsie/utils/namespaces.py +++ b/bsie/utils/namespaces.py @@ -12,16 +12,18 @@ from . import bsfs as _bsfs # constants bse = _bsfs.Namespace('http://bsfs.ai/schema/Entity') +bsf = _bsfs.Namespace('http://ie.bsfs.ai/schema/Feature') bsfs = _bsfs.Namespace('http://bsfs.ai/schema', fsep='/') bsm = _bsfs.Namespace('http://bsfs.ai/schema/Meta') +bsp = _bsfs.Namespace('http://bsfs.ai/schema/Preview') xsd = _bsfs.Namespace('http://www.w3.org/2001/XMLSchema') -bsf = _bsfs.Namespace('http://ie.bsfs.ai/schema/Feature') # export __all__: typing.Sequence[str] = ( 'bse', 'bsfs', 'bsm', + 'bsp', 'xsd', ) diff --git a/bsie/utils/node.py b/bsie/utils/node.py index 91e4f37..aa62c06 100644 --- a/bsie/utils/node.py +++ b/bsie/utils/node.py @@ -19,30 +19,47 @@ __all__: typing.Sequence[str] = ( ## code ## class Node(): - """Lightweight Node, disconnected from any bsfs structures.""" + """Lightweight Node, disconnected from any bsfs structures. + + In most cases, provide *hints* and leave setting the uri to a node + naming policy. Only provide an *uri* if it is absolutely determined. + + """ # node type. node_type: bsfs.URI # node URI. - uri: bsfs.URI + uri: typing.Optional[bsfs.URI] + + # node naming hints. + hits: dict def __init__( self, node_type: bsfs.URI, - uri: bsfs.URI, + uri: typing.Optional[bsfs.URI] = None, + **uri_hints, ): # assign members self.node_type = bsfs.URI(node_type) - self.uri = bsfs.URI(uri) + self.hints = uri_hints + self.uri = uri def __eq__(self, other: typing.Any) -> bool: + """Compare two Node instances based on type and uri. + Compares hits only if the uri is not yet specified. + """ return isinstance(other, Node) \ and other.node_type == self.node_type \ - and other.uri == self.uri + and other.uri == self.uri \ + and (self.uri is not None or self.hints == other.hints) def __hash__(self) -> int: - return hash((type(self), self.node_type, self.uri)) + identifier = self.uri + if identifier is None: + identifier = tuple((key, self.hints[key]) for key in sorted(self.hints)) + return hash((type(self), self.node_type, identifier)) def __str__(self) -> str: return f'{bsfs.typename(self)}({self.node_type}, {self.uri})' |