owmeta_core.rdf_utils module

class owmeta_core.rdf_utils.BatchAddGraph(graph, batchsize=1000, _parent=None, *args, **kwargs)[source]

Bases: object

Wrapper around graph that turns calls to ‘add’ into calls to ‘addN’

owmeta_core.rdf_utils.transitive_lookup(graph, start, predicate, context=None, direction='down', seen=None)[source]

Do a transitive lookup over an rdflib.graph.Graph or rdflib.store.Store

In other words, finds all resources which relate to start through zero or more predicate relationships. start itself will be included in the return value.

Loops in the input graph will not cause non-termination.

Parameters
graphrdflib.graph.Graph or rdflib.store.Store

The graph to query

startrdflib.term.Identifier

The resource in the graph to start from

predicaterdflib.term.URIRef

The predicate relating terms in the closure

contextrdflib.graph.Graph or rdflib.term.URIRef

The context in which the query should run. Optional

directionDOWN or UP

The direction in which to traverse

seenset of rdflib.term.Identifier

A set of terms which have already been “seen” by the algorithm. Useful for repeated calls to transitive_lookup. Note: if the start is in seen, queries from start will still be done, but any items in the result of those queries will not be queried for if in seen. Optional

Returns
set of rdflib.term.Identifier

resources in the transitive closure of predicate from start

owmeta_core.rdf_utils.transitive_subjects(graph, start, predicate, context=None, direction='down', seen=None)

Alias to transitive_lookup

owmeta_core.rdf_utils.DOWN = 'down'

Subject to Object direction for traversal across triples.

owmeta_core.rdf_utils.UP = 'up'

Object to Subject direction for traversal across triples.