+def simplify_rdf(value):
+ """Return a short name for a RDF object
+ e.g. The last part of a URI or an untyped string.
+ """
+ if isinstance(value, RDF.Node):
+ if value.is_resource():
+ name = simplify_uri(str(value.uri))
+ elif value.is_blank():
+ name = '<BLANK>'
+ else:
+ name = value.literal_value['string']
+ elif isinstance(value, RDF.Uri):
+ name = split_uri(str(value))
+ else:
+ name = value
+ return str(name)
+
+
+def simplify_uri(uri):
+ """Split off the end of a uri
+
+ >>> simplify_uri('http://asdf.org/foo/bar')
+ 'bar'
+ >>> simplify_uri('http://asdf.org/foo/bar#bleem')
+ 'bleem'
+ >>> simplify_uri('http://asdf.org/foo/bar/')
+ 'bar'
+ >>> simplify_uri('http://asdf.org/foo/bar?was=foo')
+ 'was=foo'
+ """
+ parsed = urlparse(uri)
+ if len(parsed.query) > 0:
+ return parsed.query
+ elif len(parsed.fragment) > 0:
+ return parsed.fragment
+ elif len(parsed.path) > 0:
+ for element in reversed(parsed.path.split('/')):
+ if len(element) > 0:
+ return element
+ raise ValueError("Unable to simplify %s" % (uri,))
+