owmeta_core.context module¶
- class owmeta_core.context.Context(*args, **kwargs)[source]¶
Bases:
ContextualizableDataUserMixin
A 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
contextualizing
aDataObject
and making a statement thereon. For instance, if a classA
has a propertyp
, then for the contextctx
:ctx(A)(ident='http://example.org').p('val')
would add a statement to
ctx
like:(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
tuple
A triple of
RDFLib Identifiers
- declare_imports(context=None, transitive=False)[source]¶
Declare
imports
statements 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
Context
this will be the “staged” graph.- Returns
See also
staged
Has the “staged” principal graph.
mixed
Has the “mixed” principal graph.
stored
Has the “stored” graph, including imports.
own_stored
Has 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.Graph
orset
,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.commit
is invoked after adding statements to the graph (including any imported contexts ifinline_imports
isTrue
)- saved_contexts
set
,optional
a collection of identifiers for previously saved contexts. Note that
id
is used to get an identifier: the return value ofid
can be repeated after an object is deleted.
- graph
- save_imports(context=None, *args, transitive=True, **kwargs)[source]¶
Add the
imports
on 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_graph
load_mixed_graph
Defines 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_graph
load_own_graph_from_configured_store
Defines 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_graph
load_staged_graph
Defines 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_graph
load_graph_from_configured_store
Defines 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:
object
The context manager created when Context::__call__ is passed a dict
- class owmeta_core.context.QueryContext(*args, **kwargs)[source]¶
Bases:
Context
A 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