aboutsummaryrefslogtreecommitdiffstats
path: root/bsfs/triple_store/sparql
diff options
context:
space:
mode:
authorMatthias Baumgartner <dev@igsor.net>2023-02-08 20:15:41 +0100
committerMatthias Baumgartner <dev@igsor.net>2023-02-08 20:15:41 +0100
commitcb819b8c268908b5f6cc680173db86e172847c46 (patch)
tree3046c960ea8377e12655c622f182a2d2115fa712 /bsfs/triple_store/sparql
parentc8fdaaa676afbdcf33344d72bd92b3ccb981cbf8 (diff)
downloadbsfs-cb819b8c268908b5f6cc680173db86e172847c46.tar.gz
bsfs-cb819b8c268908b5f6cc680173db86e172847c46.tar.bz2
bsfs-cb819b8c268908b5f6cc680173db86e172847c46.zip
binary blob in schema and sparql triple store
Diffstat (limited to 'bsfs/triple_store/sparql')
-rw-r--r--bsfs/triple_store/sparql/sparql.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/bsfs/triple_store/sparql/sparql.py b/bsfs/triple_store/sparql/sparql.py
index a0dd12e..dbf9d45 100644
--- a/bsfs/triple_store/sparql/sparql.py
+++ b/bsfs/triple_store/sparql/sparql.py
@@ -5,8 +5,11 @@ A copy of the license is provided with the project.
Author: Matthias Baumgartner, 2022
"""
# imports
+import base64
import itertools
import typing
+
+# external imports
import rdflib
# bsfs imports
@@ -30,6 +33,8 @@ __all__: typing.Sequence[str] = (
## code ##
+rdflib.term.bind(ns.bsfs.BinaryBlob, bytes, constructor=base64.b64decode)
+
class _Transaction():
"""Lightweight rdflib transactions for in-memory databases."""
@@ -242,7 +247,7 @@ class SparqlStore(base.TripleStoreBase):
) -> typing.Iterator[URI]:
if node_type not in self.schema.nodes():
raise errors.ConsistencyError(f'{node_type} is not defined in the schema')
- if not isinstance(filter, ast.filter.FilterExpression):
+ if filter is not None and not isinstance(filter, ast.filter.FilterExpression):
raise TypeError(filter)
# compose query
query = self._filter_parser(node_type, filter)
@@ -334,7 +339,11 @@ class SparqlStore(base.TripleStoreBase):
guid = rdflib.URIRef(guid)
# convert value
if isinstance(predicate.range, bsc.Literal):
- value = rdflib.Literal(value, datatype=rdflib.URIRef(predicate.range.uri))
+ dtype = rdflib.URIRef(predicate.range.uri)
+ if predicate.range <= self.schema.literal(ns.bsfs.BinaryBlob):
+ dtype = rdflib.URIRef(ns.bsfs.BinaryBlob)
+ value = base64.b64encode(value)
+ value = rdflib.Literal(value, datatype=dtype)
elif isinstance(predicate.range, bsc.Node):
value = rdflib.URIRef(value)
else: