+
+def add_default_schemas(model, schema_path=None):
+ """Add default schemas to a model
+ Looks for turtle files in either htsworkflow/util/schemas
+ or in the list of directories provided in schema_path
+ """
+
+ if schema_path is None:
+ path, _ = os.path.split(__file__)
+ schema_path = [os.path.join(path, 'schemas')]
+ elif type(schema_path) in types.StringTypes:
+ schema_path = [schema_path]
+
+ for p in schema_path:
+ for f in glob(os.path.join(p, '*.turtle')):
+ add_schema(model, f)
+
+def add_schema(model, filename):
+ """Add a schema to a model.
+
+ Main difference from 'load_into_model' is it tags it with
+ a RDFlib context so I can remove them later.
+ """
+ parser = RDF.Parser(name='turtle')
+ context = RDF.Node(RDF.Uri(SCHEMAS_URL))
+ url = 'file://' + filename
+ for s in parser.parse_as_stream(url):
+ try:
+ model.append(s, context)
+ except RDF.RedlandError as e:
+ logger.error("%s with %s", str(e), str(s))
+
+
+def remove_schemas(model):
+ """Remove statements labeled with our schema context"""
+ context = RDF.Node(RDF.Uri(SCHEMAS_URL))
+ model.context_remove_statements(context)
+
+