owmeta_core.context module¶
- class owmeta_core.context.Context(*args, **kwargs)[source]¶
Bases:
ContextualizableDataUserMixinA context. Analogous to an RDF context, with some special sauce
- __call__(o=None, *args, **kwargs)[source]¶
Contextualize an object
- Parameters
- o
object The object to contexualize
- o
- __bool__()[source]¶
Always returns
True. Prevents a context with zero statements from testing false since that’s not typically a useful branching condition.
- add_statement(stmt)[source]¶
Add a statement to the context. Typically, statements will be added by
contextualizingaDataObjectand making a statement thereon. For instance, if a classAhas a propertyp, then for the contextctx:ctx(A)(ident='http://example.org').p('val')
would add a statement to
ctxlike:(A(ident='http://example.org'), A.p.link, rdflib.term.Literal('val'))
- Parameters
- stmt
owmeta_core.statement.Statement Statement to add
- stmt
- contents_triples()[source]¶
Returns, as triples, the statements staged in this context
- Yields
tupleA triple of
RDFLib Identifiers
- declare_imports(context=None, transitive=False)[source]¶
Declare
importsstatements in the given context
- load_graph_from_configured_store()[source]¶
Create an RDFLib graph for accessing statements in this context, including imported contexts. The “configured” graph is the one at
self.rdf.- Returns
- load_mixed_graph()[source]¶
Create a graph for accessing statements both staged (see
load_staged_graph) and stored (seeload_graph_from_configured_store). No effort is made to either deduplicate, smush blank nodes, or logically reconcile statements between staged and stored graphs.- Returns
- load_own_graph_from_configured_store()[source]¶
Create a RDFLib graph for accessing statements in this context, excluding imported contexts. The “configured” graph is the one at
self.conf['rdf.graph'].- Returns
- load_staged_graph()[source]¶
Create a graph for accessing statements declared in this specific instance of this context. This statements may not have been written to disk; therefore, they are “staged”.
- Returns
- rdf_graph()[source]¶
Return the principal graph for this context. For a regular
Contextthis will be the “staged” graph.- Returns
See also
stagedHas the “staged” principal graph.
mixedHas the “mixed” principal graph.
storedHas the “stored” graph, including imports.
own_storedHas the “stored” graph, excluding imports.
- remove_statement(stmt)[source]¶
Remove a statement from the context
- Parameters
- stmt
tuple Statement to remove
- stmt
- save(graph=None, inline_imports=False, autocommit=True, saved_contexts=None)¶
Alias to save_context
- save_context(graph=None, inline_imports=False, autocommit=True, saved_contexts=None)[source]¶
Adds the staged statements in the context to a graph
- Parameters
- graph
rdflib.graph.Graphorset,optional the destination graph. Defaults to
self.rdf- inline_importsbool,
optional if
True, imported contexts will also be written added to the graph- autocommitbool,
optional if
True,graph.commitis invoked after adding statements to the graph (including any imported contexts ifinline_importsisTrue)- saved_contexts
set,optional a collection of identifiers for previously saved contexts. Note that
idis used to get an identifier: the return value ofidcan be repeated after an object is deleted.
- graph
- save_imports(context=None, *args, transitive=True, **kwargs)[source]¶
Add the
importson this context to a graph- Parameters
- context
Context,optional The context to add statements to. This context’s configured graph will ultimately receive the triples. By default, a context will be created with
self.conf[IMPORTS_CONTEXT_KEY]as the identifier- transitivebool,
optional If
True, call imported imported contexts to save their imports as well
- context
- property mixed¶
A read-only context whose principal graph is the “mixed” graph.
- Returns
See also
rdf_graphload_mixed_graphDefines the principal graph for this context
- property own_stored¶
A read-only context whose principal graph is the “stored” graph, excluding imported contexts.
- Returns
See also
rdf_graphload_own_graph_from_configured_storeDefines the principal graph for this context
- property rdf_object¶
Returns a dataobject for this context
- property staged¶
A read-only context whose principal graph is the “staged” graph.
- Returns
See also
rdf_graphload_staged_graphDefines the principal graph for this context
- property stored¶
A read-only context whose principal graph is the “stored” graph, including imported contexts.
- Returns
See also
rdf_graphload_graph_from_configured_storeDefines the principal graph for this context
- property triples_saved¶
The number of triples saved in the most recent call to
save_context
- class owmeta_core.context.ContextContextManager(ctx, to_import)[source]¶
Bases:
objectThe context manager created when Context::__call__ is passed a dict
- class owmeta_core.context.QueryContext(*args, **kwargs)[source]¶
Bases:
ContextA read-only context.
- owmeta_core.context.DEFAULT_CONTEXT_KEY = 'default_context_id'¶
Configuration file key for the URI of a default RDF graph context.
This is the URI of the default graph in a project or bundle.
- owmeta_core.context.IMPORTS_CONTEXT_KEY = 'imports_context_id'¶
Configuration file key for the URI of an imports RDF graph context.
The imports context holds the relationships between contexts, especially the imports relationship