""" Utility class to merge RDF in stored in Redland containers (Models and Statements) into RSS dictionaries. """ class RDFItemMerger: """ Merge the RDF in the model into the RSS dictionary item. """ def merge_model(self, item, model): for s in model: self.merge_statement(item, s) """ Merge a single RDF statement into the RSS dictionary item. """ def merge_statement(self, item, statement): item[self._get_namespace(statement.predicate)] = str(statement.object) """ Private function to get the namespace of a URI. Evil code, and should be replaced. """ def _get_namespace(uri): from urlparse import urlsplit import os.path (scheme, network, path, query, fragment) = urlsplit(str(uri).strip("[]")) if fragment: return ("%s://%s%s%s" % (scheme, network, path, query), fragment) else: (path, node) = os.path.split(path) return ("%s://%s%s/" % (scheme, network, path), node) _get_namespace = staticmethod(_get_namespace)