Add option to get_model to disable RDF graph context.
authorDiane Trout <diane@ghic.org>
Wed, 15 Jan 2014 00:58:50 +0000 (16:58 -0800)
committerDiane Trout <diane@ghic.org>
Wed, 15 Jan 2014 00:58:50 +0000 (16:58 -0800)
At least with the version of librdf I was using the context
graph really slowed adding tripes down.

htsworkflow/util/rdfhelp.py

index 4f65d7d44885ad0c16bbe1ade6604ba2b5a42700..48294416abf1def5a9bc1c3d77b0a4eaa1a607b0 100644 (file)
@@ -232,15 +232,17 @@ def strip_namespace(namespace, term):
     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))
@@ -281,10 +283,10 @@ def load_into_model(model, parser_name, path, ns=None):
         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)