diff options
author | Matthias Baumgartner <dev@igsor.net> | 2023-01-16 21:41:20 +0100 |
---|---|---|
committer | Matthias Baumgartner <dev@igsor.net> | 2023-01-16 21:41:20 +0100 |
commit | 3504609e1ba1f7f653fa79910474bebd3ec24d8a (patch) | |
tree | d94cdf7ac540eb82630f78cbf564682b66007f51 /bsfs/schema | |
parent | 76fa694911f54e293ddf517246c6c4a1e8e745fd (diff) | |
download | bsfs-3504609e1ba1f7f653fa79910474bebd3ec24d8a.tar.gz bsfs-3504609e1ba1f7f653fa79910474bebd3ec24d8a.tar.bz2 bsfs-3504609e1ba1f7f653fa79910474bebd3ec24d8a.zip |
various minor fixes
Diffstat (limited to 'bsfs/schema')
-rw-r--r-- | bsfs/schema/serialize.py | 18 |
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) |