Convert an attribute name in the form:
# direct predicate
instance1.foaf_name
# inverse predicate
instance2.if_foaf_title_of
to
<!-- direct predicate -->
<http://xmlns.com/foaf/spec/#term_name>
<!-- inverse predicate -->
<http://xmlns.com/foaf/spec/#term_title>
The function returns two values, the uri representation and True if it’s a direct predicate or False if its an inverse predicate.
Adds spaces to a camel case string. Failure to space out string returns the original string.
True if it’s a direct attribute
>>> util.is_attr_direct('foaf_name')
True
>>> util.is_attr_direct('is_foaf_name_of')
False
Same as uri_split, but instead of the base of the uri, returns the registered namespace for this uri
>>> print util.namespace_split('http://mynamespace/ns#some_property')
(rdflib.URIRef('http://mynamespace/ns#'), 'some_property')
Returns a string of the given URI under the form namespace:symbol, if namespace is registered, else returns an empty string
Inverse of attr2rdf, return the attribute name, given the URI and whether it is direct or not.
>>> print rdf2attr('http://xmlns.com/foaf/spec/#term_name',True)
foaf_name
>>> print rdf2attr('http://xmlns.com/foaf/spec/#term_title',False)
if_foaf_title_of
Split the uri into base path and remainder, the base is everything that comes before the last #‘ or / including it
>>> print util.uri_split('http://mynamespace/ns#some_property')
('NS1', 'some_property')
returns a class object from the supplied uri, used uri_to_class to get a valid class name
>>> print util.uri_to_class('http://mynamespace/ns#some_class')
surf.util.Ns1some_class
handy function to convert a uri to a Python valid class name
>>> # prints Ns1some_class, where Ns1 is the namespace (not registered, assigned automatically)
>>> print util.uri_to_classname('http://mynamespace/ns#some_class')
Ns1some_class
the function generates a unique subject in the provided namespace based on the uuid.uuid4() method, If namespace is not specified than the default SURF namespace is used
>>> print util.uuid_subject(ns.SIOC)
http://rdfs.org/sioc/ns#1b6ca1d5-41ed-4768-b86a-42185169faff