diff options
Diffstat (limited to 'bsie/extractor/generic/constant.py')
-rw-r--r-- | bsie/extractor/generic/constant.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/bsie/extractor/generic/constant.py b/bsie/extractor/generic/constant.py new file mode 100644 index 0000000..e243131 --- /dev/null +++ b/bsie/extractor/generic/constant.py @@ -0,0 +1,52 @@ +"""The Constant extractor produces pre-specified triples. + +Part of the bsie module. +A copy of the license is provided with the project. +Author: Matthias Baumgartner, 2022 +""" +# imports +import typing + +# inner-module imports +from bsie.base import extractor +from bsie.utils.bsfs import URI +from bsie.utils.node import Node + +# exports +__all__: typing.Sequence[str] = ( + 'Constant', + ) + + +## code ## + +class Constant(extractor.Extractor): + """Extract information from file's path.""" + + CONTENT_READER = None + + def __init__( + self, + schema: str, + tuples: typing.Iterable[typing.Tuple[URI, typing.Any]], + ): + self._schema = schema + self._tuples = tuples + # FIXME: use schema instance for predicate checking + #self._tuples = [(pred, value) for pred, value in tuples if pred in schema] + # FIXME: use schema instance for value checking + + def schema(self) -> str: + return self._schema + + def extract( + self, + subject: Node, + content: None, + predicates: typing.Iterable[URI], + ) -> typing.Iterator[typing.Tuple[Node, URI, typing.Any]]: + for pred, value in self._tuples: + if pred in predicates: + yield subject, pred, value + +## EOF ## |