owmeta_core.rdf_query_util module

exception owmeta_core.rdf_query_util.MissingRDFTypeException[source]

Bases: Exception

Raised when we were looking for an RDF type couldn’t find one

owmeta_core.rdf_query_util.get_most_specific_rdf_type(graph, types, base=None)[source]

Find the RDF type that isn’t a sub-class of any other, constrained to be a sub-class of base if that is provided.

Parameters
graphrdflib.graph.Graph

The graph to query rdfs:subClassOf relationships

typeslist of rdflib.term.URIRef

The types to query

baserdflib.term.URIRef

The “base” type

See also

RDFTypeResolver
owmeta_core.rdf_query_util.load(graph, start, target_type, *args)[source]

Loads a set of objects based on the graph starting from start

Parameters
graphrdflib.graph.Graph

The graph to query from

startgraph_object.GraphObject

The graph object to start the query from

target_typerdflib.term.URIRef

URI of the target type. Any result will be a sub-class of this type

owmeta_core.rdf_query_util.load_base(graph, idents, target_type, context, resolver)[source]

Loads a set of objects from an RDF graph given their identifiers

Parameters
graphrdflib.graph.Graph

The graph to query from

identslist of rdflib.term.URIRef

A list of identifiers to convert into objects

target_typerdflib.term.URIRef

URI of the target type. Any result will be a sub-class of this type

contextobject

Limits the scope of the query to statements within or entailed by this context. Notionally, it’s a owmeta_core.context.Context instance

resolverrdf_type_resolver.RDFTypeResolver

Handles some of the mappings

owmeta_core.rdf_query_util.load_terms(graph, start, target_type)[source]

Loads a set of terms based on the object graph starting from start

Parameters
graphrdflib.graph.Graph

The graph to query from

startgraph_object.GraphObject

The graph object to start the query from

target_typerdflib.term.URIRef

URI of the target type. Any result will be a sub-class of this type

owmeta_core.rdf_query_util.oid(identifier_or_rdf_type, rdf_type, context, base_type=None)[source]

Create an object from its rdf type

Parameters
identifier_or_rdf_typerdflib.term.URIRef

If rdf_type is provided, then this value is used as the identifier for the newly created object. Otherwise, this value will be the rdf_type of the object used to determine the Python type and the object’s identifier will be randomly generated.

rdf_typerdflib.term.URIRef

If provided, this will be the rdf_type of the newly created object.

contextContext, optional

The context to resolve a class from

base_typetype

The base type

Returns
The newly created object