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
oobject

The object to contexualize

__bool__()[source]

Always returns True. Prevents a context with zero statements from testing false since that’s not typically a useful branching condition.

add_import(context)[source]

Add an imported context

add_statement(stmt)[source]

Add a statement to the context. Typically, statements will be added by contextualizing a DataObject and making a statement thereon. For instance, if a class A has a property p, then for the context ctx:

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
stmtowmeta_core.statement.Statement

Statement to add

clear()[source]

Clear declared statements

contents()[source]

Returns statements added to this context

Returns
generator
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

Parameters
contextContext, optional

The context in which to declare statements. If not provided, one will be created with self.conf[IMPORTS_CONTEXT_KEY] as the identifier

Returns
Context

The context in which the statements were declared

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
rdflib.graph.ConjunctiveGraph
load_mixed_graph()[source]

Create a graph for accessing statements both staged (see load_staged_graph) and stored (see load_graph_from_configured_store). No effort is made to either deduplicate, smush blank nodes, or logically reconcile statements between staged and stored graphs.

Returns
rdflib.graph.ConjunctiveGraph
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
rdflib.graph.ConjunctiveGraph
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
rdflib.graph.ConjunctiveGraph
rdf_graph()[source]

Return the principal graph for this context. For a regular Context this will be the “staged” graph.

Returns
rdflib.graph.ConjunctiveGraph

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
stmttuple

Statement to remove

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
graphrdflib.graph.Graph or set, 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 if inline_imports is True)

saved_contextsset, optional

a collection of identifiers for previously saved contexts. Note that id is used to get an identifier: the return value of id can be repeated after an object is deleted.

save_imports(context=None, *args, transitive=True, **kwargs)[source]

Add the imports on this context to a graph

Parameters
contextContext, 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

transitive_imports()[source]

Return imports on this context and on imported contexts

Yields
Context
property imports

Return imports on this context

Yields
Context
property mixed

A read-only context whose principal graph is the “mixed” graph.

Returns
QueryContext

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
QueryContext

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

Returns
owmeta_core.dataobject.DataObject
property staged

A read-only context whose principal graph is the “staged” graph.

Returns
QueryContext

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
QueryContext

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