The surf.util Module

surf.util.attr2rdf(attrname)[source]

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.

surf.util.de_camel_case(camel_case, delim=' ', method=2)[source]

Adds spaces to a camel case string. Failure to space out string returns the original string.

surf.util.is_attr_direct(attrname)[source]

True if it’s a direct attribute

>>> util.is_attr_direct('foaf_name')
True
>>> util.is_attr_direct('is_foaf_name_of')
False
surf.util.is_uri(uri)[source]

True if the specified string is a URI reference False otherwise

surf.util.json_to_rdflib(obj)[source]

Convert a json result entry to an rdfLib type.

surf.util.namespace_split(uri)[source]

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')
surf.util.pretty_rdf(uri)[source]

Returns a string of the given URI under the form namespace:symbol, if namespace is registered, else returns an empty string

surf.util.rdf2attr(uri, direct)[source]

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
surf.util.single[source]

Descriptor for easy access to attributes with single value.

surf.util.uri_split(uri)[source]

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')
surf.util.uri_to_class(uri)[source]

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
surf.util.uri_to_classname(uri)[source]

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
surf.util.uuid_subject(namespace=None)[source]

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
surf.util.value_to_rdf(value)[source]

Convert the value to an rdflib compatible type if appropriate.

Previous topic

The surf.store Module

This Page