aboutsummaryrefslogtreecommitdiffstats
path: root/bsie
diff options
context:
space:
mode:
Diffstat (limited to 'bsie')
-rw-r--r--bsie/base/extractor.py7
-rw-r--r--bsie/base/reader.py6
-rw-r--r--bsie/extractor/generic/constant.py6
-rw-r--r--bsie/utils/node.py18
4 files changed, 35 insertions, 2 deletions
diff --git a/bsie/base/extractor.py b/bsie/base/extractor.py
index 7acf2bd..2fc4f18 100644
--- a/bsie/base/extractor.py
+++ b/bsie/base/extractor.py
@@ -63,6 +63,13 @@ class Extractor(abc.ABC):
def __repr__(self) -> str:
return f'{typename(self)}()'
+ def __eq__(self, other: typing.Any) -> bool:
+ return isinstance(other, type(self)) \
+ and self.CONTENT_READER == other.CONTENT_READER \
+ and self.schema == other.schema
+
+ def __hash__(self) -> int:
+ return hash((type(self), self.CONTENT_READER, self.schema))
def predicates(self) -> typing.Iterator[_schema.Predicate]:
"""Return the predicates that may be part of extracted triples."""
diff --git a/bsie/base/reader.py b/bsie/base/reader.py
index e59abef..b7eabf7 100644
--- a/bsie/base/reader.py
+++ b/bsie/base/reader.py
@@ -32,6 +32,12 @@ class Reader(abc.ABC):
def __repr__(self) -> str:
return f'{typename(self)}()'
+ def __eq__(self, other: typing.Any) -> bool:
+ return isinstance(other, type(self))
+
+ def __hash__(self) -> int:
+ return hash(type(self))
+
@abc.abstractmethod
def __call__(self, path: URI) -> typing.Any:
"""Return some content of the file at *path*.
diff --git a/bsie/extractor/generic/constant.py b/bsie/extractor/generic/constant.py
index 795bac6..7da792a 100644
--- a/bsie/extractor/generic/constant.py
+++ b/bsie/extractor/generic/constant.py
@@ -38,6 +38,12 @@ class Constant(extractor.Extractor):
self._tuples = tuple((self.schema.predicate(p_uri), value) for p_uri, value in tuples)
# FIXME: use schema instance for value checking
+ def __eq__(self, other: typing.Any) -> bool:
+ return super().__eq__(other) \
+ and self._tuples == other._tuples
+
+ def __hash__(self) -> int:
+ return hash((super().__hash__(), self._tuples))
def extract(
self,
diff --git a/bsie/utils/node.py b/bsie/utils/node.py
index 3a0f06b..c9c494f 100644
--- a/bsie/utils/node.py
+++ b/bsie/utils/node.py
@@ -7,8 +7,8 @@ Author: Matthias Baumgartner, 2022
# imports
import typing
-# inner-module imports
-from bsie.utils.bsfs import URI
+# bsie imports
+from bsie.utils.bsfs import URI, typename
# exports
__all__: typing.Sequence[str] = (
@@ -36,4 +36,18 @@ class Node():
self.node_type = URI(node_type)
self.uri = URI(uri)
+ def __eq__(self, other: typing.Any) -> bool:
+ return isinstance(other, Node) \
+ and other.node_type == self.node_type \
+ and other.uri == self.uri
+
+ def __hash__(self) -> int:
+ return hash((type(self), self.node_type, self.uri))
+
+ def __str__(self) -> str:
+ return f'{typename(self)}({self.node_type}, {self.uri})'
+
+ def __repr__(self) -> str:
+ return f'{typename(self)}({self.node_type}, {self.uri})'
+
## EOF ##