aboutsummaryrefslogtreecommitdiffstats
path: root/bsfs
diff options
context:
space:
mode:
authorMatthias Baumgartner <dev@igsor.net>2023-01-12 10:26:30 +0100
committerMatthias Baumgartner <dev@igsor.net>2023-01-12 10:26:30 +0100
commitb0ff4ed674ad78bf113c3cc0c2ccd187ccb91048 (patch)
treeadfc97349cac6a6856970c5e1dc187c2ed8f878c /bsfs
parent7e7284d5fc01c0a081aa79d67736f51069864a7d (diff)
downloadbsfs-b0ff4ed674ad78bf113c3cc0c2ccd187ccb91048.tar.gz
bsfs-b0ff4ed674ad78bf113c3cc0c2ccd187ccb91048.tar.bz2
bsfs-b0ff4ed674ad78bf113c3cc0c2ccd187ccb91048.zip
number literal adaptions
Diffstat (limited to 'bsfs')
-rw-r--r--bsfs/graph/schema.nt3
-rw-r--r--bsfs/query/validator.py6
-rw-r--r--bsfs/triple_store/sparql/parse_filter.py1
-rw-r--r--bsfs/triple_store/sparql/sparql.py4
4 files changed, 9 insertions, 5 deletions
diff --git a/bsfs/graph/schema.nt b/bsfs/graph/schema.nt
index 8612681..f619746 100644
--- a/bsfs/graph/schema.nt
+++ b/bsfs/graph/schema.nt
@@ -8,7 +8,8 @@ prefix bsfs: <http://bsfs.ai/schema/>
prefix bsm: <http://bsfs.ai/schema/Meta#>
# literals
-xsd:integer rdfs:subClassOf bsfs:Literal .
+bsfs:Number rdfs:subClassOf bsfs:Literal .
+xsd:integer rdfs:subClassOf bsfs:Number .
# predicates
bsm:t_created rdfs:subClassOf bsfs:Predicate ;
diff --git a/bsfs/query/validator.py b/bsfs/query/validator.py
index b04a9bf..75b51ca 100644
--- a/bsfs/query/validator.py
+++ b/bsfs/query/validator.py
@@ -182,8 +182,7 @@ class Filter():
if not type_ <= dom:
raise errors.ConsistencyError(f'expected type {dom}, found {type_}')
# node.count is a numerical expression
- # FIXME: We have to ensure that ns.xsd.integer is always known in the schema!
- self._parse_filter_expression(self.schema.literal(ns.xsd.integer), node.count)
+ self._parse_filter_expression(self.schema.literal(ns.bsfs.Number), node.count)
## conditions
@@ -211,6 +210,9 @@ class Filter():
# type exists in the schema
if type_ not in self.schema.literals():
raise errors.ConsistencyError(f'literal {type_} is not in the schema')
+ # type must be a numerical
+ if not type_ <= self.schema.literal(ns.bsfs.Number):
+ raise errors.ConsistencyError(f'expected a number type, found {type_}')
# FIXME: Check if node.value corresponds to type_
diff --git a/bsfs/triple_store/sparql/parse_filter.py b/bsfs/triple_store/sparql/parse_filter.py
index 0297cbc..18a3288 100644
--- a/bsfs/triple_store/sparql/parse_filter.py
+++ b/bsfs/triple_store/sparql/parse_filter.py
@@ -242,7 +242,6 @@ class Filter():
# predicate count expression (fetch number of predicates at *head*)
num_preds = f'{{ SELECT (COUNT(distinct {inner}) as {outer}) WHERE {{ {head} {pred} {inner} }} }}'
# count expression
- # FIXME: We have to ensure that ns.xsd.integer is always known in the schema!
count_bounds = self._parse_filter_expression(self.schema.literal(ns.xsd.integer), node.count, outer)
# combine
return num_preds + ' . ' + count_bounds
diff --git a/bsfs/triple_store/sparql/sparql.py b/bsfs/triple_store/sparql/sparql.py
index ddace35..87467ff 100644
--- a/bsfs/triple_store/sparql/sparql.py
+++ b/bsfs/triple_store/sparql/sparql.py
@@ -11,6 +11,7 @@ import rdflib
# bsfs imports
from bsfs import schema as bsc
+from bsfs.namespace import ns
from bsfs.query import ast
from bsfs.utils import errors, URI
@@ -94,7 +95,8 @@ class SparqlStore(base.TripleStoreBase):
super().__init__(None)
self._graph = rdflib.Graph()
self._transaction = _Transaction(self._graph)
- self._schema = bsc.Schema()
+ # NOTE: parsing bsfs.query.ast.filter.Has requires xsd:integer.
+ self._schema = bsc.Schema(literals={bsc.ROOT_NUMBER.child(ns.xsd.integer)})
self._filter_parser = parse_filter.Filter(self._schema)
# NOTE: mypy and pylint complain about the **kwargs not being listed (contrasting super)