return node
-def toTypedNode(value):
+def toTypedNode(value, language="en"):
"""Convert a python variable to a RDF Node with its closest xsd type
"""
if type(value) == types.BooleanType:
if value_type is not None:
node = RDF.Node(literal=value, datatype=value_type)
else:
- node = RDF.Node(literal=unicode(value).encode('utf-8'))
+ node = RDF.Node(literal=unicode(value).encode('utf-8'), language=language)
return node
return element
raise ValueError("Unable to simplify %s" % (uri,))
-def stripNamespace(namespace, term):
+def strip_namespace(namespace, term):
"""Remove the namespace portion of a term
returns None if they aren't in common
return term_s.replace(namespace._prefix, "")
-def get_model(model_name=None, directory=None):
+def get_model(model_name=None, directory=None, use_contexts=True):
if directory is None:
directory = os.getcwd()
+ contexts = 'yes' if use_contexts else 'no'
+
if model_name is None:
- storage = RDF.MemoryStorage(options_string="contexts='yes'")
+ storage = RDF.MemoryStorage(options_string="contexts='{}'".format(contexts))
logger.info("Using RDF Memory model")
else:
- options = "contexts='yes',hash-type='bdb',dir='{0}'".format(directory)
+ options = "contexts='{0}',hash-type='bdb',dir='{1}'".format(contexts, directory)
storage = RDF.HashStorage(model_name,
options=options)
logger.info("Using {0} with options {1}".format(model_name, options))
statements = []
retries = 3
+ succeeded = False
while retries > 0:
try:
retries -= 1
statements = rdf_parser.parse_as_stream(url, ns)
retries = 0
+ succeeded = True
except RDF.RedlandError, e:
errmsg = "RDF.RedlandError: {0} {1} tries remaining"
logger.error(errmsg.format(str(e), retries))
+ if not succeeded:
+ logger.warn("Unable to download %s", url)
+
for s in statements:
conditionally_add_statement(model, s, ns)
namespace = 'file://localhost/htsworkflow/schemas/'+s
add_schema(model, schema, namespace)
- if schema_path:
+ if schema_path:
if type(schema_path) in types.StringTypes:
schema_path = [schema_path]
writer.set_namespace('wot', wotNS._prefix)
# should these be here, kind of specific to an application
- writer.set_namespace('libraryOntology', libraryOntology._prefix)
+ writer.set_namespace('htswlib', libraryOntology._prefix)
writer.set_namespace('ucscSubmission', submissionOntology._prefix)
writer.set_namespace('ucscDaf', dafTermOntology._prefix)
+ writer.set_namespace('geoSoft', geoSoftNS._prefix)
+ writer.set_namespace('encode3', encode3NS._prefix)
return writer
+def get_turtle_header():
+ """Return a turtle header with our typical namespaces
+ """
+ serializer = get_serializer()
+ empty = get_model()
+ return serializer.serialize_model_to_string(empty)
def dump_model(model, destination=None):
if destination is None: