aboutsummaryrefslogtreecommitdiffstats
path: root/bsfs/schema/serialize.py
diff options
context:
space:
mode:
Diffstat (limited to 'bsfs/schema/serialize.py')
-rw-r--r--bsfs/schema/serialize.py18
1 files changed, 13 insertions, 5 deletions
diff --git a/bsfs/schema/serialize.py b/bsfs/schema/serialize.py
index 8b31737..acc009a 100644
--- a/bsfs/schema/serialize.py
+++ b/bsfs/schema/serialize.py
@@ -35,8 +35,11 @@ def from_string(schema_str: str) -> schema.Schema:
graph.parse(data=schema_str, format='turtle')
# helper functions
- # FIXME: type annotation
- def _fetch_value(subject: URI, predicate: rdflib.URIRef, value_factory) -> typing.Optional[typing.Any]:
+ def _fetch_value(
+ subject: URI,
+ predicate: rdflib.URIRef,
+ value_factory: typing.Callable[[typing.Any], typing.Any],
+ ) -> typing.Optional[typing.Any]:
"""Fetch the object of a given subject and predicate.
Raises a `errors.ConsistencyError` if multiple objects match.
"""
@@ -242,9 +245,14 @@ def to_string(schema_inst: schema.Schema, fmt: str = 'turtle') -> str:
for triple in _parse(node):
graph.add(triple)
# add known namespaces for readability
- # FIXME: more systematically (e.g. for all in ns?)
- graph.bind('bsfs', rdflib.URIRef('http://bsfs.ai/schema/'))
- graph.bind('bse', rdflib.URIRef('http://bsfs.ai/schema/Entity#'))
+ # FIXME: more generically?
+ graph.bind('bse', rdflib.URIRef(ns.bse['']))
+ graph.bind('bsfs', rdflib.URIRef(ns.bsfs['']))
+ graph.bind('bsm', rdflib.URIRef(ns.bsm['']))
+ graph.bind('rdf', rdflib.URIRef(ns.rdf['']))
+ graph.bind('rdfs', rdflib.URIRef(ns.rdfs['']))
+ graph.bind('schema', rdflib.URIRef(ns.schema['']))
+ graph.bind('xsd', rdflib.URIRef(ns.xsd['']))
# serialize to turtle
return graph.serialize(format=fmt)