def add_namespace(self, ns_prefix, ns_uri):
'''
preferred method is to instantiate with repository under 'context',
but prefixes / namespaces can be added for a Resource instance
adds to self.rdf.prefixes which will endure through create/update/refresh,
and get added back to parsed graph namespaces
Args:
ns_prefix (str): prefix for namespace, e.g. 'dc', 'foaf'
ns_uri (str): string of namespace / ontology. e.g. 'http://purl.org/dc/elements/1.1/', 'http://xmlns.com/foaf/0.1/'
Returns:
None: binds this new prefix:namespace combination to self.rdf.prefixes for use, and self.rdf.graph for serialization
'''
# add to prefixes
setattr(self.rdf.prefixes, ns_prefix, rdflib.Namespace(ns_uri))
# bind to graph
self.rdf.namespace_manager.bind(ns_prefix, ns_uri, override=False)
评论列表
文章目录