def get_prefix_defs (prefixes):
    '''Returns the prefix definition part of a SPARQL query bases on a list of prefixes'''
    
    out = ""
    
    # Build the prefixes string from the NS map
    for pref in prefixes:
        ns = [str(NS[p]) for p in NS.keys() if p == pref]
        if len(ns) == 1:
            out += "PREFIX %s:<%s>\n" % (pref, ns[0])
            
    return out
def get_prefix_defs(prefixes):
    '''Returns the prefix definition part of a SPARQL query bases on a list of prefixes'''

    out = ""

    # Build the prefixes string from the NS map
    for pref in prefixes:
        ns = [str(NS[p]) for p in NS.keys() if p == pref]
        if len(ns) == 1:
            out += "PREFIX %s:<%s>\n" % (pref, ns[0])

    return out
def normalize (uri, prefixes = None):
    '''Converts a URI into a 'namespace:term' string or <uri> entity 
       and (optionally) appends the namespace to the prefixes list'''
    
    # Split the uri into namespace and term
    namespace, term = split_uri(uri)

    # Resolve the namespace prefix
    prefs = [p for p in NS.keys() if str(NS[p]) == namespace]
    if len(prefs) == 1:
        namespace = prefs[0]
    else:
        namespace = None
        
    # Optionally append the namespace to the prefixes list
    if (prefixes and namespace) and (namespace not in prefixes):
        prefixes.append(namespace)
        
    # Return the 'namespace:term' string or the <url> (if no prefix matches)
    return namespace_manager.normalizeUri(unicode(uri))
def normalize(uri, prefixes=None):
    '''Converts a URI into a 'namespace:term' string or <uri> entity 
       and (optionally) appends the namespace to the prefixes list'''

    # Split the uri into namespace and term
    namespace, term = split_uri(uri)

    # Resolve the namespace prefix
    prefs = [p for p in NS.keys() if str(NS[p]) == namespace]
    if len(prefs) == 1:
        namespace = prefs[0]
    else:
        namespace = None

    # Optionally append the namespace to the prefixes list
    if (prefixes and namespace) and (namespace not in prefixes):
        prefixes.append(namespace)

    # Return the 'namespace:term' string or the <url> (if no prefix matches)
    return namespace_manager.normalizeUri(unicode(uri))
    '''Returns a list of test sparql queries for the given model'''
    
    queries = []
    generate_queries (data, queries, str(NS['sp'][model]))
    return queries


# Query builder state variables
main_types = []
data = {}
loaded = False

# Initialize the namespace manager object
namespace_manager = NamespaceManager(Graph())

# Import the namespaces into the namespace manager
for ns in NS.keys():
    namespace_manager.bind(ns, NS[ns], override=False)
    
# Parse the ontology when necessary
if not rdf_ontology.api_types:
    rdf_ontology.parse_ontology(open(APP_PATH + '/data/smart.owl').read())

# Build a list of data types that need to be added to the data definitions
for t in rdf_ontology.api_types:
    if t.is_statement or len(t.calls) > 0 or rdf_ontology.sp.Component in [x.uri for x in t.parents]:
        main_types.append(t)

# Build the data definitions object with each data type
for t in main_types: 
    generate_data_for_type(t, data)
    queries = []
    generate_queries(data, queries, str(NS['sp'][model]))
    return queries


# Query builder state variables
main_types = []
data = {}
loaded = False

# Initialize the namespace manager object
namespace_manager = NamespaceManager(Graph())

# Import the namespaces into the namespace manager
for ns in NS.keys():
    namespace_manager.bind(ns, NS[ns], override=False)

# Parse the ontology when necessary
if not rdf_ontology.api_types:
    rdf_ontology.parse_ontology(open(APP_PATH + '/data/smart.owl').read())

# Build a list of data types that need to be added to the data definitions
for t in rdf_ontology.api_types:
    if t.is_statement or len(t.calls) > 0 or rdf_ontology.sp.Component in [
            x.uri for x in t.parents
    ]:
        main_types.append(t)

# Build the data definitions object with each data type
for t in main_types: