rdfframework.utilities package

Submodules

rdfframework.utilities.codetimer module

Simple timer module for timing code execution

class rdfframework.utilities.codetimer.CodeTimer[source]

Bases: object

simple class for placing timers in the code for performance testing

add_timer(timer_name)[source]

adds a timer to the class

delete_timer(timer_name)[source]

deletes a timer

log(timer_name, node)[source]

logs a event in the timer

print_timer(timer_name, **kwargs)[source]

prints the timer to the terminal

keyword args:
delete -> True/False -deletes the timer after printing
rdfframework.utilities.codetimer.code_timer(reset=False)[source]

Sets a global variable for tracking the timer accross multiple files

rdfframework.utilities.debug module

utilities for debuging code

rdfframework.utilities.debug.dumpable_obj(obj)[source]

takes an object that fails with json.dumps and converts it to a json.dumps dumpable object. This is useful for debuging code when you want to dump an object for easy reading

rdfframework.utilities.frameworkutilities module

class rdfframework.utilities.frameworkutilities.DeleteProperty[source]

Bases: object

dummy class for tagging items to be deleted. This will prevent passed in data ever being confused with marking a property for deletion.

class rdfframework.utilities.frameworkutilities.NotInFormClass[source]

Bases: object

dummy class for tagging properties that were never in a form. This will prevent passed in data ever being confused with a property that was never in the form.

rdfframework.utilities.frameworkutilities.cbool(value, strict=True)[source]

converts a value to true or false. Python’s default bool() function does not handle ‘true’ of ‘false’ strings

rdfframework.utilities.frameworkutilities.clean_iri(uri_string)[source]

removes the <> signs from a string start and end

rdfframework.utilities.frameworkutilities.convert_spo_to_dict(data, mode='subject', option='string')[source]

Takes the SPAQRL query results and converts them to a python Dict

mode: subject –> groups based on subject

rdfframework.utilities.frameworkutilities.copy_obj(obj)[source]

does a deepcopy of an object, but does not copy a class i.e. x = {“key”:[<classInstance1>,<classInstance2>,<classInstance3>]} y = copy_obj(x) y –> {“key”:[<classInstance1>,<classInstance2>,<classInstance3>]} del y[‘key’][0] y –> {“key”:[<classInstance2>,<classInstance3>]} x –> {“key”:[<classInstance1>,<classInstance2>,<classInstance3>]} *** this is to overcome a dictionary object that lists with classes

as the list items.
rdfframework.utilities.frameworkutilities.fw_config(**kwargs)[source]

function returns the application configuration information

rdfframework.utilities.frameworkutilities.get_app_ns_uri(value)[source]

looks in the framework for the namespace uri

rdfframework.utilities.frameworkutilities.get_attr(item, name, default=None)[source]

similar to getattr and get but will test for class or dict

rdfframework.utilities.frameworkutilities.iri(uri_string)[source]

converts a string to an IRI or returns an IRI if already formated

rdfframework.utilities.frameworkutilities.is_not_null(value)[source]

test for None and empty string

rdfframework.utilities.frameworkutilities.is_valid_object(uri_string)[source]

Test to see if the string is a object store

rdfframework.utilities.frameworkutilities.make_list(value)[source]

Takes a value and turns it into a list if it is not one

!!!!! This is important becouse list(value) if perfomed on an dictionary will return the keys of the dictionary in a list and not the dictionay as an element in the list. i.e.

x = {“first”:1, “second”:2} list(x) = [“first”, “second”] or use this [x,] make_list(x) =[{“first”:1, “second”:2}]
rdfframework.utilities.frameworkutilities.make_set(value)[source]

Takes a value and turns it into a set

!!!! This is important because set(string) will parse a string to individual characters vs. adding the string as an element of the set i.e.

x = ‘setvalue’ set(x) = {‘t’, ‘a’, ‘e’, ‘v’, ‘u’, ‘s’, ‘l’} make_set(x) = {‘setvalue’} or use set([x,]) by adding string as first item in list.
rdfframework.utilities.frameworkutilities.make_triple(sub, pred, obj)[source]
Takes a subject predicate and object and joins them with a space
in between
Args:
sub – Subject pred – Predicate obj – Object
Returns
str
rdfframework.utilities.frameworkutilities.nz(value, none_value, strict=True)[source]

This function is named after an old VBA function. It returns a default value if the passed in value is None. If strict is False it will treat an empty string as None as well.

example: x = None nz(x,”hello”) –> “hello” nz(x,””) –> “” y = “” nz(y,”hello”) –> “” nz(y,”hello”, False) –> “hello”

rdfframework.utilities.frameworkutilities.remove_null(obj)[source]

reads through a list or set and strips any null values

rdfframework.utilities.frameworkutilities.render_without_request(template_name, **template_vars)[source]

Usage is the same as flask.render_template:

render_without_request(‘my_template.html’, var1=’foo’, var2=’bar’)

rdfframework.utilities.frameworkutilities.slugify(value)[source]

Converts to lowercase, removes non-word characters (alphanumerics and underscores) and converts spaces to hyphens. Also strips leading and trailing whitespace using Django format

Args:

rdfframework.utilities.frameworkutilities.uid_to_repo_uri(id_value)[source]
rdfframework.utilities.frameworkutilities.xsd_to_python(value, data_type, rdf_type='literal', output='python')[source]

This will take a value and xsd data_type and convert it to a python variable

rdfframework.utilities.uriconvertor module

contains functions for converting objects to namespace prefixes

rdfframework.utilities.uriconvertor.convert_obj_to_rdf_namespace(obj, ns_obj=None)[source]

This function takes rdf json definitions and converts all of the uri strings to a ns_value format

rdfframework.utilities.uriconvertor.convert_to_ns(value, ns_obj=None)[source]

converts a value to the prefixed rdf ns equivalent. If not found returns the value as is

rdfframework.utilities.uriconvertor.convert_to_ttl(value, ns_obj=None)[source]

converts a value to the prefixed rdf ns equivalent. If not found returns the value as is

rdfframework.utilities.uriconvertor.convert_to_uri(value, ns_obj=None, strip_iri=False)[source]

converts a prefixed rdf ns equivalent value to its uri form. If not found returns the value as is

rdfframework.utilities.uriconvertor.create_namespace_obj(obj)[source]

takes initial rdf application definitions and reads the namespaces

rdfframework.utilities.uriconvertor.iris_to_strings(obj, ns_obj=None)[source]
rdfframework.utilities.uriconvertor.nouri(value)[source]
rdfframework.utilities.uriconvertor.pyuri(value)[source]

converts an iri to the app defined rdf namespaces in the framework in a python accessable format. i.e. schema:name or http:schema.org/name –> schema_name

rdfframework.utilities.uriconvertor.ttluri(value)[source]

converts an iri to the app defined rdf namespaces in the framework in a turtle accessable format. i.e. schema_name or http:schema.org/name –> schema:name

rdfframework.utilities.uriconvertor.uri(value)[source]
rdfframework.utilities.uriconvertor.uri_prefix(value)[source]

Takes a uri and returns the prefix for that uri

rdfframework.utilities.valuecalculator module

rdfframework.utilities.valuecalculator.calculate_default_value(field)[source]

calculates the default value based on the field default input

Module contents