aboutsummaryrefslogtreecommitdiffstats
path: root/bsie/lib/bsie.py
diff options
context:
space:
mode:
Diffstat (limited to 'bsie/lib/bsie.py')
-rw-r--r--bsie/lib/bsie.py61
1 files changed, 36 insertions, 25 deletions
diff --git a/bsie/lib/bsie.py b/bsie/lib/bsie.py
index 3aeee2b..e087fa9 100644
--- a/bsie/lib/bsie.py
+++ b/bsie/lib/bsie.py
@@ -8,8 +8,6 @@ Author: Matthias Baumgartner, 2022
import typing
# bsie imports
-from bsie.tools.pipeline import Pipeline
-from bsie.utils.bsfs import URI, schema as schema_
from bsie.tools import Pipeline
from bsie.utils import bsfs, node, ns
@@ -30,11 +28,14 @@ class BSIE():
"""
+ # pipeline
+ _pipeline: Pipeline
+
# predicates to extract.
- predicates: typing.Set[URI]
+ _principals: typing.Set[bsfs.URI]
# local schema.
- schema: schema_.Schema
+ _schema: bsfs.schema.Schema
def __init__(
self,
@@ -46,36 +47,46 @@ class BSIE():
discard: typing.Optional[typing.Iterable[bsfs.URI]] = None,
):
# store pipeline
- self.pipeline = pipeline
- # start off with available predicates
- self.predicates = {pred.uri for pred in self.pipeline.predicates()}
- # limit predicates to specified ones by argument.
+ self._pipeline = pipeline
+ # start off with available principals
+ self._principals = {pred.uri for pred in self._pipeline.principals}
+ # limit principals to specified ones by argument.
if collect is not None:
collect = set(collect)
if len(collect) > 0:
- self.predicates &= collect
- # discard predicates.
+ self._principals &= collect
+ # discard principals.
if discard is not None:
- self.predicates -= set(discard)
+ self._principals -= set(discard)
# discard ns.bsfs.Predicate
- self.predicates.discard(ns.bsfs.Predicate)
- # compile a schema that only contains the requested predicates (and implied types)
- self.schema = schema_.Schema({
- self.pipeline.schema.predicate(pred) for pred in self.predicates})
+ self._principals.discard(ns.bsfs.Predicate)
+ # compile a schema that only contains the requested principals (and auxiliary predicates)
+ self._schema = self._pipeline.subschema(
+ self._pipeline.schema.predicate(pred) for pred in self._principals)
+
+ @property
+ def schema(self) -> bsfs.schema.Schema:
+ """Return the BSIE schema."""
+ return self._schema
+
+ @property
+ def principals(self) -> typing.Iterator[bsfs.URI]:
+ """Return an iterator to the principal predicates."""
+ return iter(self._principals)
def from_file(
self,
- path: URI,
- predicates: typing.Optional[typing.Iterable[URI]] = None,
- ) -> typing.Iterator[typing.Tuple[node.Node, URI, typing.Any]]:
- """Produce triples for a given *path*. Limit to *predicates* if given."""
- # get requested predicates.
- predicates = set(predicates) if predicates is not None else self.predicates
- # filter through requested predicates.
- predicates &= self.predicates
+ path: bsfs.URI,
+ principals: typing.Optional[typing.Iterable[bsfs.URI]] = None,
+ ) -> typing.Iterator[typing.Tuple[node.Node, bsfs.URI, typing.Any]]:
+ """Produce triples for a given *path*. Limit to *principals* if given."""
+ # get requested principals.
+ principals = set(principals) if principals is not None else self._principals
+ # filter through requested principals.
+ principals &= self._principals
# predicate lookup
- predicates = {self.schema.predicate(pred) for pred in predicates}
+ principals = {self.schema.predicate(pred) for pred in principals}
# invoke pipeline
- yield from self.pipeline(path, predicates)
+ yield from self._pipeline(path, principals)
## EOF ##