From 057e09d6537bf5c39815661a75819081e3e5fda7 Mon Sep 17 00:00:00 2001 From: Matthias Baumgartner Date: Sun, 18 Dec 2022 13:37:59 +0100 Subject: adaptions to updates in bsfs --- bsie/tools/pipeline.py | 7 +++++-- bsie/utils/bsfs.py | 2 ++ bsie/utils/namespaces.py | 8 ++++---- test/apps/test_index.py | 4 ++-- test/lib/test_bsie.py | 4 ++-- test/tools/test_pipeline.py | 2 +- 6 files changed, 16 insertions(+), 11 deletions(-) diff --git a/bsie/tools/pipeline.py b/bsie/tools/pipeline.py index 52ce526..20e8ddf 100644 --- a/bsie/tools/pipeline.py +++ b/bsie/tools/pipeline.py @@ -18,6 +18,9 @@ __all__: typing.Sequence[str] = ( 'Pipeline', ) +# constants +FILE_PREFIX = 'file#' + ## code ## logger = logging.getLogger(__name__) @@ -48,7 +51,7 @@ class Pipeline(): ext2rdr: typing.Dict[base.extractor.Extractor, typing.Optional[base.reader.Reader]] ): # store core members - self._prefix = prefix + self._prefix = prefix + FILE_PREFIX self._ext2rdr = ext2rdr # compile schema from all extractors self._schema = bsfs.schema.Schema.Union(ext.schema for ext in ext2rdr) @@ -114,7 +117,7 @@ class Pipeline(): # create subject for file uuid = bsfs.uuid.UCID.from_path(path) - subject = node.Node(ns.bsfs.File, self._prefix + 'file#' + uuid) + subject = node.Node(ns.bsfs.File, self._prefix[uuid]) # extract information for rdr, extrs in rdr2ext.items(): diff --git a/bsie/utils/bsfs.py b/bsie/utils/bsfs.py index c48049d..0b88479 100644 --- a/bsie/utils/bsfs.py +++ b/bsie/utils/bsfs.py @@ -9,6 +9,7 @@ import typing # bsfs imports from bsfs import Open, schema +from bsfs.apps.init import init_sparql_store from bsfs.namespace import Namespace from bsfs.utils import URI, typename, uuid @@ -17,6 +18,7 @@ __all__: typing.Sequence[str] = ( 'Namespace', 'Open', 'URI', + 'init_sparql_store', 'schema', 'typename', 'uuid', diff --git a/bsie/utils/namespaces.py b/bsie/utils/namespaces.py index d6e1c72..a29fc1b 100644 --- a/bsie/utils/namespaces.py +++ b/bsie/utils/namespaces.py @@ -11,10 +11,10 @@ import typing from . import bsfs as _bsfs # constants -bse = _bsfs.Namespace('http://bsfs.ai/schema/Entity#') -bsfs = _bsfs.Namespace('http://bsfs.ai/schema/') -bsm = _bsfs.Namespace('http://bsfs.ai/schema/Meta#') -xsd = _bsfs.Namespace('http://www.w3.org/2001/XMLSchema#') +bse = _bsfs.Namespace('http://bsfs.ai/schema/Entity') +bsfs = _bsfs.Namespace('http://bsfs.ai/schema', fsep='/') +bsm = _bsfs.Namespace('http://bsfs.ai/schema/Meta') +xsd = _bsfs.Namespace('http://www.w3.org/2001/XMLSchema') # export __all__: typing.Sequence[str] = ( diff --git a/test/apps/test_index.py b/test/apps/test_index.py index 2be8470..9cdc656 100644 --- a/test/apps/test_index.py +++ b/test/apps/test_index.py @@ -30,7 +30,7 @@ class TestIndex(unittest.TestCase): ]) prefix = 'http://example.com/me/file#' - self.assertTrue(set(bsfs._Graph__backend.graph).issuperset({ + self.assertTrue(set(bsfs._backend._graph).issuperset({ (rdflib.URIRef(prefix + '2f4109b40107cc50e0884755a1a961ed126887e49b8dbaf0e146b2e226aa6647'), rdflib.RDF.type, rdflib.URIRef(ns.bsfs.File)), (rdflib.URIRef(prefix + '2f4109b40107cc50e0884755a1a961ed126887e49b8dbaf0e146b2e226aa6647'), rdflib.URIRef(ns.bse.author), rdflib.Literal('Me, myself, and I', datatype=rdflib.XSD.string)), (rdflib.URIRef(prefix + '2f4109b40107cc50e0884755a1a961ed126887e49b8dbaf0e146b2e226aa6647'), rdflib.URIRef(ns.bse.filename), rdflib.Literal('alpha_second', datatype=rdflib.XSD.string)), @@ -90,7 +90,7 @@ class TestIndex(unittest.TestCase): # (rdflib.URIRef(prefix + 'd43758ace82154a1cc10ca0dfef63cb20dd831f9c87edd6dc06539eefe67371d'), rdflib.URIRef(ns.bsm.t_created), rdflib.Literal('1670..........', datatype=rdflib.XSD.integer)), # (rdflib.URIRef(prefix + 'd803187cbf3676ae9d38126270a6152c60431589aa3bb3824baf8954e9c097f1'), rdflib.URIRef(ns.bsm.t_created), rdflib.Literal('1670..........', datatype=rdflib.XSD.integer)), # instead, we simply check if there's such a predicate for each file - self.assertSetEqual({sub for sub, _ in bsfs._Graph__backend.graph.subject_objects(rdflib.URIRef(ns.bsm.t_created))}, { + self.assertSetEqual({sub for sub, _ in bsfs._backend._graph.subject_objects(rdflib.URIRef(ns.bsm.t_created))}, { rdflib.URIRef(prefix + '2f4109b40107cc50e0884755a1a961ed126887e49b8dbaf0e146b2e226aa6647'), rdflib.URIRef(prefix + '441f3d10c8ff489fe8e33e639606512f6c463151cc429de7e554b9af670c2ece'), rdflib.URIRef(prefix + '69b98ecf7aff3e95b09688ba93331678eb8397817111f674c9558e6dd8f5e871'), diff --git a/test/lib/test_bsie.py b/test/lib/test_bsie.py index f3f476e..771a0c2 100644 --- a/test/lib/test_bsie.py +++ b/test/lib/test_bsie.py @@ -38,7 +38,7 @@ class TestBSIE(unittest.TestCase): )}, ]) # build pipeline - self.prefix = bsfs.Namespace('http://example.com/local/file#') + self.prefix = bsfs.Namespace('http://example.com/local/') pbuild = builder.PipelineBuilder(self.prefix, rbuild, ebuild) self.pipeline = pbuild.build() @@ -155,7 +155,7 @@ class TestBSIE(unittest.TestCase): ns.bse.author, }) content_hash = 'a948904f2f0f479b8f8197694b30184b0d2ed1c1cd2a1ec0fb85d299a192a447' - subject = node.Node(ns.bsfs.File, self.prefix + 'file#' + content_hash) + subject = node.Node(ns.bsfs.File, (self.prefix + 'file#')[content_hash]) testfile = os.path.join(os.path.dirname(__file__), 'testfile.t') # from_file extracts all available triples diff --git a/test/tools/test_pipeline.py b/test/tools/test_pipeline.py index 91bf736..a116a30 100644 --- a/test/tools/test_pipeline.py +++ b/test/tools/test_pipeline.py @@ -94,7 +94,7 @@ class TestPipeline(unittest.TestCase): pipeline = Pipeline(self.prefix, self.ext2rdr) # build objects for tests content_hash = 'a948904f2f0f479b8f8197694b30184b0d2ed1c1cd2a1ec0fb85d299a192a447' - subject = node.Node(ns.bsfs.File, self.prefix + 'file#' + content_hash) + subject = node.Node(ns.bsfs.File, (self.prefix + 'file#')[content_hash]) testfile = os.path.join(os.path.dirname(__file__), 'testfile.t') p_filename = pipeline.schema.predicate(ns.bse.filename) p_filesize = pipeline.schema.predicate(ns.bse.filesize) -- cgit v1.2.3